DisplayList.h revision 09d5cddf67b676018700bcc10a72242641cd7eec
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), mReplayFlags(replayFlags), mAllocator(allocator){} 73 74public: 75 OpenGLRenderer& mRenderer; 76 const int mReplayFlags; 77 78 // Allocator with the lifetime of a single frame. 79 // replay uses an Allocator owned by the struct, while defer shares the DeferredDisplayList's Allocator 80 LinearAllocator * const mAllocator; 81}; 82 83class DeferStateStruct : public PlaybackStateStruct { 84public: 85 DeferStateStruct(DeferredDisplayList& deferredList, OpenGLRenderer& renderer, int replayFlags) 86 : PlaybackStateStruct(renderer, replayFlags, &(deferredList.mAllocator)), 87 mDeferredList(deferredList) {} 88 89 DeferredDisplayList& mDeferredList; 90}; 91 92class ReplayStateStruct : public PlaybackStateStruct { 93public: 94 ReplayStateStruct(OpenGLRenderer& renderer, Rect& dirty, int replayFlags) 95 : PlaybackStateStruct(renderer, replayFlags, &mReplayAllocator), 96 mDirty(dirty), mDrawGlStatus(DrawGlInfo::kStatusDone) {} 97 98 Rect& mDirty; 99 status_t mDrawGlStatus; 100 LinearAllocator mReplayAllocator; 101}; 102 103/** 104 * Data structure that holds the list of commands used in display list stream 105 */ 106class DisplayListData { 107public: 108 DisplayListData(); 109 ~DisplayListData(); 110 111 // allocator into which all ops were allocated 112 LinearAllocator allocator; 113 114 // pointers to all ops within display list, pointing into allocator data 115 Vector<DisplayListOp*> displayListOps; 116 117 // index of DisplayListOp restore, after which projected descendents should be drawn 118 int projectionReceiveIndex; 119 120 Vector<const SkBitmap*> bitmapResources; 121 Vector<const SkBitmap*> ownedBitmapResources; 122 Vector<const Res_png_9patch*> patchResources; 123 124 Vector<const SkPaint*> paints; 125 Vector<const SkPath*> paths; 126 SortedVector<const SkPath*> sourcePaths; 127 Vector<const SkRegion*> regions; 128 Vector<Layer*> layers; 129 Vector<Functor*> functors; 130 bool hasDrawOps; 131 132 bool isEmpty() { 133 return !displayListOps.size(); 134 } 135 136 void addChild(DrawRenderNodeOp* childOp); 137 const Vector<DrawRenderNodeOp*>& children() { return mChildren; } 138 139 void refProperty(CanvasPropertyPrimitive* prop) { 140 mReferenceHolders.push(prop); 141 } 142 143 void refProperty(CanvasPropertyPaint* prop) { 144 mReferenceHolders.push(prop); 145 } 146 147private: 148 Vector< sp<VirtualLightRefBase> > mReferenceHolders; 149 150 // list of children display lists for quick, non-drawing traversal 151 Vector<DrawRenderNodeOp*> mChildren; 152 153 void cleanupResources(); 154}; 155 156}; // namespace uirenderer 157}; // namespace android 158 159#endif // ANDROID_HWUI_OPENGL_RENDERER_H 160