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