1/*
2 * Copyright (C) 2016 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
17package com.android.layoutlib.bridge.intensive;
18
19import com.android.ide.common.rendering.api.RenderSession;
20import com.android.ide.common.rendering.api.Result;
21import com.android.ide.common.rendering.api.ViewInfo;
22
23import android.annotation.NonNull;
24import android.annotation.Nullable;
25
26import java.awt.image.BufferedImage;
27import java.util.ArrayList;
28import java.util.Collections;
29import java.util.List;
30
31class RenderResult {
32    private final List<ViewInfo> mRootViews;
33    private final List<ViewInfo> mSystemViews;
34    private final Result mRenderResult;
35    private BufferedImage mImage;
36
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
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
54    Result getResult() {
55        return mRenderResult;
56    }
57
58    @NonNull
59    public List<ViewInfo> getRootViews() {
60        return mRootViews;
61    }
62
63    @NonNull
64    public List<ViewInfo> getSystemViews() {
65        return mSystemViews;
66    }
67
68    @Nullable
69    public BufferedImage getImage() {
70        return mImage;
71    }
72}
73