RenderNode.h revision d0a0b2a3140bfb1819a116413ce9d81886697a07
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 void defer(DeferStateStruct& deferStruct, const int level); 96 void replay(ReplayStateStruct& replayStruct, const int level); 97 98 ANDROID_API void output(uint32_t level = 1); 99 100 bool isRenderable() const { 101 return mDisplayListData && mDisplayListData->hasDrawOps; 102 } 103 104 void setName(const char* name) { 105 if (name) { 106 char* lastPeriod = strrchr(name, '.'); 107 if (lastPeriod) { 108 mName.setTo(lastPeriod + 1); 109 } else { 110 mName.setTo(name); 111 } 112 } 113 } 114 115 const RenderProperties& properties() { 116 return mProperties; 117 } 118 119 const RenderProperties& stagingProperties() { 120 return mStagingProperties; 121 } 122 123 RenderProperties& mutateStagingProperties() { 124 mNeedsPropertiesSync = true; 125 return mStagingProperties; 126 } 127 128 bool isProjectionReceiver() { 129 return properties().isProjectionReceiver(); 130 } 131 132 int getWidth() { 133 return properties().getWidth(); 134 } 135 136 int getHeight() { 137 return properties().getHeight(); 138 } 139 140 void updateProperties(); 141 142private: 143 typedef key_value_pair_t<float, DrawDisplayListOp*> ZDrawDisplayListOpPair; 144 145 static size_t findNonNegativeIndex(const Vector<ZDrawDisplayListOpPair>& nodes) { 146 for (size_t i = 0; i < nodes.size(); i++) { 147 if (nodes[i].key >= 0.0f) return i; 148 } 149 return nodes.size(); 150 } 151 152 enum ChildrenSelectMode { 153 kNegativeZChildren, 154 kPositiveZChildren 155 }; 156 157 void applyViewPropertyTransforms(mat4& matrix, bool true3dTransform = false); 158 159 void computeOrderingImpl(DrawDisplayListOp* opState, 160 Vector<DrawDisplayListOp*>* compositedChildrenOfProjectionSurface, 161 const mat4* transformFromProjectionSurface); 162 163 template <class T> 164 inline void setViewProperties(OpenGLRenderer& renderer, T& handler, const int level); 165 166 void buildZSortedChildList(Vector<ZDrawDisplayListOpPair>& zTranslatedNodes); 167 168 template <class T> 169 inline void iterate3dChildren(const Vector<ZDrawDisplayListOpPair>& zTranslatedNodes, 170 ChildrenSelectMode mode, OpenGLRenderer& renderer, T& handler); 171 172 template <class T> 173 inline void iterateProjectedChildren(OpenGLRenderer& renderer, T& handler, const int level); 174 175 template <class T> 176 inline void iterate(OpenGLRenderer& renderer, T& handler, const int level); 177 178 class TextContainer { 179 public: 180 size_t length() const { 181 return mByteLength; 182 } 183 184 const char* text() const { 185 return (const char*) mText; 186 } 187 188 size_t mByteLength; 189 const char* mText; 190 }; 191 192 String8 mName; 193 bool mDestroyed; // used for debugging crash, TODO: remove once invalid state crash fixed 194 195 bool mNeedsPropertiesSync; 196 RenderProperties mProperties; 197 RenderProperties mStagingProperties; 198 199 DisplayListData* mDisplayListData; 200 201 /** 202 * Draw time state - these properties are only set and used during rendering 203 */ 204 205 // for projection surfaces, contains a list of all children items 206 Vector<DrawDisplayListOp*> mProjectedNodes; 207}; // class RenderNode 208 209} /* namespace uirenderer */ 210} /* namespace android */ 211 212#endif /* RENDERNODE_H */ 213