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