DisplayList.h revision 3d4eed7f1aa99401dabe2e45b82f98fb4fc2d754
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 */ 70struct 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. replay uses an Allocator owned by the struct, 82 // while defer shares the DeferredDisplayList's Allocator 83 // TODO: move this allocator to be owned by object with clear frame lifecycle 84 LinearAllocator * const mAllocator; 85 86 SkPath* allocPathForFrame() { 87 return mRenderer.allocPathForFrame(); 88 } 89}; 90 91struct DeferStateStruct : public PlaybackStateStruct { 92 DeferStateStruct(DeferredDisplayList& deferredList, OpenGLRenderer& renderer, int replayFlags) 93 : PlaybackStateStruct(renderer, replayFlags, &(deferredList.mAllocator)), 94 mDeferredList(deferredList) {} 95 96 DeferredDisplayList& mDeferredList; 97}; 98 99struct ReplayStateStruct : public PlaybackStateStruct { 100 ReplayStateStruct(OpenGLRenderer& renderer, Rect& dirty, int replayFlags) 101 : PlaybackStateStruct(renderer, replayFlags, &mReplayAllocator), 102 mDirty(dirty) {} 103 104 Rect& mDirty; 105 LinearAllocator mReplayAllocator; 106}; 107 108/** 109 * Data structure that holds the list of commands used in display list stream 110 */ 111class DisplayListData { 112 friend class DisplayListRenderer; 113public: 114 struct Chunk { 115 // range of included ops in DLD::displayListOps 116 size_t beginOpIndex; 117 size_t endOpIndex; 118 119 // range of included children in DLD::mChildren 120 size_t beginChildIndex; 121 size_t endChildIndex; 122 123 // whether children with non-zero Z in the chunk should be reordered 124 bool reorderChildren; 125 }; 126 127 DisplayListData(); 128 ~DisplayListData(); 129 130 // pointers to all ops within display list, pointing into allocator data 131 Vector<DisplayListOp*> displayListOps; 132 133 // index of DisplayListOp restore, after which projected descendents should be drawn 134 int projectionReceiveIndex; 135 136 Vector<const SkBitmap*> bitmapResources; 137 Vector<const Res_png_9patch*> patchResources; 138 139 std::vector<std::unique_ptr<const SkPaint>> paints; 140 std::vector<std::unique_ptr<const SkRegion>> regions; 141 std::vector<std::unique_ptr<const SkPath>> paths; 142 SortedVector<const SkPath*> sourcePaths; 143 Vector<Functor*> functors; 144 145 const Vector<Chunk>& getChunks() const { 146 return chunks; 147 } 148 149 size_t addChild(DrawRenderNodeOp* childOp); 150 const Vector<DrawRenderNodeOp*>& children() { return mChildren; } 151 152 void ref(VirtualLightRefBase* prop) { 153 mReferenceHolders.push(prop); 154 } 155 156 size_t getUsedSize() { 157 return allocator.usedSize(); 158 } 159 bool isEmpty() { 160 return !hasDrawOps; 161 } 162 163private: 164 Vector< sp<VirtualLightRefBase> > mReferenceHolders; 165 166 // list of children display lists for quick, non-drawing traversal 167 Vector<DrawRenderNodeOp*> mChildren; 168 169 Vector<Chunk> chunks; 170 171 // allocator into which all ops were allocated 172 LinearAllocator allocator; 173 bool hasDrawOps; 174 175 void cleanupResources(); 176}; 177 178}; // namespace uirenderer 179}; // namespace android 180 181#endif // ANDROID_HWUI_OPENGL_RENDERER_H 182