blob: 624db2ce67bec7d9f6ff8c35c50f3e22c3b03e4e [file] [log] [blame]
John Reck04fc5832014-02-05 16:38:25 -08001/*
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:
John Recka39dd592014-02-14 16:59:37 -080037 // Note that DeferredLayerUpdater assumes it is taking ownership of the layer
38 // and will not call incrementRef on it as a result.
John Reck04fc5832014-02-05 16:38:25 -080039 ANDROID_API DeferredLayerUpdater(Layer* layer, OpenGLRenderer* renderer = 0);
40 ANDROID_API ~DeferredLayerUpdater();
41
42 ANDROID_API bool setSize(uint32_t width, uint32_t height) {
43 if (mWidth != width || mHeight != height) {
44 mWidth = width;
45 mHeight = height;
46 return true;
47 }
48 return false;
49 }
50
51 ANDROID_API bool setBlend(bool blend) {
52 if (blend != mBlend) {
53 mBlend = blend;
54 return true;
55 }
56 return false;
57 }
58
59 ANDROID_API void setSurfaceTexture(const sp<GLConsumer>& texture, bool needsAttach) {
60 if (texture.get() != mSurfaceTexture.get()) {
61 mNeedsGLContextAttach = needsAttach;
62 mSurfaceTexture = texture;
63 }
64 }
65
66 ANDROID_API void updateTexImage() {
67 mUpdateTexImage = true;
68 }
69
70 ANDROID_API void setTransform(const SkMatrix* matrix) {
71 delete mTransform;
72 mTransform = matrix ? new SkMatrix(*matrix) : 0;
73 }
74
75 ANDROID_API void setDisplayList(DisplayList* displayList,
76 int left, int top, int right, int bottom);
77
Derek Sollenberger90d0c752014-02-12 18:59:05 +000078 ANDROID_API void setPaint(const SkPaint* paint) {
79 OpenGLRenderer::getAlphaAndModeDirect(paint, &mAlpha, &mMode);
80 }
81
82 ANDROID_API void setColorFilter(SkColorFilter* colorFilter);
John Reck04fc5832014-02-05 16:38:25 -080083
84 ANDROID_API bool apply();
John Reck04fc5832014-02-05 16:38:25 -080085
86 ANDROID_API Layer* backingLayer() {
87 return mLayer;
88 }
89
90 ANDROID_API Layer* detachBackingLayer() {
91 Layer* layer = mLayer;
92 mLayer = 0;
93 return layer;
94 }
95
96private:
97 // Generic properties
98 uint32_t mWidth;
99 uint32_t mHeight;
100 bool mBlend;
101 SkColorFilter* mColorFilter;
102 int mAlpha;
103 SkXfermode::Mode mMode;
104
105 // Layer type specific properties
106 // displayList and surfaceTexture are mutually exclusive, only 1 may be set
107 // dirtyRect is only valid if displayList is set
108 DisplayList* mDisplayList;
109 Rect mDirtyRect;
110 sp<GLConsumer> mSurfaceTexture;
111 SkMatrix* mTransform;
112 bool mNeedsGLContextAttach;
113 bool mUpdateTexImage;
114
115 Layer* mLayer;
116 OpenGLRenderer* mRenderer;
117 Caches& mCaches;
118
119 void doUpdateTexImage();
120};
121
122} /* namespace uirenderer */
123} /* namespace android */
124
125#endif /* DEFERREDLAYERUPDATE_H_ */