blob: fe70d13fb984ca39470409474334dc0a4d5ec1cb [file] [log] [blame]
Chris Craik0776a602013-02-14 15:36:01 -08001/*
2 * Copyright (C) 2013 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#ifndef ANDROID_HWUI_DISPLAY_LIST_H
18#define ANDROID_HWUI_DISPLAY_LIST_H
19
Romain Guy7031ff62013-02-22 11:48:16 -080020#ifndef LOG_TAG
21 #define LOG_TAG "OpenGLRenderer"
22#endif
23
Chris Craik0776a602013-02-14 15:36:01 -080024#include <SkCamera.h>
25#include <SkMatrix.h>
26
Chris Craikff785832013-03-08 13:12:16 -080027#include <private/hwui/DrawGlInfo.h>
28
Chris Craikf57776b2013-10-25 18:30:17 -070029#include <utils/KeyedVector.h>
Chris Craikc1c5f082013-09-11 16:23:37 -070030#include <utils/LinearAllocator.h>
Chris Craik0776a602013-02-14 15:36:01 -080031#include <utils/RefBase.h>
32#include <utils/SortedVector.h>
33#include <utils/String8.h>
34#include <utils/Vector.h>
Romain Guye3b0a012013-06-26 15:45:41 -070035
Chris Craik0776a602013-02-14 15:36:01 -080036#include <cutils/compiler.h>
37
Romain Guye3b0a012013-06-26 15:45:41 -070038#include <androidfw/ResourceTypes.h>
39
Chris Craik0776a602013-02-14 15:36:01 -080040#include "Debug.h"
Chris Craikf57776b2013-10-25 18:30:17 -070041#include "Matrix.h"
42#include "DeferredDisplayList.h"
John Reckacb6f072014-03-12 16:11:23 -070043#include "RenderProperties.h"
John Reck087bc0c2014-04-04 16:20:08 -070044#include "utils/VirtualLightRefBase.h"
Chris Craik0776a602013-02-14 15:36:01 -080045
46class SkBitmap;
47class SkPaint;
48class SkPath;
49class SkRegion;
50
51namespace android {
52namespace uirenderer {
53
Chris Craikc3566d02013-02-04 16:16:33 -080054class DeferredDisplayList;
Chris Craik0776a602013-02-14 15:36:01 -080055class DisplayListOp;
56class DisplayListRenderer;
57class OpenGLRenderer;
58class Rect;
59class Layer;
Chris Craik0776a602013-02-14 15:36:01 -080060class SkiaShader;
61
Chris Craikff785832013-03-08 13:12:16 -080062class ClipRectOp;
63class SaveLayerOp;
64class SaveOp;
65class RestoreToCountOp;
Chris Craikf57776b2013-10-25 18:30:17 -070066class DrawDisplayListOp;
Chris Craikff785832013-03-08 13:12:16 -080067
Chris Craikf57776b2013-10-25 18:30:17 -070068/**
69 * Holds data used in the playback a tree of DisplayLists.
70 */
71class PlaybackStateStruct {
72protected:
73 PlaybackStateStruct(OpenGLRenderer& renderer, int replayFlags, LinearAllocator* allocator)
Chris Craik3783e702014-01-27 14:26:14 -080074 : mRenderer(renderer), mReplayFlags(replayFlags), mAllocator(allocator){}
Chris Craikf57776b2013-10-25 18:30:17 -070075
76public:
Chris Craikff785832013-03-08 13:12:16 -080077 OpenGLRenderer& mRenderer;
78 const int mReplayFlags;
Chris Craikf57776b2013-10-25 18:30:17 -070079
80 // Allocator with the lifetime of a single frame.
81 // replay uses an Allocator owned by the struct, while defer shares the DeferredDisplayList's Allocator
82 LinearAllocator * const mAllocator;
Chris Craikff785832013-03-08 13:12:16 -080083};
84
Chris Craikf57776b2013-10-25 18:30:17 -070085class DeferStateStruct : public PlaybackStateStruct {
86public:
87 DeferStateStruct(DeferredDisplayList& deferredList, OpenGLRenderer& renderer, int replayFlags)
Chris Craik9f68c092014-01-10 10:30:57 -080088 : PlaybackStateStruct(renderer, replayFlags, &(deferredList.mAllocator)),
89 mDeferredList(deferredList) {}
Chris Craikf57776b2013-10-25 18:30:17 -070090
91 DeferredDisplayList& mDeferredList;
92};
93
94class ReplayStateStruct : public PlaybackStateStruct {
95public:
Chris Craikff785832013-03-08 13:12:16 -080096 ReplayStateStruct(OpenGLRenderer& renderer, Rect& dirty, int replayFlags)
Chris Craikf57776b2013-10-25 18:30:17 -070097 : PlaybackStateStruct(renderer, replayFlags, &mReplayAllocator),
98 mDirty(dirty), mDrawGlStatus(DrawGlInfo::kStatusDone) {}
99
Chris Craikff785832013-03-08 13:12:16 -0800100 Rect& mDirty;
Chris Craikff785832013-03-08 13:12:16 -0800101 status_t mDrawGlStatus;
Chris Craikf57776b2013-10-25 18:30:17 -0700102 LinearAllocator mReplayAllocator;
Chris Craikff785832013-03-08 13:12:16 -0800103};
104
Chris Craik0776a602013-02-14 15:36:01 -0800105/**
John Reck44fd8d22014-02-26 11:00:11 -0800106 * Data structure that holds the list of commands used in display list stream
Chris Craik0776a602013-02-14 15:36:01 -0800107 */
John Reck44fd8d22014-02-26 11:00:11 -0800108class DisplayListData {
Chris Craik0776a602013-02-14 15:36:01 -0800109public:
John Reck087bc0c2014-04-04 16:20:08 -0700110 DisplayListData();
111 ~DisplayListData();
John Reck44fd8d22014-02-26 11:00:11 -0800112
Chris Craikf57776b2013-10-25 18:30:17 -0700113 // allocator into which all ops were allocated
Chris Craik0776a602013-02-14 15:36:01 -0800114 LinearAllocator allocator;
Chris Craikf57776b2013-10-25 18:30:17 -0700115
116 // pointers to all ops within display list, pointing into allocator data
Chris Craik0776a602013-02-14 15:36:01 -0800117 Vector<DisplayListOp*> displayListOps;
Chris Craikf57776b2013-10-25 18:30:17 -0700118
Chris Craikf533e942014-01-14 22:35:37 -0800119 // index of DisplayListOp restore, after which projected descendents should be drawn
Chris Craik1df26442014-02-05 16:50:41 -0800120 int projectionReceiveIndex;
John Reck44fd8d22014-02-26 11:00:11 -0800121
122 Vector<const SkBitmap*> bitmapResources;
123 Vector<const SkBitmap*> ownedBitmapResources;
124 Vector<const Res_png_9patch*> patchResources;
125
126 Vector<const SkPaint*> paints;
127 Vector<const SkPath*> paths;
128 SortedVector<const SkPath*> sourcePaths;
129 Vector<const SkRegion*> regions;
130 Vector<const SkMatrix*> matrices;
131 Vector<SkiaShader*> shaders;
132 Vector<Layer*> layers;
133 uint32_t functorCount;
134 bool hasDrawOps;
135
136 bool isEmpty() {
137 return !displayListOps.size();
138 }
139
John Reck087bc0c2014-04-04 16:20:08 -0700140 void addChild(DrawDisplayListOp* childOp);
141 const Vector<DrawDisplayListOp*>& children() { return mChildren; }
142
John Reck44fd8d22014-02-26 11:00:11 -0800143private:
John Reck087bc0c2014-04-04 16:20:08 -0700144 Vector< sp<VirtualLightRefBase> > mReferenceHolders;
145
146 // list of children display lists for quick, non-drawing traversal
147 Vector<DrawDisplayListOp*> mChildren;
148
John Reck44fd8d22014-02-26 11:00:11 -0800149 void cleanupResources();
Chris Craik0776a602013-02-14 15:36:01 -0800150};
151
Chris Craik0776a602013-02-14 15:36:01 -0800152}; // namespace uirenderer
153}; // namespace android
154
155#endif // ANDROID_HWUI_OPENGL_RENDERER_H