blob: 2376295b7effcfcd50a809d2a5edcee6820fd383 [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 */
Chris Craik5e00c7c2016-07-06 16:10:09 -070016
17#pragma once
John Reck04fc5832014-02-05 16:38:25 -080018
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 Reckc36df952015-07-29 10:09:36 -070038 ANDROID_API DeferredLayerUpdater(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
John Reck417ed6d2016-03-22 16:01:08 -070050 int getWidth() { return mWidth; }
51 int getHeight() { return mHeight; }
52
John Reck04fc5832014-02-05 16:38:25 -080053 ANDROID_API bool setBlend(bool blend) {
54 if (blend != mBlend) {
55 mBlend = blend;
56 return true;
57 }
58 return false;
59 }
60
61 ANDROID_API void setSurfaceTexture(const sp<GLConsumer>& texture, bool needsAttach) {
62 if (texture.get() != mSurfaceTexture.get()) {
63 mNeedsGLContextAttach = needsAttach;
64 mSurfaceTexture = texture;
Chris Craik48f650c2015-03-10 11:03:39 -070065
66 GLenum target = texture->getCurrentTextureTarget();
67 LOG_ALWAYS_FATAL_IF(target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES,
68 "set unsupported GLConsumer with target %x", target);
John Reck04fc5832014-02-05 16:38:25 -080069 }
70 }
71
72 ANDROID_API void updateTexImage() {
73 mUpdateTexImage = true;
74 }
75
76 ANDROID_API void setTransform(const SkMatrix* matrix) {
77 delete mTransform;
Chris Craikd41c4d82015-01-05 15:51:13 -080078 mTransform = matrix ? new SkMatrix(*matrix) : nullptr;
John Reck04fc5832014-02-05 16:38:25 -080079 }
80
John Reck417ed6d2016-03-22 16:01:08 -070081 SkMatrix* getTransform() {
82 return mTransform;
83 }
84
Derek Sollenberger674554f2014-02-19 16:47:32 +000085 ANDROID_API void setPaint(const SkPaint* paint);
John Reck04fc5832014-02-05 16:38:25 -080086
Chris Craikd2dfd8f2015-12-16 14:27:20 -080087 void apply();
John Reck04fc5832014-02-05 16:38:25 -080088
John Reck12f5e342014-11-07 07:53:43 -080089 Layer* backingLayer() {
John Reck04fc5832014-02-05 16:38:25 -080090 return mLayer;
91 }
92
Chris Craikd2dfd8f2015-12-16 14:27:20 -080093 void detachSurfaceTexture();
John Reck918ad522014-06-27 14:45:25 -070094
Derek Sollenberger56ad6ec2016-07-22 12:13:32 -040095 void updateLayer(bool forceFilter, GLenum renderTarget, const float* textureTransform);
96
John Reck04fc5832014-02-05 16:38:25 -080097private:
98 // Generic properties
Dan Stozaa41f29c2014-11-12 12:35:42 -080099 int mWidth;
100 int mHeight;
John Reck04fc5832014-02-05 16:38:25 -0800101 bool mBlend;
102 SkColorFilter* mColorFilter;
103 int mAlpha;
104 SkXfermode::Mode mMode;
John Reck04fc5832014-02-05 16:38:25 -0800105 sp<GLConsumer> mSurfaceTexture;
106 SkMatrix* mTransform;
107 bool mNeedsGLContextAttach;
108 bool mUpdateTexImage;
109
110 Layer* mLayer;
John Reckd72e0a32014-05-29 18:56:11 -0700111
John Reck04fc5832014-02-05 16:38:25 -0800112 void doUpdateTexImage();
113};
114
115} /* namespace uirenderer */
116} /* namespace android */