DisplayList.h revision edaecc1db0584fa017822dfc2da0c968b53967e6
1/* 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 20#ifndef LOG_TAG 21 #define LOG_TAG "OpenGLRenderer" 22#endif 23 24#include <SkCamera.h> 25#include <SkMatrix.h> 26 27#include <private/hwui/DrawGlInfo.h> 28 29#include <utils/KeyedVector.h> 30#include <utils/LinearAllocator.h> 31#include <utils/RefBase.h> 32#include <utils/SortedVector.h> 33#include <utils/String8.h> 34#include <utils/Vector.h> 35 36#include <cutils/compiler.h> 37 38#include <androidfw/ResourceTypes.h> 39 40#include "Debug.h" 41#include "CanvasProperty.h" 42#include "DeferredDisplayList.h" 43#include "Matrix.h" 44#include "RenderProperties.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; 60 61class ClipRectOp; 62class SaveLayerOp; 63class SaveOp; 64class RestoreToCountOp; 65class DrawRenderNodeOp; 66 67/** 68 * Holds data used in the playback a tree of DisplayLists. 69 */ 70class PlaybackStateStruct { 71protected: 72 PlaybackStateStruct(OpenGLRenderer& renderer, int replayFlags, LinearAllocator* allocator) 73 : mRenderer(renderer) 74 , mReplayFlags(replayFlags) 75 , mAllocator(allocator) {} 76 77public: 78 OpenGLRenderer& mRenderer; 79 const int mReplayFlags; 80 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; 84 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; 93}; 94 95struct DeferStateStruct : public PlaybackStateStruct { 96 DeferStateStruct(DeferredDisplayList& deferredList, OpenGLRenderer& renderer, int replayFlags) 97 : PlaybackStateStruct(renderer, replayFlags, &(deferredList.mAllocator)), 98 mDeferredList(deferredList) {} 99 100 DeferredDisplayList& mDeferredList; 101}; 102 103class ReplayStateStruct : public PlaybackStateStruct { 104public: 105 ReplayStateStruct(OpenGLRenderer& renderer, Rect& dirty, int replayFlags) 106 : PlaybackStateStruct(renderer, replayFlags, &mReplayAllocator), 107 mDirty(dirty) {} 108 109 Rect& mDirty; 110 LinearAllocator mReplayAllocator; 111}; 112 113/** 114 * Data structure that holds the list of commands used in display list stream 115 */ 116class DisplayListData { 117 friend class DisplayListRenderer; 118public: 119 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 132 DisplayListData(); 133 ~DisplayListData(); 134 135 // pointers to all ops within display list, pointing into allocator data 136 Vector<DisplayListOp*> displayListOps; 137 138 // index of DisplayListOp restore, after which projected descendents should be drawn 139 int projectionReceiveIndex; 140 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; 149 Vector<Functor*> functors; 150 151 const Vector<Chunk>& getChunks() const { 152 return chunks; 153 } 154 155 size_t addChild(DrawRenderNodeOp* childOp); 156 const Vector<DrawRenderNodeOp*>& children() { return mChildren; } 157 158 void ref(VirtualLightRefBase* prop) { 159 mReferenceHolders.push(prop); 160 } 161 162 size_t getUsedSize() { 163 return allocator.usedSize(); 164 } 165 bool isEmpty() { 166 return !hasDrawOps; 167 } 168 169private: 170 Vector< sp<VirtualLightRefBase> > mReferenceHolders; 171 172 // list of children display lists for quick, non-drawing traversal 173 Vector<DrawRenderNodeOp*> mChildren; 174 175 Vector<Chunk> chunks; 176 177 // allocator into which all ops were allocated 178 LinearAllocator allocator; 179 bool hasDrawOps; 180 181 void cleanupResources(); 182}; 183 184}; // namespace uirenderer 185}; // namespace android 186 187#endif // ANDROID_HWUI_OPENGL_RENDERER_H 188