blob: 67173615d411cc6e8b144e4071a4f6e8c17838ea [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
sergeyv00eb43d2017-02-13 14:34:15 -080071 ANDROID_API void setSurfaceTexture(const sp<GLConsumer>& texture) {
John Reck04fc5832014-02-05 16:38:25 -080072 if (texture.get() != mSurfaceTexture.get()) {
Greg Daniel45ec62b2017-01-04 14:27:00 -050073 mSurfaceTexture = texture;
Chris Craik48f650c2015-03-10 11:03:39 -070074
75 GLenum target = texture->getCurrentTextureTarget();
76 LOG_ALWAYS_FATAL_IF(target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES,
77 "set unsupported GLConsumer with target %x", target);
John Reck04fc5832014-02-05 16:38:25 -080078 }
79 }
80
81 ANDROID_API void updateTexImage() {
82 mUpdateTexImage = true;
83 }
84
85 ANDROID_API void setTransform(const SkMatrix* matrix) {
86 delete mTransform;
Chris Craikd41c4d82015-01-05 15:51:13 -080087 mTransform = matrix ? new SkMatrix(*matrix) : nullptr;
John Reck04fc5832014-02-05 16:38:25 -080088 }
89
John Reck417ed6d2016-03-22 16:01:08 -070090 SkMatrix* getTransform() {
91 return mTransform;
92 }
93
Derek Sollenberger674554f2014-02-19 16:47:32 +000094 ANDROID_API void setPaint(const SkPaint* paint);
John Reck04fc5832014-02-05 16:38:25 -080095
Chris Craikd2dfd8f2015-12-16 14:27:20 -080096 void apply();
John Reck04fc5832014-02-05 16:38:25 -080097
John Reck12f5e342014-11-07 07:53:43 -080098 Layer* backingLayer() {
John Reck04fc5832014-02-05 16:38:25 -080099 return mLayer;
100 }
101
Chris Craikd2dfd8f2015-12-16 14:27:20 -0800102 void detachSurfaceTexture();
John Reck918ad522014-06-27 14:45:25 -0700103
Derek Sollenberger56ad6ec2016-07-22 12:13:32 -0400104 void updateLayer(bool forceFilter, GLenum renderTarget, const float* textureTransform);
105
sergeyv3e9999b2017-01-19 15:37:02 -0800106 void destroyLayer();
107
108 Layer::Api getBackingLayerApi() {
109 return mLayerApi;
110 }
111
John Reck04fc5832014-02-05 16:38:25 -0800112private:
sergeyv3e9999b2017-01-19 15:37:02 -0800113 RenderState& mRenderState;
114
John Reck04fc5832014-02-05 16:38:25 -0800115 // Generic properties
sergeyv3e9999b2017-01-19 15:37:02 -0800116 int mWidth = 0;
117 int mHeight = 0;
118 bool mBlend = false;
119 SkColorFilter* mColorFilter = nullptr;
120 int mAlpha = 255;
121 SkBlendMode mMode = SkBlendMode::kSrcOver;
John Reck04fc5832014-02-05 16:38:25 -0800122 sp<GLConsumer> mSurfaceTexture;
123 SkMatrix* mTransform;
sergeyv00eb43d2017-02-13 14:34:15 -0800124 bool mGLContextAttached;
John Reck04fc5832014-02-05 16:38:25 -0800125 bool mUpdateTexImage;
126
127 Layer* mLayer;
sergeyv3e9999b2017-01-19 15:37:02 -0800128 Layer::Api mLayerApi;
129 CreateLayerFn mCreateLayerFn;
John Reckd72e0a32014-05-29 18:56:11 -0700130
John Reck04fc5832014-02-05 16:38:25 -0800131 void doUpdateTexImage();
Greg Daniel45ec62b2017-01-04 14:27:00 -0500132 void doUpdateVkTexImage();
John Reck04fc5832014-02-05 16:38:25 -0800133};
134
135} /* namespace uirenderer */
136} /* namespace android */