blob: ead83144f4d41a6a04dad87620acbb2c2d883d81 [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
Greg Daniel8cd3edf2017-01-09 14:15:41 -050025#include <GLES2/gl2.h>
26#include <GLES2/gl2ext.h>
27
John Reck04fc5832014-02-05 16:38:25 -080028#include "Layer.h"
John Reck04fc5832014-02-05 16:38:25 -080029#include "Rect.h"
John Reck749906b2014-10-03 15:02:19 -070030#include "renderthread/RenderThread.h"
John Reck04fc5832014-02-05 16:38:25 -080031
32namespace android {
33namespace uirenderer {
34
35// Container to hold the properties a layer should be set to at the start
36// of a render pass
John Reckd72e0a32014-05-29 18:56:11 -070037class DeferredLayerUpdater : public VirtualLightRefBase {
John Reck04fc5832014-02-05 16:38:25 -080038public:
John Recka39dd592014-02-14 16:59:37 -080039 // Note that DeferredLayerUpdater assumes it is taking ownership of the layer
40 // and will not call incrementRef on it as a result.
Chih-Hung Hsieha619ec72016-08-29 14:52:43 -070041 ANDROID_API explicit DeferredLayerUpdater(Layer* layer);
John Reck04fc5832014-02-05 16:38:25 -080042 ANDROID_API ~DeferredLayerUpdater();
43
Dan Stozaa41f29c2014-11-12 12:35:42 -080044 ANDROID_API bool setSize(int width, int height) {
John Reck04fc5832014-02-05 16:38:25 -080045 if (mWidth != width || mHeight != height) {
46 mWidth = width;
47 mHeight = height;
48 return true;
49 }
50 return false;
51 }
52
John Reck417ed6d2016-03-22 16:01:08 -070053 int getWidth() { return mWidth; }
54 int getHeight() { return mHeight; }
55
John Reck04fc5832014-02-05 16:38:25 -080056 ANDROID_API bool setBlend(bool blend) {
57 if (blend != mBlend) {
58 mBlend = blend;
59 return true;
60 }
61 return false;
62 }
63
64 ANDROID_API void setSurfaceTexture(const sp<GLConsumer>& texture, bool needsAttach) {
65 if (texture.get() != mSurfaceTexture.get()) {
Greg Daniel8cd3edf2017-01-09 14:15:41 -050066 mNeedsGLContextAttach = needsAttach;
Greg Daniel45ec62b2017-01-04 14:27:00 -050067 mSurfaceTexture = texture;
Chris Craik48f650c2015-03-10 11:03:39 -070068
69 GLenum target = texture->getCurrentTextureTarget();
70 LOG_ALWAYS_FATAL_IF(target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES,
71 "set unsupported GLConsumer with target %x", target);
John Reck04fc5832014-02-05 16:38:25 -080072 }
73 }
74
75 ANDROID_API void updateTexImage() {
76 mUpdateTexImage = true;
77 }
78
79 ANDROID_API void setTransform(const SkMatrix* matrix) {
80 delete mTransform;
Chris Craikd41c4d82015-01-05 15:51:13 -080081 mTransform = matrix ? new SkMatrix(*matrix) : nullptr;
John Reck04fc5832014-02-05 16:38:25 -080082 }
83
John Reck417ed6d2016-03-22 16:01:08 -070084 SkMatrix* getTransform() {
85 return mTransform;
86 }
87
Derek Sollenberger674554f2014-02-19 16:47:32 +000088 ANDROID_API void setPaint(const SkPaint* paint);
John Reck04fc5832014-02-05 16:38:25 -080089
Chris Craikd2dfd8f2015-12-16 14:27:20 -080090 void apply();
John Reck04fc5832014-02-05 16:38:25 -080091
John Reck12f5e342014-11-07 07:53:43 -080092 Layer* backingLayer() {
John Reck04fc5832014-02-05 16:38:25 -080093 return mLayer;
94 }
95
Chris Craikd2dfd8f2015-12-16 14:27:20 -080096 void detachSurfaceTexture();
John Reck918ad522014-06-27 14:45:25 -070097
Derek Sollenberger56ad6ec2016-07-22 12:13:32 -040098 void updateLayer(bool forceFilter, GLenum renderTarget, const float* textureTransform);
99
John Reck04fc5832014-02-05 16:38:25 -0800100private:
101 // Generic properties
Dan Stozaa41f29c2014-11-12 12:35:42 -0800102 int mWidth;
103 int mHeight;
John Reck04fc5832014-02-05 16:38:25 -0800104 bool mBlend;
105 SkColorFilter* mColorFilter;
106 int mAlpha;
Mike Reed260ab722016-10-07 15:59:20 -0400107 SkBlendMode mMode;
John Reck04fc5832014-02-05 16:38:25 -0800108 sp<GLConsumer> mSurfaceTexture;
109 SkMatrix* mTransform;
110 bool mNeedsGLContextAttach;
111 bool mUpdateTexImage;
112
113 Layer* mLayer;
John Reckd72e0a32014-05-29 18:56:11 -0700114
John Reck04fc5832014-02-05 16:38:25 -0800115 void doUpdateTexImage();
Greg Daniel45ec62b2017-01-04 14:27:00 -0500116 void doUpdateVkTexImage();
117 void updateLayer(bool forceFilter, const float* textureTransform);
John Reck04fc5832014-02-05 16:38:25 -0800118};
119
120} /* namespace uirenderer */
121} /* namespace android */