blob: 7a43a2a9891560eb993a42a4c71f81a1702b880c [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"
Chris Craik0776a602013-02-14 15:36:01 -080044
45class SkBitmap;
46class SkPaint;
47class SkPath;
48class SkRegion;
49
50namespace android {
51namespace uirenderer {
52
Chris Craikc3566d02013-02-04 16:16:33 -080053class DeferredDisplayList;
Chris Craik0776a602013-02-14 15:36:01 -080054class DisplayListOp;
55class DisplayListRenderer;
56class OpenGLRenderer;
57class Rect;
58class Layer;
Chris Craik0776a602013-02-14 15:36:01 -080059
Chris Craikff785832013-03-08 13:12:16 -080060class ClipRectOp;
61class SaveLayerOp;
62class SaveOp;
63class RestoreToCountOp;
Chris Craika7090e02014-06-20 16:01:00 -070064class DrawRenderNodeOp;
Chris Craikff785832013-03-08 13:12:16 -080065
Chris Craikf57776b2013-10-25 18:30:17 -070066/**
67 * Holds data used in the playback a tree of DisplayLists.
68 */
69class PlaybackStateStruct {
70protected:
71 PlaybackStateStruct(OpenGLRenderer& renderer, int replayFlags, LinearAllocator* allocator)
Chris Craik74669862014-08-07 17:27:30 -070072 : mRenderer(renderer)
73 , mReplayFlags(replayFlags)
74 , 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
Chris Craik4ac36f82014-12-09 16:54:03 -080080 // Allocator with the lifetime of a single frame. replay uses an Allocator owned by the struct,
81 // while defer shares the DeferredDisplayList's Allocator
82 // TODO: move this allocator to be owned by object with clear frame lifecycle
Chris Craikf57776b2013-10-25 18:30:17 -070083 LinearAllocator * const mAllocator;
Chris Craik74669862014-08-07 17:27:30 -070084
85 SkPath* allocPathForFrame() {
Chris Craik4ac36f82014-12-09 16:54:03 -080086 return mRenderer.allocPathForFrame();
Chris Craik74669862014-08-07 17:27:30 -070087 }
Chris Craikff785832013-03-08 13:12:16 -080088};
89
Chris Craikf57776b2013-10-25 18:30:17 -070090class DeferStateStruct : public PlaybackStateStruct {
91public:
92 DeferStateStruct(DeferredDisplayList& deferredList, OpenGLRenderer& renderer, int replayFlags)
Chris Craik9f68c092014-01-10 10:30:57 -080093 : PlaybackStateStruct(renderer, replayFlags, &(deferredList.mAllocator)),
94 mDeferredList(deferredList) {}
Chris Craikf57776b2013-10-25 18:30:17 -070095
96 DeferredDisplayList& mDeferredList;
97};
98
99class ReplayStateStruct : public PlaybackStateStruct {
100public:
Chris Craikff785832013-03-08 13:12:16 -0800101 ReplayStateStruct(OpenGLRenderer& renderer, Rect& dirty, int replayFlags)
Chris Craikf57776b2013-10-25 18:30:17 -0700102 : PlaybackStateStruct(renderer, replayFlags, &mReplayAllocator),
103 mDirty(dirty), mDrawGlStatus(DrawGlInfo::kStatusDone) {}
104
Chris Craikff785832013-03-08 13:12:16 -0800105 Rect& mDirty;
Chris Craikff785832013-03-08 13:12:16 -0800106 status_t mDrawGlStatus;
Chris Craikf57776b2013-10-25 18:30:17 -0700107 LinearAllocator mReplayAllocator;
Chris Craikff785832013-03-08 13:12:16 -0800108};
109
Chris Craik0776a602013-02-14 15:36:01 -0800110/**
John Reck44fd8d22014-02-26 11:00:11 -0800111 * Data structure that holds the list of commands used in display list stream
Chris Craik0776a602013-02-14 15:36:01 -0800112 */
John Reck44fd8d22014-02-26 11:00:11 -0800113class DisplayListData {
Chris Craik8afd0f22014-08-21 17:41:57 -0700114 friend class DisplayListRenderer;
Chris Craik0776a602013-02-14 15:36:01 -0800115public:
Chris Craik8afd0f22014-08-21 17:41:57 -0700116 struct Chunk {
117 // range of included ops in DLD::displayListOps
118 size_t beginOpIndex;
119 size_t endOpIndex;
120
121 // range of included children in DLD::mChildren
122 size_t beginChildIndex;
123 size_t endChildIndex;
124
125 // whether children with non-zero Z in the chunk should be reordered
126 bool reorderChildren;
127 };
128
John Reck087bc0c2014-04-04 16:20:08 -0700129 DisplayListData();
130 ~DisplayListData();
John Reck44fd8d22014-02-26 11:00:11 -0800131
Chris Craikf57776b2013-10-25 18:30:17 -0700132 // pointers to all ops within display list, pointing into allocator data
Chris Craik0776a602013-02-14 15:36:01 -0800133 Vector<DisplayListOp*> displayListOps;
Chris Craikf57776b2013-10-25 18:30:17 -0700134
Chris Craikf533e942014-01-14 22:35:37 -0800135 // index of DisplayListOp restore, after which projected descendents should be drawn
Chris Craik1df26442014-02-05 16:50:41 -0800136 int projectionReceiveIndex;
John Reck44fd8d22014-02-26 11:00:11 -0800137
138 Vector<const SkBitmap*> bitmapResources;
139 Vector<const SkBitmap*> ownedBitmapResources;
140 Vector<const Res_png_9patch*> patchResources;
141
142 Vector<const SkPaint*> paints;
143 Vector<const SkPath*> paths;
144 SortedVector<const SkPath*> sourcePaths;
145 Vector<const SkRegion*> regions;
John Reck09d5cdd2014-07-24 10:36:08 -0700146 Vector<Functor*> functors;
John Reck44fd8d22014-02-26 11:00:11 -0800147
Chris Craik8afd0f22014-08-21 17:41:57 -0700148 const Vector<Chunk>& getChunks() const {
149 return chunks;
John Reck44fd8d22014-02-26 11:00:11 -0800150 }
151
Chris Craik8afd0f22014-08-21 17:41:57 -0700152 size_t addChild(DrawRenderNodeOp* childOp);
Chris Craika7090e02014-06-20 16:01:00 -0700153 const Vector<DrawRenderNodeOp*>& children() { return mChildren; }
John Reck087bc0c2014-04-04 16:20:08 -0700154
John Reck0e89e2b2014-10-31 14:49:06 -0700155 void ref(VirtualLightRefBase* prop) {
John Reck52244ff2014-05-01 21:27:37 -0700156 mReferenceHolders.push(prop);
157 }
158
Chris Craik8afd0f22014-08-21 17:41:57 -0700159 size_t getUsedSize() {
160 return allocator.usedSize();
161 }
162 bool isEmpty() {
163 return !hasDrawOps;
164 }
165
John Reck44fd8d22014-02-26 11:00:11 -0800166private:
John Reck087bc0c2014-04-04 16:20:08 -0700167 Vector< sp<VirtualLightRefBase> > mReferenceHolders;
168
169 // list of children display lists for quick, non-drawing traversal
Chris Craika7090e02014-06-20 16:01:00 -0700170 Vector<DrawRenderNodeOp*> mChildren;
John Reck087bc0c2014-04-04 16:20:08 -0700171
Chris Craik8afd0f22014-08-21 17:41:57 -0700172 Vector<Chunk> chunks;
173
174 // allocator into which all ops were allocated
175 LinearAllocator allocator;
176 bool hasDrawOps;
177
John Reck44fd8d22014-02-26 11:00:11 -0800178 void cleanupResources();
Chris Craik0776a602013-02-14 15:36:01 -0800179};
180
Chris Craik0776a602013-02-14 15:36:01 -0800181}; // namespace uirenderer
182}; // namespace android
183
184#endif // ANDROID_HWUI_OPENGL_RENDERER_H