DisplayList.h revision 5a4690bf26932c0d6940e4af8516d920e09ae81a
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#include <utils/Vector.h> 31 32#include <cutils/compiler.h> 33 34#include <androidfw/ResourceTypes.h> 35 36#include "Debug.h" 37#include "CanvasProperty.h" 38#include "DeferredDisplayList.h" 39#include "Matrix.h" 40#include "RenderProperties.h" 41 42class SkBitmap; 43class SkPaint; 44class SkPath; 45class SkRegion; 46 47namespace android { 48namespace uirenderer { 49 50class DeferredDisplayList; 51class DisplayListOp; 52class DisplayListCanvas; 53class OpenGLRenderer; 54class Rect; 55class Layer; 56 57class ClipRectOp; 58class SaveLayerOp; 59class SaveOp; 60class RestoreToCountOp; 61class DrawRenderNodeOp; 62 63/** 64 * Holds data used in the playback a tree of DisplayLists. 65 */ 66struct PlaybackStateStruct { 67protected: 68 PlaybackStateStruct(OpenGLRenderer& renderer, int replayFlags, LinearAllocator* allocator) 69 : mRenderer(renderer) 70 , mReplayFlags(replayFlags) 71 , mAllocator(allocator) {} 72 73public: 74 OpenGLRenderer& mRenderer; 75 const int mReplayFlags; 76 77 // Allocator with the lifetime of a single frame. replay uses an Allocator owned by the struct, 78 // while defer shares the DeferredDisplayList's Allocator 79 // TODO: move this allocator to be owned by object with clear frame lifecycle 80 LinearAllocator * const mAllocator; 81 82 SkPath* allocPathForFrame() { 83 return mRenderer.allocPathForFrame(); 84 } 85}; 86 87struct DeferStateStruct : public PlaybackStateStruct { 88 DeferStateStruct(DeferredDisplayList& deferredList, OpenGLRenderer& renderer, int replayFlags) 89 : PlaybackStateStruct(renderer, replayFlags, &(deferredList.mAllocator)), 90 mDeferredList(deferredList) {} 91 92 DeferredDisplayList& mDeferredList; 93}; 94 95struct ReplayStateStruct : public PlaybackStateStruct { 96 ReplayStateStruct(OpenGLRenderer& renderer, Rect& dirty, int replayFlags) 97 : PlaybackStateStruct(renderer, replayFlags, &mReplayAllocator), 98 mDirty(dirty) {} 99 100 Rect& mDirty; 101 LinearAllocator mReplayAllocator; 102}; 103 104/** 105 * Data structure that holds the list of commands used in display list stream 106 */ 107class DisplayListData { 108 friend class DisplayListCanvas; 109public: 110 struct Chunk { 111 // range of included ops in DLD::displayListOps 112 size_t beginOpIndex; 113 size_t endOpIndex; 114 115 // range of included children in DLD::mChildren 116 size_t beginChildIndex; 117 size_t endChildIndex; 118 119 // whether children with non-zero Z in the chunk should be reordered 120 bool reorderChildren; 121 }; 122 123 DisplayListData(); 124 ~DisplayListData(); 125 126 // pointers to all ops within display list, pointing into allocator data 127 Vector<DisplayListOp*> displayListOps; 128 129 // index of DisplayListOp restore, after which projected descendents should be drawn 130 int projectionReceiveIndex; 131 132 Vector<const SkBitmap*> bitmapResources; 133 Vector<const SkPath*> pathResources; 134 Vector<const Res_png_9patch*> patchResources; 135 136 std::vector<std::unique_ptr<const SkPaint>> paints; 137 std::vector<std::unique_ptr<const SkRegion>> regions; 138 Vector<Functor*> functors; 139 140 const Vector<Chunk>& getChunks() const { 141 return chunks; 142 } 143 144 size_t addChild(DrawRenderNodeOp* childOp); 145 const Vector<DrawRenderNodeOp*>& children() { return mChildren; } 146 147 void ref(VirtualLightRefBase* prop) { 148 mReferenceHolders.push(prop); 149 } 150 151 size_t getUsedSize() { 152 return allocator.usedSize(); 153 } 154 bool isEmpty() { 155 return !hasDrawOps; 156 } 157 158private: 159 Vector< sp<VirtualLightRefBase> > mReferenceHolders; 160 161 // list of children display lists for quick, non-drawing traversal 162 Vector<DrawRenderNodeOp*> mChildren; 163 164 Vector<Chunk> chunks; 165 166 // allocator into which all ops were allocated 167 LinearAllocator allocator; 168 bool hasDrawOps; 169 170 void cleanupResources(); 171}; 172 173}; // namespace uirenderer 174}; // namespace android 175 176#endif // ANDROID_HWUI_OPENGL_RENDERER_H 177