1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.layoutlib.bridge.intensive;
18 
19 import com.android.ide.common.rendering.api.RenderSession;
20 import com.android.ide.common.rendering.api.Result;
21 import com.android.ide.common.rendering.api.ViewInfo;
22 
23 import android.annotation.NonNull;
24 import android.annotation.Nullable;
25 
26 import java.awt.image.BufferedImage;
27 import java.util.ArrayList;
28 import java.util.Collections;
29 import java.util.List;
30 
31 public class RenderResult {
32     private final List<ViewInfo> mRootViews;
33     private final List<ViewInfo> mSystemViews;
34     private final Result mRenderResult;
35     private BufferedImage mImage;
36 
RenderResult(@ullable Result result, @Nullable List<ViewInfo> systemViewInfoList, @Nullable List<ViewInfo> rootViewInfoList, @Nullable BufferedImage image)37     private RenderResult(@Nullable Result result, @Nullable List<ViewInfo> systemViewInfoList,
38             @Nullable List<ViewInfo> rootViewInfoList, @Nullable BufferedImage image) {
39         mSystemViews = systemViewInfoList == null ? Collections.emptyList() : systemViewInfoList;
40         mRootViews = rootViewInfoList == null ? Collections.emptyList() : rootViewInfoList;
41         mRenderResult = result;
42         mImage = image;
43     }
44 
45     @NonNull
getFromSession(@onNull RenderSession session)46     static RenderResult getFromSession(@NonNull RenderSession session) {
47         return new RenderResult(session.getResult(),
48                 new ArrayList<>(session.getSystemRootViews()),
49                 new ArrayList<>(session.getRootViews()),
50                 session.getImage());
51     }
52 
53     @Nullable
getResult()54     public Result getResult() {
55         return mRenderResult;
56     }
57 
58     @NonNull
getRootViews()59     public List<ViewInfo> getRootViews() {
60         return mRootViews;
61     }
62 
63     @NonNull
getSystemViews()64     public List<ViewInfo> getSystemViews() {
65         return mSystemViews;
66     }
67 
68     @Nullable
getImage()69     public BufferedImage getImage() {
70         return mImage;
71     }
72 }
73