blob: 9ede00307076f08f912d73f75f4aa20d0c90ad0f [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"
Tom Hudson2dc236b2014-10-15 15:46:42 -040041#include "CanvasProperty.h"
Chris Craikf57776b2013-10-25 18:30:17 -070042#include "DeferredDisplayList.h"
Tom Hudson2dc236b2014-10-15 15:46:42 -040043#include "Matrix.h"
John Reckacb6f072014-03-12 16:11:23 -070044#include "RenderProperties.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 -080060
Chris Craikff785832013-03-08 13:12:16 -080061class ClipRectOp;
62class SaveLayerOp;
63class SaveOp;
64class RestoreToCountOp;
Chris Craika7090e02014-06-20 16:01:00 -070065class DrawRenderNodeOp;
Chris Craikff785832013-03-08 13:12:16 -080066
Chris Craikf57776b2013-10-25 18:30:17 -070067/**
68 * Holds data used in the playback a tree of DisplayLists.
69 */
70class PlaybackStateStruct {
71protected:
72 PlaybackStateStruct(OpenGLRenderer& renderer, int replayFlags, LinearAllocator* allocator)
Chris Craik74669862014-08-07 17:27:30 -070073 : mRenderer(renderer)
74 , mReplayFlags(replayFlags)
75 , mAllocator(allocator) {}
Chris Craikf57776b2013-10-25 18:30:17 -070076
77public:
Chris Craikff785832013-03-08 13:12:16 -080078 OpenGLRenderer& mRenderer;
79 const int mReplayFlags;
Chris Craikf57776b2013-10-25 18:30:17 -070080
81 // Allocator with the lifetime of a single frame.
82 // replay uses an Allocator owned by the struct, while defer shares the DeferredDisplayList's Allocator
83 LinearAllocator * const mAllocator;
Chris Craik74669862014-08-07 17:27:30 -070084
85 SkPath* allocPathForFrame() {
86 mTempPaths.push_back();
87 return &mTempPaths.back();
88 }
89
90private:
91 // Paths kept alive for the duration of the frame
92 std::vector<SkPath> mTempPaths;
Chris Craikff785832013-03-08 13:12:16 -080093};
94
Andreas Gampeedaecc12014-11-10 20:54:07 -080095struct DeferStateStruct : public PlaybackStateStruct {
Chris Craikf57776b2013-10-25 18:30:17 -070096 DeferStateStruct(DeferredDisplayList& deferredList, OpenGLRenderer& renderer, int replayFlags)
Chris Craik9f68c092014-01-10 10:30:57 -080097 : PlaybackStateStruct(renderer, replayFlags, &(deferredList.mAllocator)),
98 mDeferredList(deferredList) {}
Chris Craikf57776b2013-10-25 18:30:17 -070099
100 DeferredDisplayList& mDeferredList;
101};
102
103class ReplayStateStruct : public PlaybackStateStruct {
104public:
Chris Craikff785832013-03-08 13:12:16 -0800105 ReplayStateStruct(OpenGLRenderer& renderer, Rect& dirty, int replayFlags)
Chris Craikf57776b2013-10-25 18:30:17 -0700106 : PlaybackStateStruct(renderer, replayFlags, &mReplayAllocator),
Tom Hudson107843d2014-09-08 11:26:26 -0400107 mDirty(dirty) {}
Chris Craikf57776b2013-10-25 18:30:17 -0700108
Chris Craikff785832013-03-08 13:12:16 -0800109 Rect& mDirty;
Chris Craikf57776b2013-10-25 18:30:17 -0700110 LinearAllocator mReplayAllocator;
Chris Craikff785832013-03-08 13:12:16 -0800111};
112
Chris Craik0776a602013-02-14 15:36:01 -0800113/**
John Reck44fd8d22014-02-26 11:00:11 -0800114 * Data structure that holds the list of commands used in display list stream
Chris Craik0776a602013-02-14 15:36:01 -0800115 */
John Reck44fd8d22014-02-26 11:00:11 -0800116class DisplayListData {
Chris Craik8afd0f22014-08-21 17:41:57 -0700117 friend class DisplayListRenderer;
Chris Craik0776a602013-02-14 15:36:01 -0800118public:
Chris Craik8afd0f22014-08-21 17:41:57 -0700119 struct Chunk {
120 // range of included ops in DLD::displayListOps
121 size_t beginOpIndex;
122 size_t endOpIndex;
123
124 // range of included children in DLD::mChildren
125 size_t beginChildIndex;
126 size_t endChildIndex;
127
128 // whether children with non-zero Z in the chunk should be reordered
129 bool reorderChildren;
130 };
131
John Reck087bc0c2014-04-04 16:20:08 -0700132 DisplayListData();
133 ~DisplayListData();
John Reck44fd8d22014-02-26 11:00:11 -0800134
Chris Craikf57776b2013-10-25 18:30:17 -0700135 // pointers to all ops within display list, pointing into allocator data
Chris Craik0776a602013-02-14 15:36:01 -0800136 Vector<DisplayListOp*> displayListOps;
Chris Craikf57776b2013-10-25 18:30:17 -0700137
Chris Craikf533e942014-01-14 22:35:37 -0800138 // index of DisplayListOp restore, after which projected descendents should be drawn
Chris Craik1df26442014-02-05 16:50:41 -0800139 int projectionReceiveIndex;
John Reck44fd8d22014-02-26 11:00:11 -0800140
141 Vector<const SkBitmap*> bitmapResources;
142 Vector<const SkBitmap*> ownedBitmapResources;
143 Vector<const Res_png_9patch*> patchResources;
144
145 Vector<const SkPaint*> paints;
146 Vector<const SkPath*> paths;
147 SortedVector<const SkPath*> sourcePaths;
148 Vector<const SkRegion*> regions;
John Reck09d5cdd2014-07-24 10:36:08 -0700149 Vector<Functor*> functors;
John Reck44fd8d22014-02-26 11:00:11 -0800150
Chris Craik8afd0f22014-08-21 17:41:57 -0700151 const Vector<Chunk>& getChunks() const {
152 return chunks;
John Reck44fd8d22014-02-26 11:00:11 -0800153 }
154
Chris Craik8afd0f22014-08-21 17:41:57 -0700155 size_t addChild(DrawRenderNodeOp* childOp);
Chris Craika7090e02014-06-20 16:01:00 -0700156 const Vector<DrawRenderNodeOp*>& children() { return mChildren; }
John Reck087bc0c2014-04-04 16:20:08 -0700157
John Reck0e89e2b2014-10-31 14:49:06 -0700158 void ref(VirtualLightRefBase* prop) {
John Reck52244ff2014-05-01 21:27:37 -0700159 mReferenceHolders.push(prop);
160 }
161
Chris Craik8afd0f22014-08-21 17:41:57 -0700162 size_t getUsedSize() {
163 return allocator.usedSize();
164 }
165 bool isEmpty() {
166 return !hasDrawOps;
167 }
168
John Reck44fd8d22014-02-26 11:00:11 -0800169private:
John Reck087bc0c2014-04-04 16:20:08 -0700170 Vector< sp<VirtualLightRefBase> > mReferenceHolders;
171
172 // list of children display lists for quick, non-drawing traversal
Chris Craika7090e02014-06-20 16:01:00 -0700173 Vector<DrawRenderNodeOp*> mChildren;
John Reck087bc0c2014-04-04 16:20:08 -0700174
Chris Craik8afd0f22014-08-21 17:41:57 -0700175 Vector<Chunk> chunks;
176
177 // allocator into which all ops were allocated
178 LinearAllocator allocator;
179 bool hasDrawOps;
180
John Reck44fd8d22014-02-26 11:00:11 -0800181 void cleanupResources();
Chris Craik0776a602013-02-14 15:36:01 -0800182};
183
Chris Craik0776a602013-02-14 15:36:01 -0800184}; // namespace uirenderer
185}; // namespace android
186
187#endif // ANDROID_HWUI_OPENGL_RENDERER_H