blob: 9782c1c517946b759b8985d3827d642e8cac6994 [file] [log] [blame]
Chris Craikc3566d02013-02-04 16:16:33 -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_DEFERRED_DISPLAY_LIST_H
18#define ANDROID_HWUI_DEFERRED_DISPLAY_LIST_H
19
20#include <utils/Errors.h>
21#include <utils/Vector.h>
22
23#include "Matrix.h"
24#include "Rect.h"
Chris Craik527a3aa2013-03-04 10:19:31 -080025#include "utils/TinyHashMap.h"
26
27class SkBitmap;
Chris Craikc3566d02013-02-04 16:16:33 -080028
29namespace android {
30namespace uirenderer {
31
Chris Craikff785832013-03-08 13:12:16 -080032class ClipOp;
Chris Craikc3566d02013-02-04 16:16:33 -080033class DrawOp;
Chris Craikff785832013-03-08 13:12:16 -080034class SaveOp;
35class SaveLayerOp;
36class StateOp;
Chris Craikc3566d02013-02-04 16:16:33 -080037class OpenGLRenderer;
Chris Craikc3566d02013-02-04 16:16:33 -080038
Chris Craik527a3aa2013-03-04 10:19:31 -080039class Batch;
40class DrawBatch;
41class MergingDrawBatch;
42
43typedef void* mergeid_t;
44
Chris Craikc3566d02013-02-04 16:16:33 -080045class DeferredDisplayList {
46public:
47 DeferredDisplayList() { clear(); }
48 ~DeferredDisplayList() { clear(); }
49
50 enum OpBatchId {
Chris Craik527a3aa2013-03-04 10:19:31 -080051 kOpBatch_None = 0, // Don't batch
Chris Craikc3566d02013-02-04 16:16:33 -080052 kOpBatch_Bitmap,
53 kOpBatch_Patch,
54 kOpBatch_AlphaVertices,
55 kOpBatch_Vertices,
56 kOpBatch_AlphaMaskTexture,
57 kOpBatch_Text,
58 kOpBatch_ColorText,
59
60 kOpBatch_Count, // Add other batch ids before this
61 };
62
63 bool isEmpty() { return mBatches.isEmpty(); }
64
65 /**
66 * Plays back all of the draw ops recorded into batches to the renderer.
67 * Adjusts the state of the renderer as necessary, and restores it when complete
68 */
Chris Craikff785832013-03-08 13:12:16 -080069 status_t flush(OpenGLRenderer& renderer, Rect& dirty);
70
71 void addClip(OpenGLRenderer& renderer, ClipOp* op);
72 void addSaveLayer(OpenGLRenderer& renderer, SaveLayerOp* op, int newSaveCount);
73 void addSave(OpenGLRenderer& renderer, SaveOp* op, int newSaveCount);
Chris Craik7273daa2013-03-28 11:25:24 -070074 void addRestoreToCount(OpenGLRenderer& renderer, StateOp* op, int newSaveCount);
Chris Craikc3566d02013-02-04 16:16:33 -080075
76 /**
77 * Add a draw op into the DeferredDisplayList, reordering as needed (for performance) if
78 * disallowReorder is false, respecting draw order when overlaps occur
79 */
Chris Craikff785832013-03-08 13:12:16 -080080 void addDrawOp(OpenGLRenderer& renderer, DrawOp* op);
Chris Craikc3566d02013-02-04 16:16:33 -080081
82private:
Chris Craikd90144d2013-03-19 15:03:48 -070083 /**
Chris Craikff785832013-03-08 13:12:16 -080084 * Resets the batching back-pointers, creating a barrier in the operation stream so that no ops
85 * added in the future will be inserted into a batch that already exist.
86 */
87 void resetBatchingState();
88
Chris Craik1206b9b2013-04-04 14:46:24 -070089 void clear();
90
Chris Craikff785832013-03-08 13:12:16 -080091 void storeStateOpBarrier(OpenGLRenderer& renderer, StateOp* op);
Chris Craik7273daa2013-03-28 11:25:24 -070092 void storeRestoreToCountBarrier(OpenGLRenderer& renderer, StateOp* op, int newSaveCount);
Chris Craikff785832013-03-08 13:12:16 -080093
94 bool recordingComplexClip() const { return mComplexClipStackStart >= 0; }
95
96 int getStateOpDeferFlags() const;
97 int getDrawOpDeferFlags() const;
98
Chris Craikd90144d2013-03-19 15:03:48 -070099 /**
100 * At defer time, stores the *defer time* savecount of save/saveLayer ops that were deferred, so
101 * that when an associated restoreToCount is deferred, it can be recorded as a
102 * RestoreToCountBatch
Chris Craikff785832013-03-08 13:12:16 -0800103 */
104 Vector<int> mSaveStack;
105 int mComplexClipStackStart;
Chris Craikc3566d02013-02-04 16:16:33 -0800106
Chris Craik527a3aa2013-03-04 10:19:31 -0800107 Vector<Batch*> mBatches;
108
109 // Maps batch ids to the most recent *non-merging* batch of that id
110 Batch* mBatchLookup[kOpBatch_Count];
111
112 // Points to the index after the most recent barrier
113 int mEarliestBatchIndex;
114
115 /**
116 * Maps the mergeid_t returned by an op's getMergeId() to the most recently seen
117 * MergingDrawBatch of that id. These ids are unique per draw type and guaranteed to not
118 * collide, which avoids the need to resolve mergeid collisions.
119 */
120 TinyHashMap<mergeid_t, DrawBatch*> mMergingBatches[kOpBatch_Count];
Chris Craikc3566d02013-02-04 16:16:33 -0800121};
122
123}; // namespace uirenderer
124}; // namespace android
125
126#endif // ANDROID_HWUI_DEFERRED_DISPLAY_LIST_H