blob: 79a2f6101f5fb5e9662d184f4596ca2031d5c301 [file] [log] [blame]
Chris Craik0776a602013-02-14 15:36:01 -08001/*
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
Romain Guy7031ff62013-02-22 11:48:16 -080020#ifndef LOG_TAG
21 #define LOG_TAG "OpenGLRenderer"
22#endif
23
Chris Craik0776a602013-02-14 15:36:01 -080024#include <SkCamera.h>
25#include <SkMatrix.h>
26
Chris Craikff785832013-03-08 13:12:16 -080027#include <private/hwui/DrawGlInfo.h>
28
Chris Craikf57776b2013-10-25 18:30:17 -070029#include <utils/KeyedVector.h>
Chris Craikc1c5f082013-09-11 16:23:37 -070030#include <utils/LinearAllocator.h>
Chris Craik0776a602013-02-14 15:36:01 -080031#include <utils/RefBase.h>
32#include <utils/SortedVector.h>
33#include <utils/String8.h>
34#include <utils/Vector.h>
Romain Guye3b0a012013-06-26 15:45:41 -070035
Chris Craik0776a602013-02-14 15:36:01 -080036#include <cutils/compiler.h>
37
Romain Guye3b0a012013-06-26 15:45:41 -070038#include <androidfw/ResourceTypes.h>
39
Chris Craik0776a602013-02-14 15:36:01 -080040#include "Debug.h"
Chris Craikf57776b2013-10-25 18:30:17 -070041#include "Matrix.h"
42#include "DeferredDisplayList.h"
John Reckacb6f072014-03-12 16:11:23 -070043#include "RenderProperties.h"
Chris Craik0776a602013-02-14 15:36:01 -080044
45class SkBitmap;
46class SkPaint;
47class SkPath;
48class SkRegion;
49
50namespace android {
51namespace uirenderer {
52
Chris Craikc3566d02013-02-04 16:16:33 -080053class DeferredDisplayList;
Chris Craik0776a602013-02-14 15:36:01 -080054class DisplayListOp;
55class DisplayListRenderer;
56class OpenGLRenderer;
57class Rect;
58class Layer;
Chris Craik0776a602013-02-14 15:36:01 -080059
Chris Craikff785832013-03-08 13:12:16 -080060class ClipRectOp;
61class SaveLayerOp;
62class SaveOp;
63class RestoreToCountOp;
Chris Craika7090e02014-06-20 16:01:00 -070064class DrawRenderNodeOp;
Chris Craikff785832013-03-08 13:12:16 -080065
Chris Craikf57776b2013-10-25 18:30:17 -070066/**
67 * Holds data used in the playback a tree of DisplayLists.
68 */
69class PlaybackStateStruct {
70protected:
71 PlaybackStateStruct(OpenGLRenderer& renderer, int replayFlags, LinearAllocator* allocator)
Chris Craik3783e702014-01-27 14:26:14 -080072 : mRenderer(renderer), mReplayFlags(replayFlags), mAllocator(allocator){}
Chris Craikf57776b2013-10-25 18:30:17 -070073
74public:
Chris Craikff785832013-03-08 13:12:16 -080075 OpenGLRenderer& mRenderer;
76 const int mReplayFlags;
Chris Craikf57776b2013-10-25 18:30:17 -070077
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;
Chris Craikff785832013-03-08 13:12:16 -080081};
82
Chris Craikf57776b2013-10-25 18:30:17 -070083class DeferStateStruct : public PlaybackStateStruct {
84public:
85 DeferStateStruct(DeferredDisplayList& deferredList, OpenGLRenderer& renderer, int replayFlags)
Chris Craik9f68c092014-01-10 10:30:57 -080086 : PlaybackStateStruct(renderer, replayFlags, &(deferredList.mAllocator)),
87 mDeferredList(deferredList) {}
Chris Craikf57776b2013-10-25 18:30:17 -070088
89 DeferredDisplayList& mDeferredList;
90};
91
92class ReplayStateStruct : public PlaybackStateStruct {
93public:
Chris Craikff785832013-03-08 13:12:16 -080094 ReplayStateStruct(OpenGLRenderer& renderer, Rect& dirty, int replayFlags)
Chris Craikf57776b2013-10-25 18:30:17 -070095 : PlaybackStateStruct(renderer, replayFlags, &mReplayAllocator),
96 mDirty(dirty), mDrawGlStatus(DrawGlInfo::kStatusDone) {}
97
Chris Craikff785832013-03-08 13:12:16 -080098 Rect& mDirty;
Chris Craikff785832013-03-08 13:12:16 -080099 status_t mDrawGlStatus;
Chris Craikf57776b2013-10-25 18:30:17 -0700100 LinearAllocator mReplayAllocator;
Chris Craikff785832013-03-08 13:12:16 -0800101};
102
Chris Craik0776a602013-02-14 15:36:01 -0800103/**
John Reck44fd8d22014-02-26 11:00:11 -0800104 * Data structure that holds the list of commands used in display list stream
Chris Craik0776a602013-02-14 15:36:01 -0800105 */
John Reck44fd8d22014-02-26 11:00:11 -0800106class DisplayListData {
Chris Craik0776a602013-02-14 15:36:01 -0800107public:
John Reck087bc0c2014-04-04 16:20:08 -0700108 DisplayListData();
109 ~DisplayListData();
John Reck44fd8d22014-02-26 11:00:11 -0800110
Chris Craikf57776b2013-10-25 18:30:17 -0700111 // allocator into which all ops were allocated
Chris Craik0776a602013-02-14 15:36:01 -0800112 LinearAllocator allocator;
Chris Craikf57776b2013-10-25 18:30:17 -0700113
114 // pointers to all ops within display list, pointing into allocator data
Chris Craik0776a602013-02-14 15:36:01 -0800115 Vector<DisplayListOp*> displayListOps;
Chris Craikf57776b2013-10-25 18:30:17 -0700116
Chris Craikf533e942014-01-14 22:35:37 -0800117 // index of DisplayListOp restore, after which projected descendents should be drawn
Chris Craik1df26442014-02-05 16:50:41 -0800118 int projectionReceiveIndex;
John Reck44fd8d22014-02-26 11:00:11 -0800119
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;
John Reck44fd8d22014-02-26 11:00:11 -0800128 Vector<Layer*> layers;
John Reck09d5cdd2014-07-24 10:36:08 -0700129 Vector<Functor*> functors;
John Reck44fd8d22014-02-26 11:00:11 -0800130 bool hasDrawOps;
131
132 bool isEmpty() {
133 return !displayListOps.size();
134 }
135
Chris Craika7090e02014-06-20 16:01:00 -0700136 void addChild(DrawRenderNodeOp* childOp);
137 const Vector<DrawRenderNodeOp*>& children() { return mChildren; }
John Reck087bc0c2014-04-04 16:20:08 -0700138
John Reck52244ff2014-05-01 21:27:37 -0700139 void refProperty(CanvasPropertyPrimitive* prop) {
140 mReferenceHolders.push(prop);
141 }
142
143 void refProperty(CanvasPropertyPaint* prop) {
144 mReferenceHolders.push(prop);
145 }
146
John Reck44fd8d22014-02-26 11:00:11 -0800147private:
John Reck087bc0c2014-04-04 16:20:08 -0700148 Vector< sp<VirtualLightRefBase> > mReferenceHolders;
149
150 // list of children display lists for quick, non-drawing traversal
Chris Craika7090e02014-06-20 16:01:00 -0700151 Vector<DrawRenderNodeOp*> mChildren;
John Reck087bc0c2014-04-04 16:20:08 -0700152
John Reck44fd8d22014-02-26 11:00:11 -0800153 void cleanupResources();
Chris Craik0776a602013-02-14 15:36:01 -0800154};
155
Chris Craik0776a602013-02-14 15:36:01 -0800156}; // namespace uirenderer
157}; // namespace android
158
159#endif // ANDROID_HWUI_OPENGL_RENDERER_H