blob: 61efafe46e61d5c14319ca83cc2bc9f4c814f9c8 [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 Reck749906b2014-10-03 15:02:19 -070027#include "renderthread/RenderThread.h"
John Reck04fc5832014-02-05 16:38:25 -080028
29namespace android {
30namespace uirenderer {
31
32// Container to hold the properties a layer should be set to at the start
33// of a render pass
John Reckd72e0a32014-05-29 18:56:11 -070034class DeferredLayerUpdater : public VirtualLightRefBase {
John Reck04fc5832014-02-05 16:38:25 -080035public:
John Recka39dd592014-02-14 16:59:37 -080036 // Note that DeferredLayerUpdater assumes it is taking ownership of the layer
37 // and will not call incrementRef on it as a result.
John Reck749906b2014-10-03 15:02:19 -070038 ANDROID_API DeferredLayerUpdater(renderthread::RenderThread& thread, Layer* layer);
John Reck04fc5832014-02-05 16:38:25 -080039 ANDROID_API ~DeferredLayerUpdater();
40
Dan Stozaa41f29c2014-11-12 12:35:42 -080041 ANDROID_API bool setSize(int width, int height) {
John Reck04fc5832014-02-05 16:38:25 -080042 if (mWidth != width || mHeight != height) {
43 mWidth = width;
44 mHeight = height;
45 return true;
46 }
47 return false;
48 }
49
50 ANDROID_API bool setBlend(bool blend) {
51 if (blend != mBlend) {
52 mBlend = blend;
53 return true;
54 }
55 return false;
56 }
57
58 ANDROID_API void setSurfaceTexture(const sp<GLConsumer>& texture, bool needsAttach) {
59 if (texture.get() != mSurfaceTexture.get()) {
60 mNeedsGLContextAttach = needsAttach;
61 mSurfaceTexture = texture;
62 }
63 }
64
65 ANDROID_API void updateTexImage() {
66 mUpdateTexImage = true;
67 }
68
69 ANDROID_API void setTransform(const SkMatrix* matrix) {
70 delete mTransform;
71 mTransform = matrix ? new SkMatrix(*matrix) : 0;
72 }
73
Derek Sollenberger674554f2014-02-19 16:47:32 +000074 ANDROID_API void setPaint(const SkPaint* paint);
John Reck04fc5832014-02-05 16:38:25 -080075
John Reck68bfe0a2014-06-24 15:34:58 -070076 ANDROID_API bool apply();
John Reck04fc5832014-02-05 16:38:25 -080077
John Reck12f5e342014-11-07 07:53:43 -080078 Layer* backingLayer() {
John Reck04fc5832014-02-05 16:38:25 -080079 return mLayer;
80 }
81
John Reck918ad522014-06-27 14:45:25 -070082 ANDROID_API void detachSurfaceTexture();
83
John Reck04fc5832014-02-05 16:38:25 -080084private:
85 // Generic properties
Dan Stozaa41f29c2014-11-12 12:35:42 -080086 int mWidth;
87 int mHeight;
John Reck04fc5832014-02-05 16:38:25 -080088 bool mBlend;
89 SkColorFilter* mColorFilter;
90 int mAlpha;
91 SkXfermode::Mode mMode;
92
John Reck04fc5832014-02-05 16:38:25 -080093 sp<GLConsumer> mSurfaceTexture;
94 SkMatrix* mTransform;
95 bool mNeedsGLContextAttach;
96 bool mUpdateTexImage;
97
98 Layer* mLayer;
John Reck04fc5832014-02-05 16:38:25 -080099 Caches& mCaches;
John Reck749906b2014-10-03 15:02:19 -0700100 renderthread::RenderThread& mRenderThread;
John Reckd72e0a32014-05-29 18:56:11 -0700101
John Reck04fc5832014-02-05 16:38:25 -0800102 void doUpdateTexImage();
103};
104
105} /* namespace uirenderer */
106} /* namespace android */
107
108#endif /* DEFERREDLAYERUPDATE_H_ */