DeferredLayerUpdater.h revision 90d0c75e94a32fb7d993fae69762820aabc2fcbb
1/*
2 * Copyright (C) 2014 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#ifndef DEFERREDLAYERUPDATE_H_
17#define DEFERREDLAYERUPDATE_H_
18
19#include <cutils/compiler.h>
20#include <gui/GLConsumer.h>
21#include <SkColorFilter.h>
22#include <SkMatrix.h>
23#include <utils/StrongPointer.h>
24
25#include "DisplayList.h"
26#include "Layer.h"
27#include "OpenGLRenderer.h"
28#include "Rect.h"
29
30namespace android {
31namespace uirenderer {
32
33// Container to hold the properties a layer should be set to at the start
34// of a render pass
35class DeferredLayerUpdater {
36public:
37    ANDROID_API DeferredLayerUpdater(Layer* layer, OpenGLRenderer* renderer = 0);
38    ANDROID_API ~DeferredLayerUpdater();
39
40    ANDROID_API bool setSize(uint32_t width, uint32_t height) {
41        if (mWidth != width || mHeight != height) {
42            mWidth = width;
43            mHeight = height;
44            return true;
45        }
46        return false;
47    }
48
49    ANDROID_API bool setBlend(bool blend) {
50        if (blend != mBlend) {
51            mBlend = blend;
52            return true;
53        }
54        return false;
55    }
56
57    ANDROID_API void setSurfaceTexture(const sp<GLConsumer>& texture, bool needsAttach) {
58        if (texture.get() != mSurfaceTexture.get()) {
59            mNeedsGLContextAttach = needsAttach;
60            mSurfaceTexture = texture;
61        }
62    }
63
64    ANDROID_API void updateTexImage() {
65        mUpdateTexImage = true;
66    }
67
68    ANDROID_API void setTransform(const SkMatrix* matrix) {
69        delete mTransform;
70        mTransform = matrix ? new SkMatrix(*matrix) : 0;
71    }
72
73    ANDROID_API void setDisplayList(DisplayList* displayList,
74                int left, int top, int right, int bottom);
75
76    ANDROID_API void setPaint(const SkPaint* paint) {
77        OpenGLRenderer::getAlphaAndModeDirect(paint, &mAlpha, &mMode);
78    }
79
80    ANDROID_API void setColorFilter(SkColorFilter* colorFilter);
81
82    ANDROID_API bool apply();
83    ANDROID_API void applyDeferred(DeferredLayerUpdater* deferredApply);
84
85    ANDROID_API Layer* backingLayer() {
86        return mLayer;
87    }
88
89    ANDROID_API Layer* detachBackingLayer() {
90        Layer* layer = mLayer;
91        mLayer = 0;
92        return layer;
93    }
94
95private:
96    // Generic properties
97    uint32_t mWidth;
98    uint32_t mHeight;
99    bool mBlend;
100    SkColorFilter* mColorFilter;
101    int mAlpha;
102    SkXfermode::Mode mMode;
103
104    // Layer type specific properties
105    // displayList and surfaceTexture are mutually exclusive, only 1 may be set
106    // dirtyRect is only valid if displayList is set
107    DisplayList* mDisplayList;
108    Rect mDirtyRect;
109    sp<GLConsumer> mSurfaceTexture;
110    SkMatrix* mTransform;
111    bool mNeedsGLContextAttach;
112    bool mUpdateTexImage;
113
114    Layer* mLayer;
115    OpenGLRenderer* mRenderer;
116    Caches& mCaches;
117
118    void doUpdateTexImage();
119};
120
121} /* namespace uirenderer */
122} /* namespace android */
123
124#endif /* DEFERREDLAYERUPDATE_H_ */
125