DeferredDisplayList.h revision 7273daace9303f4662444111c40bb83d3ead4a92
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_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"
25
26namespace android {
27namespace uirenderer {
28
29class ClipOp;
30class DrawOp;
31class SaveOp;
32class SaveLayerOp;
33class StateOp;
34class DrawOpBatch;
35class OpenGLRenderer;
36
37class DeferredDisplayList {
38public:
39    DeferredDisplayList() { clear(); }
40    ~DeferredDisplayList() { clear(); }
41
42    enum OpBatchId {
43        kOpBatch_None = -1, // Don't batch
44        kOpBatch_Bitmap,
45        kOpBatch_Patch,
46        kOpBatch_AlphaVertices,
47        kOpBatch_Vertices,
48        kOpBatch_AlphaMaskTexture,
49        kOpBatch_Text,
50        kOpBatch_ColorText,
51
52        kOpBatch_Count, // Add other batch ids before this
53    };
54
55    void clear();
56
57    bool isEmpty() { return mBatches.isEmpty(); }
58
59    /**
60     * Plays back all of the draw ops recorded into batches to the renderer.
61     * Adjusts the state of the renderer as necessary, and restores it when complete
62     */
63    status_t flush(OpenGLRenderer& renderer, Rect& dirty);
64
65    void addClip(OpenGLRenderer& renderer, ClipOp* op);
66    void addSaveLayer(OpenGLRenderer& renderer, SaveLayerOp* op, int newSaveCount);
67    void addSave(OpenGLRenderer& renderer, SaveOp* op, int newSaveCount);
68    void addRestoreToCount(OpenGLRenderer& renderer, StateOp* op, int newSaveCount);
69
70    /**
71     * Add a draw op into the DeferredDisplayList, reordering as needed (for performance) if
72     * disallowReorder is false, respecting draw order when overlaps occur
73     */
74    void addDrawOp(OpenGLRenderer& renderer, DrawOp* op);
75
76private:
77    /**
78     * Resets the batching back-pointers, creating a barrier in the operation stream so that no ops
79     * added in the future will be inserted into a batch that already exist.
80     */
81    void resetBatchingState();
82
83    void storeStateOpBarrier(OpenGLRenderer& renderer, StateOp* op);
84    void storeRestoreToCountBarrier(OpenGLRenderer& renderer, StateOp* op, int newSaveCount);
85
86    bool recordingComplexClip() const { return mComplexClipStackStart >= 0; }
87
88    int getStateOpDeferFlags() const;
89    int getDrawOpDeferFlags() const;
90
91    /**
92     * At defer time, stores the *defer time* savecount of save/saveLayer ops that were deferred, so
93     * that when an associated restoreToCount is deferred, it can be recorded as a
94     * RestoreToCountBatch
95     */
96    Vector<int> mSaveStack;
97    int mComplexClipStackStart;
98
99    Vector<DrawOpBatch*> mBatches;
100    int mBatchIndices[kOpBatch_Count];
101};
102
103}; // namespace uirenderer
104}; // namespace android
105
106#endif // ANDROID_HWUI_DEFERRED_DISPLAY_LIST_H
107