RenderNode.h revision b265e2ca50b6ceb2fd2987ef1f7d063b1bde19ae
1/* 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" 44 45class SkBitmap; 46class SkPaint; 47class SkPath; 48class SkRegion; 49 50namespace android { 51namespace uirenderer { 52 53class DeferredDisplayList; 54class DisplayListOp; 55class DisplayListRenderer; 56class OpenGLRenderer; 57class Rect; 58class Layer; 59class SkiaShader; 60 61class ClipRectOp; 62class SaveLayerOp; 63class SaveOp; 64class RestoreToCountOp; 65class DrawDisplayListOp; 66 67/** 68 * Primary class for storing recorded canvas commands, as well as per-View/ViewGroup display properties. 69 * 70 * Recording of canvas commands is somewhat similar to SkPicture, except the canvas-recording 71 * functionality is split between DisplayListRenderer (which manages the recording), DisplayListData 72 * (which holds the actual data), and DisplayList (which holds properties and performs playback onto 73 * a renderer). 74 * 75 * Note that DisplayListData is swapped out from beneath an individual DisplayList when a view's 76 * recorded stream of canvas operations is refreshed. The DisplayList (and its properties) stay 77 * attached. 78 */ 79class RenderNode { 80public: 81 ANDROID_API RenderNode(); 82 ANDROID_API ~RenderNode(); 83 84 // See flags defined in DisplayList.java 85 enum ReplayFlag { 86 kReplayFlag_ClipChildren = 0x1 87 }; 88 89 ANDROID_API static void destroyDisplayListDeferred(RenderNode* displayList); 90 ANDROID_API static void outputLogBuffer(int fd); 91 92 ANDROID_API void setData(DisplayListData* newData); 93 94 void computeOrdering(); 95 96 void deferNodeTree(DeferStateStruct& deferStruct); 97 void deferNodeInParent(DeferStateStruct& deferStruct, const int level); 98 99 void replayNodeTree(ReplayStateStruct& replayStruct); 100 void replayNodeInParent(ReplayStateStruct& replayStruct, const int level); 101 102 ANDROID_API void output(uint32_t level = 1); 103 104 bool isRenderable() const { 105 return mDisplayListData && mDisplayListData->hasDrawOps; 106 } 107 108 void setName(const char* name) { 109 if (name) { 110 char* lastPeriod = strrchr(name, '.'); 111 if (lastPeriod) { 112 mName.setTo(lastPeriod + 1); 113 } else { 114 mName.setTo(name); 115 } 116 } 117 } 118 119 const RenderProperties& properties() { 120 return mProperties; 121 } 122 123 const RenderProperties& stagingProperties() { 124 return mStagingProperties; 125 } 126 127 RenderProperties& mutateStagingProperties() { 128 mNeedsPropertiesSync = true; 129 return mStagingProperties; 130 } 131 132 bool isProjectionReceiver() { 133 return properties().isProjectionReceiver(); 134 } 135 136 int getWidth() { 137 return properties().getWidth(); 138 } 139 140 int getHeight() { 141 return properties().getHeight(); 142 } 143 144 ANDROID_API void updateProperties(); 145 146 // Returns true if this RenderNode or any of its children have functors 147 bool hasFunctors(); 148 149private: 150 typedef key_value_pair_t<float, DrawDisplayListOp*> ZDrawDisplayListOpPair; 151 152 static size_t findNonNegativeIndex(const Vector<ZDrawDisplayListOpPair>& nodes) { 153 for (size_t i = 0; i < nodes.size(); i++) { 154 if (nodes[i].key >= 0.0f) return i; 155 } 156 return nodes.size(); 157 } 158 159 enum ChildrenSelectMode { 160 kNegativeZChildren, 161 kPositiveZChildren 162 }; 163 164 void applyViewPropertyTransforms(mat4& matrix, bool true3dTransform = false); 165 166 void computeOrderingImpl(DrawDisplayListOp* opState, 167 Vector<DrawDisplayListOp*>* compositedChildrenOfProjectionSurface, 168 const mat4* transformFromProjectionSurface); 169 170 template <class T> 171 inline void setViewProperties(OpenGLRenderer& renderer, T& handler); 172 173 void buildZSortedChildList(Vector<ZDrawDisplayListOpPair>& zTranslatedNodes); 174 175 template<class T> 176 inline void issueDrawShadowOperation(const Matrix4& transformFromParent, T& handler); 177 178 template <class T> 179 inline void issueOperationsOf3dChildren(const Vector<ZDrawDisplayListOpPair>& zTranslatedNodes, 180 ChildrenSelectMode mode, OpenGLRenderer& renderer, T& handler); 181 182 template <class T> 183 inline void issueOperationsOfProjectedChildren(OpenGLRenderer& renderer, T& handler); 184 185 /** 186 * Issue the RenderNode's operations into a handler, recursing for subtrees through 187 * DrawDisplayListOp's defer() or replay() methods 188 */ 189 template <class T> 190 inline void issueOperations(OpenGLRenderer& renderer, T& handler); 191 192 class TextContainer { 193 public: 194 size_t length() const { 195 return mByteLength; 196 } 197 198 const char* text() const { 199 return (const char*) mText; 200 } 201 202 size_t mByteLength; 203 const char* mText; 204 }; 205 206 String8 mName; 207 bool mDestroyed; // used for debugging crash, TODO: remove once invalid state crash fixed 208 209 bool mNeedsPropertiesSync; 210 RenderProperties mProperties; 211 RenderProperties mStagingProperties; 212 213 DisplayListData* mDisplayListData; 214 215 /** 216 * Draw time state - these properties are only set and used during rendering 217 */ 218 219 // for projection surfaces, contains a list of all children items 220 Vector<DrawDisplayListOp*> mProjectedNodes; 221}; // class RenderNode 222 223} /* namespace uirenderer */ 224} /* namespace android */ 225 226#endif /* RENDERNODE_H */ 227