blob: b9edbe5ac2a694fd261cd86062c53baa146857d8 [file] [log] [blame]
John Reck113e0822014-03-18 09:22:59 -07001/*
2 * Copyright (C) 2014 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#ifndef RENDERNODE_H
17#define RENDERNODE_H
18
19#ifndef LOG_TAG
20 #define LOG_TAG "OpenGLRenderer"
21#endif
22
23#include <SkCamera.h>
24#include <SkMatrix.h>
25
26#include <private/hwui/DrawGlInfo.h>
27
28#include <utils/KeyedVector.h>
29#include <utils/LinearAllocator.h>
30#include <utils/RefBase.h>
31#include <utils/SortedVector.h>
32#include <utils/String8.h>
33#include <utils/Vector.h>
34
35#include <cutils/compiler.h>
36
37#include <androidfw/ResourceTypes.h>
38
39#include "Debug.h"
40#include "Matrix.h"
41#include "DeferredDisplayList.h"
42#include "DisplayList.h"
43#include "RenderProperties.h"
John Reck087bc0c2014-04-04 16:20:08 -070044#include "utils/VirtualLightRefBase.h"
John Reck113e0822014-03-18 09:22:59 -070045
46class SkBitmap;
47class SkPaint;
48class SkPath;
49class SkRegion;
50
51namespace android {
52namespace uirenderer {
53
54class DeferredDisplayList;
55class DisplayListOp;
56class DisplayListRenderer;
57class OpenGLRenderer;
58class Rect;
59class Layer;
60class SkiaShader;
61
62class ClipRectOp;
63class SaveLayerOp;
64class SaveOp;
65class RestoreToCountOp;
66class DrawDisplayListOp;
67
John Reckf4198b72014-04-09 17:00:04 -070068struct TreeInfo {
John Reck860d1552014-04-11 19:15:05 -070069 TreeInfo()
70 : hasFunctors(false)
71 , prepareTextures(false)
72 {}
73
John Reckf4198b72014-04-09 17:00:04 -070074 bool hasFunctors;
John Reck860d1552014-04-11 19:15:05 -070075 bool prepareTextures;
John Reckf4198b72014-04-09 17:00:04 -070076 // TODO: Damage calculations? Flag to skip staging pushes for RT animations?
77};
78
John Reck113e0822014-03-18 09:22:59 -070079/**
80 * Primary class for storing recorded canvas commands, as well as per-View/ViewGroup display properties.
81 *
82 * Recording of canvas commands is somewhat similar to SkPicture, except the canvas-recording
83 * functionality is split between DisplayListRenderer (which manages the recording), DisplayListData
84 * (which holds the actual data), and DisplayList (which holds properties and performs playback onto
85 * a renderer).
86 *
87 * Note that DisplayListData is swapped out from beneath an individual DisplayList when a view's
88 * recorded stream of canvas operations is refreshed. The DisplayList (and its properties) stay
89 * attached.
90 */
John Reck087bc0c2014-04-04 16:20:08 -070091class RenderNode : public VirtualLightRefBase {
John Reck113e0822014-03-18 09:22:59 -070092public:
93 ANDROID_API RenderNode();
94 ANDROID_API ~RenderNode();
95
96 // See flags defined in DisplayList.java
97 enum ReplayFlag {
98 kReplayFlag_ClipChildren = 0x1
99 };
100
John Reck113e0822014-03-18 09:22:59 -0700101 ANDROID_API static void outputLogBuffer(int fd);
102
John Reck8de65a82014-04-09 15:23:38 -0700103 ANDROID_API void setStagingDisplayList(DisplayListData* newData);
John Reck113e0822014-03-18 09:22:59 -0700104
105 void computeOrdering();
Chris Craikb265e2c2014-03-27 15:50:09 -0700106
107 void deferNodeTree(DeferStateStruct& deferStruct);
108 void deferNodeInParent(DeferStateStruct& deferStruct, const int level);
109
110 void replayNodeTree(ReplayStateStruct& replayStruct);
111 void replayNodeInParent(ReplayStateStruct& replayStruct, const int level);
John Reck113e0822014-03-18 09:22:59 -0700112
113 ANDROID_API void output(uint32_t level = 1);
114
115 bool isRenderable() const {
116 return mDisplayListData && mDisplayListData->hasDrawOps;
117 }
118
Chris Craikdefb7f32014-04-08 18:17:07 -0700119 const char* getName() const {
120 return mName.string();
121 }
122
John Reck113e0822014-03-18 09:22:59 -0700123 void setName(const char* name) {
124 if (name) {
125 char* lastPeriod = strrchr(name, '.');
126 if (lastPeriod) {
127 mName.setTo(lastPeriod + 1);
128 } else {
129 mName.setTo(name);
130 }
131 }
132 }
133
John Reckd0a0b2a2014-03-20 16:28:56 -0700134 const RenderProperties& properties() {
John Reck113e0822014-03-18 09:22:59 -0700135 return mProperties;
136 }
137
John Reckd0a0b2a2014-03-20 16:28:56 -0700138 const RenderProperties& stagingProperties() {
139 return mStagingProperties;
140 }
141
142 RenderProperties& mutateStagingProperties() {
143 mNeedsPropertiesSync = true;
144 return mStagingProperties;
145 }
146
John Reck113e0822014-03-18 09:22:59 -0700147 int getWidth() {
148 return properties().getWidth();
149 }
150
151 int getHeight() {
152 return properties().getHeight();
153 }
154
John Reckf4198b72014-04-09 17:00:04 -0700155 ANDROID_API void prepareTree(TreeInfo& info);
John Reck668f0e32014-03-26 15:10:40 -0700156
John Reck113e0822014-03-18 09:22:59 -0700157private:
158 typedef key_value_pair_t<float, DrawDisplayListOp*> ZDrawDisplayListOpPair;
159
160 static size_t findNonNegativeIndex(const Vector<ZDrawDisplayListOpPair>& nodes) {
161 for (size_t i = 0; i < nodes.size(); i++) {
162 if (nodes[i].key >= 0.0f) return i;
163 }
164 return nodes.size();
165 }
166
167 enum ChildrenSelectMode {
168 kNegativeZChildren,
169 kPositiveZChildren
170 };
171
John Reck113e0822014-03-18 09:22:59 -0700172 void applyViewPropertyTransforms(mat4& matrix, bool true3dTransform = false);
173
174 void computeOrderingImpl(DrawDisplayListOp* opState,
Chris Craik3f0854292014-04-15 16:18:08 -0700175 const SkPath* outlineOfProjectionSurface,
John Reck113e0822014-03-18 09:22:59 -0700176 Vector<DrawDisplayListOp*>* compositedChildrenOfProjectionSurface,
177 const mat4* transformFromProjectionSurface);
178
179 template <class T>
Chris Craikb265e2c2014-03-27 15:50:09 -0700180 inline void setViewProperties(OpenGLRenderer& renderer, T& handler);
John Reck113e0822014-03-18 09:22:59 -0700181
182 void buildZSortedChildList(Vector<ZDrawDisplayListOpPair>& zTranslatedNodes);
183
Chris Craikb265e2c2014-03-27 15:50:09 -0700184 template<class T>
185 inline void issueDrawShadowOperation(const Matrix4& transformFromParent, T& handler);
186
John Reck113e0822014-03-18 09:22:59 -0700187 template <class T>
Chris Craikb265e2c2014-03-27 15:50:09 -0700188 inline void issueOperationsOf3dChildren(const Vector<ZDrawDisplayListOpPair>& zTranslatedNodes,
John Reck113e0822014-03-18 09:22:59 -0700189 ChildrenSelectMode mode, OpenGLRenderer& renderer, T& handler);
190
191 template <class T>
Chris Craikb265e2c2014-03-27 15:50:09 -0700192 inline void issueOperationsOfProjectedChildren(OpenGLRenderer& renderer, T& handler);
John Reck113e0822014-03-18 09:22:59 -0700193
Chris Craikb265e2c2014-03-27 15:50:09 -0700194 /**
195 * Issue the RenderNode's operations into a handler, recursing for subtrees through
196 * DrawDisplayListOp's defer() or replay() methods
197 */
John Reck113e0822014-03-18 09:22:59 -0700198 template <class T>
Chris Craikb265e2c2014-03-27 15:50:09 -0700199 inline void issueOperations(OpenGLRenderer& renderer, T& handler);
John Reck113e0822014-03-18 09:22:59 -0700200
201 class TextContainer {
202 public:
203 size_t length() const {
204 return mByteLength;
205 }
206
207 const char* text() const {
208 return (const char*) mText;
209 }
210
211 size_t mByteLength;
212 const char* mText;
213 };
214
John Reckf4198b72014-04-09 17:00:04 -0700215 void prepareTreeImpl(TreeInfo& info);
216 void pushStagingChanges(TreeInfo& info);
217 void prepareSubTree(TreeInfo& info, DisplayListData* subtree);
John Reck8de65a82014-04-09 15:23:38 -0700218
John Reck113e0822014-03-18 09:22:59 -0700219 String8 mName;
John Reck113e0822014-03-18 09:22:59 -0700220
John Reckd0a0b2a2014-03-20 16:28:56 -0700221 bool mNeedsPropertiesSync;
John Reck113e0822014-03-18 09:22:59 -0700222 RenderProperties mProperties;
John Reckd0a0b2a2014-03-20 16:28:56 -0700223 RenderProperties mStagingProperties;
224
John Reck8de65a82014-04-09 15:23:38 -0700225 bool mNeedsDisplayListDataSync;
John Reck113e0822014-03-18 09:22:59 -0700226 DisplayListData* mDisplayListData;
John Reck8de65a82014-04-09 15:23:38 -0700227 DisplayListData* mStagingDisplayListData;
John Reck113e0822014-03-18 09:22:59 -0700228
229 /**
230 * Draw time state - these properties are only set and used during rendering
231 */
232
233 // for projection surfaces, contains a list of all children items
234 Vector<DrawDisplayListOp*> mProjectedNodes;
235}; // class RenderNode
236
237} /* namespace uirenderer */
238} /* namespace android */
239
240#endif /* RENDERNODE_H */