blob: 84411edbebfc9e130fe9f1bfccc1aefbb5335270 [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
John Reck04fc5832014-02-05 16:38:25 -080025#include "Layer.h"
John Reck04fc5832014-02-05 16:38:25 -080026#include "Rect.h"
John Reck113e0822014-03-18 09:22:59 -070027#include "RenderNode.h"
John Reck749906b2014-10-03 15:02:19 -070028#include "renderthread/RenderThread.h"
John Reck04fc5832014-02-05 16:38:25 -080029
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
John Reckd72e0a32014-05-29 18:56:11 -070035class DeferredLayerUpdater : public VirtualLightRefBase {
John Reck04fc5832014-02-05 16:38:25 -080036public:
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 Reck749906b2014-10-03 15:02:19 -070039 ANDROID_API DeferredLayerUpdater(renderthread::RenderThread& thread, Layer* layer);
John Reck04fc5832014-02-05 16:38:25 -080040 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
Derek Sollenberger674554f2014-02-19 16:47:32 +000075 ANDROID_API void setPaint(const SkPaint* paint);
John Reck04fc5832014-02-05 16:38:25 -080076
John Reck68bfe0a2014-06-24 15:34:58 -070077 ANDROID_API bool apply();
John Reck04fc5832014-02-05 16:38:25 -080078
John Reck12f5e342014-11-07 07:53:43 -080079 Layer* backingLayer() {
John Reck04fc5832014-02-05 16:38:25 -080080 return mLayer;
81 }
82
John Reck918ad522014-06-27 14:45:25 -070083 ANDROID_API void detachSurfaceTexture();
84
John Reck04fc5832014-02-05 16:38:25 -080085private:
86 // Generic properties
87 uint32_t mWidth;
88 uint32_t mHeight;
89 bool mBlend;
90 SkColorFilter* mColorFilter;
91 int mAlpha;
92 SkXfermode::Mode mMode;
93
John Reck04fc5832014-02-05 16:38:25 -080094 sp<GLConsumer> mSurfaceTexture;
95 SkMatrix* mTransform;
96 bool mNeedsGLContextAttach;
97 bool mUpdateTexImage;
98
99 Layer* mLayer;
John Reck04fc5832014-02-05 16:38:25 -0800100 Caches& mCaches;
John Reck749906b2014-10-03 15:02:19 -0700101 renderthread::RenderThread& mRenderThread;
John Reckd72e0a32014-05-29 18:56:11 -0700102
John Reck04fc5832014-02-05 16:38:25 -0800103 void doUpdateTexImage();
104};
105
106} /* namespace uirenderer */
107} /* namespace android */
108
109#endif /* DEFERREDLAYERUPDATE_H_ */