blob: 064b724c5e5f10ec37db2fd83f4a428ce171a77f [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
sergeyv3e9999b2017-01-19 15:37:02 -080035class RenderState;
36
John Reck04fc5832014-02-05 16:38:25 -080037// Container to hold the properties a layer should be set to at the start
38// of a render pass
John Reckd72e0a32014-05-29 18:56:11 -070039class DeferredLayerUpdater : public VirtualLightRefBase {
John Reck04fc5832014-02-05 16:38:25 -080040public:
John Recka39dd592014-02-14 16:59:37 -080041 // Note that DeferredLayerUpdater assumes it is taking ownership of the layer
42 // and will not call incrementRef on it as a result.
sergeyv3e9999b2017-01-19 15:37:02 -080043 typedef std::function<Layer*(RenderState& renderState, uint32_t layerWidth,
44 uint32_t layerHeight, SkColorFilter* colorFilter, int alpha,
45 SkBlendMode mode, bool blend)> CreateLayerFn;
46 ANDROID_API explicit DeferredLayerUpdater(RenderState& renderState,
47 CreateLayerFn createLayerFn, Layer::Api layerApi);
48
John Reck04fc5832014-02-05 16:38:25 -080049 ANDROID_API ~DeferredLayerUpdater();
50
Dan Stozaa41f29c2014-11-12 12:35:42 -080051 ANDROID_API bool setSize(int width, int height) {
John Reck04fc5832014-02-05 16:38:25 -080052 if (mWidth != width || mHeight != height) {
53 mWidth = width;
54 mHeight = height;
55 return true;
56 }
57 return false;
58 }
59
John Reck417ed6d2016-03-22 16:01:08 -070060 int getWidth() { return mWidth; }
61 int getHeight() { return mHeight; }
62
John Reck04fc5832014-02-05 16:38:25 -080063 ANDROID_API bool setBlend(bool blend) {
64 if (blend != mBlend) {
65 mBlend = blend;
66 return true;
67 }
68 return false;
69 }
70
71 ANDROID_API void setSurfaceTexture(const sp<GLConsumer>& texture, bool needsAttach) {
72 if (texture.get() != mSurfaceTexture.get()) {
Greg Daniel8cd3edf2017-01-09 14:15:41 -050073 mNeedsGLContextAttach = needsAttach;
Greg Daniel45ec62b2017-01-04 14:27:00 -050074 mSurfaceTexture = texture;
Chris Craik48f650c2015-03-10 11:03:39 -070075
76 GLenum target = texture->getCurrentTextureTarget();
77 LOG_ALWAYS_FATAL_IF(target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES,
78 "set unsupported GLConsumer with target %x", target);
John Reck04fc5832014-02-05 16:38:25 -080079 }
80 }
81
82 ANDROID_API void updateTexImage() {
83 mUpdateTexImage = true;
84 }
85
86 ANDROID_API void setTransform(const SkMatrix* matrix) {
87 delete mTransform;
Chris Craikd41c4d82015-01-05 15:51:13 -080088 mTransform = matrix ? new SkMatrix(*matrix) : nullptr;
John Reck04fc5832014-02-05 16:38:25 -080089 }
90
John Reck417ed6d2016-03-22 16:01:08 -070091 SkMatrix* getTransform() {
92 return mTransform;
93 }
94
Derek Sollenberger674554f2014-02-19 16:47:32 +000095 ANDROID_API void setPaint(const SkPaint* paint);
John Reck04fc5832014-02-05 16:38:25 -080096
Chris Craikd2dfd8f2015-12-16 14:27:20 -080097 void apply();
John Reck04fc5832014-02-05 16:38:25 -080098
John Reck12f5e342014-11-07 07:53:43 -080099 Layer* backingLayer() {
John Reck04fc5832014-02-05 16:38:25 -0800100 return mLayer;
101 }
102
Chris Craikd2dfd8f2015-12-16 14:27:20 -0800103 void detachSurfaceTexture();
John Reck918ad522014-06-27 14:45:25 -0700104
Derek Sollenberger56ad6ec2016-07-22 12:13:32 -0400105 void updateLayer(bool forceFilter, GLenum renderTarget, const float* textureTransform);
106
sergeyv3e9999b2017-01-19 15:37:02 -0800107 void destroyLayer();
108
109 Layer::Api getBackingLayerApi() {
110 return mLayerApi;
111 }
112
John Reck04fc5832014-02-05 16:38:25 -0800113private:
sergeyv3e9999b2017-01-19 15:37:02 -0800114 RenderState& mRenderState;
115
John Reck04fc5832014-02-05 16:38:25 -0800116 // Generic properties
sergeyv3e9999b2017-01-19 15:37:02 -0800117 int mWidth = 0;
118 int mHeight = 0;
119 bool mBlend = false;
120 SkColorFilter* mColorFilter = nullptr;
121 int mAlpha = 255;
122 SkBlendMode mMode = SkBlendMode::kSrcOver;
John Reck04fc5832014-02-05 16:38:25 -0800123 sp<GLConsumer> mSurfaceTexture;
124 SkMatrix* mTransform;
125 bool mNeedsGLContextAttach;
126 bool mUpdateTexImage;
127
128 Layer* mLayer;
sergeyv3e9999b2017-01-19 15:37:02 -0800129 Layer::Api mLayerApi;
130 CreateLayerFn mCreateLayerFn;
John Reckd72e0a32014-05-29 18:56:11 -0700131
John Reck04fc5832014-02-05 16:38:25 -0800132 void doUpdateTexImage();
Greg Daniel45ec62b2017-01-04 14:27:00 -0500133 void doUpdateVkTexImage();
John Reck04fc5832014-02-05 16:38:25 -0800134};
135
136} /* namespace uirenderer */
137} /* namespace android */