DisplayList.h revision 0b7e8245db728d127ada698be63d78b33fc6e4da
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#include <SkCamera.h> 21#include <SkMatrix.h> 22 23#include <private/hwui/DrawGlInfo.h> 24 25#include <utils/KeyedVector.h> 26#include <utils/LinearAllocator.h> 27#include <utils/RefBase.h> 28#include <utils/SortedVector.h> 29#include <utils/String8.h> 30 31#include <cutils/compiler.h> 32 33#include <androidfw/ResourceTypes.h> 34 35#include "Debug.h" 36#include "CanvasProperty.h" 37#include "DeferredDisplayList.h" 38#include "Matrix.h" 39#include "RenderProperties.h" 40 41#include <vector> 42 43class SkBitmap; 44class SkPaint; 45class SkPath; 46class SkRegion; 47 48namespace android { 49namespace uirenderer { 50 51class DeferredDisplayList; 52class DisplayListOp; 53class DisplayListCanvas; 54class OpenGLRenderer; 55class Rect; 56class Layer; 57 58#if HWUI_NEW_OPS 59struct RecordedOp; 60struct RenderNodeOp; 61 62typedef RecordedOp BaseOpType; 63typedef RenderNodeOp NodeOpType; 64#else 65class DrawRenderNodeOp; 66 67typedef DisplayListOp BaseOpType; 68typedef DrawRenderNodeOp NodeOpType; 69#endif 70 71/** 72 * Holds data used in the playback a tree of DisplayLists. 73 */ 74struct PlaybackStateStruct { 75protected: 76 PlaybackStateStruct(OpenGLRenderer& renderer, int replayFlags, LinearAllocator* allocator) 77 : mRenderer(renderer) 78 , mReplayFlags(replayFlags) 79 , mAllocator(allocator) {} 80 81public: 82 OpenGLRenderer& mRenderer; 83 const int mReplayFlags; 84 85 // Allocator with the lifetime of a single frame. replay uses an Allocator owned by the struct, 86 // while defer shares the DeferredDisplayList's Allocator 87 // TODO: move this allocator to be owned by object with clear frame lifecycle 88 LinearAllocator * const mAllocator; 89 90 SkPath* allocPathForFrame() { 91 return mRenderer.allocPathForFrame(); 92 } 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 103struct ReplayStateStruct : public PlaybackStateStruct { 104 ReplayStateStruct(OpenGLRenderer& renderer, Rect& dirty, int replayFlags) 105 : PlaybackStateStruct(renderer, replayFlags, &mReplayAllocator), 106 mDirty(dirty) {} 107 108 Rect& mDirty; 109 LinearAllocator mReplayAllocator; 110}; 111 112/** 113 * Data structure that holds the list of commands used in display list stream 114 */ 115class DisplayList { 116 friend class DisplayListCanvas; 117 friend class RecordingCanvas; 118public: 119 struct Chunk { 120 // range of included ops in DisplayList::ops() 121 size_t beginOpIndex; 122 size_t endOpIndex; 123 124 // range of included children in DisplayList::children() 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 DisplayList(); 133 ~DisplayList(); 134 135 // index of DisplayListOp restore, after which projected descendents should be drawn 136 int projectionReceiveIndex; 137 138 const LsaVector<Chunk>& getChunks() const { return chunks; } 139 const LsaVector<BaseOpType*>& getOps() const { return ops; } 140 141 const LsaVector<NodeOpType*>& getChildren() const { return children; } 142 143 const LsaVector<const SkBitmap*>& getBitmapResources() const { return bitmapResources; } 144 const LsaVector<Functor*>& getFunctors() const { return functors; } 145 146 size_t addChild(NodeOpType* childOp); 147 148 149 void ref(VirtualLightRefBase* prop) { 150 referenceHolders.push_back(prop); 151 } 152 153 size_t getUsedSize() { 154 return allocator.usedSize(); 155 } 156 bool isEmpty() { 157#if HWUI_NEW_OPS 158 return ops.empty(); 159#else 160 return !hasDrawOps; 161#endif 162 } 163 164private: 165 // allocator into which all ops and LsaVector arrays allocated 166 LinearAllocator allocator; 167 LinearStdAllocator<void*> stdAllocator; 168 169 LsaVector<Chunk> chunks; 170 LsaVector<BaseOpType*> ops; 171 172 // list of Ops referring to RenderNode children for quick, non-drawing traversal 173 LsaVector<NodeOpType*> children; 174 175 // Resources - Skia objects + 9 patches referred to by this DisplayList 176 LsaVector<const SkBitmap*> bitmapResources; 177 LsaVector<const SkPath*> pathResources; 178 LsaVector<const Res_png_9patch*> patchResources; 179 LsaVector<std::unique_ptr<const SkPaint>> paints; 180 LsaVector<std::unique_ptr<const SkRegion>> regions; 181 LsaVector< sp<VirtualLightRefBase> > referenceHolders; 182 183 // List of functors 184 LsaVector<Functor*> functors; 185 186 bool hasDrawOps; // only used if !HWUI_NEW_OPS 187 188 void cleanupResources(); 189}; 190 191}; // namespace uirenderer 192}; // namespace android 193 194#endif // ANDROID_HWUI_OPENGL_RENDERER_H 195