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