blob: 9dc029fd38525db3ac90269074f11a1735b5df52 [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
John Reck04fc5832014-02-05 16:38:25 -080019#include <SkColorFilter.h>
20#include <SkMatrix.h>
John Reck1bcacfd2017-11-03 10:12:19 -070021#include <cutils/compiler.h>
22#include <gui/GLConsumer.h>
John Reck04fc5832014-02-05 16:38:25 -080023#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,
John Reck1bcacfd2017-11-03 10:12:19 -070044 uint32_t layerHeight, SkColorFilter* colorFilter, int alpha,
45 SkBlendMode mode, bool blend)>
46 CreateLayerFn;
47 ANDROID_API explicit DeferredLayerUpdater(RenderState& renderState, CreateLayerFn createLayerFn,
48 Layer::Api layerApi);
sergeyv3e9999b2017-01-19 15:37:02 -080049
John Reck04fc5832014-02-05 16:38:25 -080050 ANDROID_API ~DeferredLayerUpdater();
51
Dan Stozaa41f29c2014-11-12 12:35:42 -080052 ANDROID_API bool setSize(int width, int height) {
John Reck04fc5832014-02-05 16:38:25 -080053 if (mWidth != width || mHeight != height) {
54 mWidth = width;
55 mHeight = height;
56 return true;
57 }
58 return false;
59 }
60
John Reck417ed6d2016-03-22 16:01:08 -070061 int getWidth() { return mWidth; }
62 int getHeight() { return mHeight; }
63
John Reck04fc5832014-02-05 16:38:25 -080064 ANDROID_API bool setBlend(bool blend) {
65 if (blend != mBlend) {
66 mBlend = blend;
67 return true;
68 }
69 return false;
70 }
71
sergeyv00eb43d2017-02-13 14:34:15 -080072 ANDROID_API void setSurfaceTexture(const sp<GLConsumer>& texture) {
John Reck04fc5832014-02-05 16:38:25 -080073 if (texture.get() != mSurfaceTexture.get()) {
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,
John Reck1bcacfd2017-11-03 10:12:19 -070078 "set unsupported GLConsumer with target %x", target);
John Reck04fc5832014-02-05 16:38:25 -080079 }
80 }
81
John Reck1bcacfd2017-11-03 10:12:19 -070082 ANDROID_API void updateTexImage() { mUpdateTexImage = true; }
John Reck04fc5832014-02-05 16:38:25 -080083
84 ANDROID_API void setTransform(const SkMatrix* matrix) {
85 delete mTransform;
Chris Craikd41c4d82015-01-05 15:51:13 -080086 mTransform = matrix ? new SkMatrix(*matrix) : nullptr;
John Reck04fc5832014-02-05 16:38:25 -080087 }
88
John Reck1bcacfd2017-11-03 10:12:19 -070089 SkMatrix* getTransform() { return mTransform; }
John Reck417ed6d2016-03-22 16:01:08 -070090
Derek Sollenberger674554f2014-02-19 16:47:32 +000091 ANDROID_API void setPaint(const SkPaint* paint);
John Reck04fc5832014-02-05 16:38:25 -080092
Chris Craikd2dfd8f2015-12-16 14:27:20 -080093 void apply();
John Reck04fc5832014-02-05 16:38:25 -080094
John Reck1bcacfd2017-11-03 10:12:19 -070095 Layer* backingLayer() { return mLayer; }
John Reck04fc5832014-02-05 16:38:25 -080096
Chris Craikd2dfd8f2015-12-16 14:27:20 -080097 void detachSurfaceTexture();
John Reck918ad522014-06-27 14:45:25 -070098
Chris Craik09df8872017-02-14 12:37:49 -080099 void updateLayer(bool forceFilter, const float* textureTransform);
Derek Sollenberger56ad6ec2016-07-22 12:13:32 -0400100
sergeyv3e9999b2017-01-19 15:37:02 -0800101 void destroyLayer();
102
John Reck1bcacfd2017-11-03 10:12:19 -0700103 Layer::Api getBackingLayerApi() { return mLayerApi; }
sergeyv3e9999b2017-01-19 15:37:02 -0800104
John Reck04fc5832014-02-05 16:38:25 -0800105private:
sergeyv3e9999b2017-01-19 15:37:02 -0800106 RenderState& mRenderState;
107
John Reck04fc5832014-02-05 16:38:25 -0800108 // Generic properties
sergeyv3e9999b2017-01-19 15:37:02 -0800109 int mWidth = 0;
110 int mHeight = 0;
111 bool mBlend = false;
112 SkColorFilter* mColorFilter = nullptr;
113 int mAlpha = 255;
114 SkBlendMode mMode = SkBlendMode::kSrcOver;
John Reck04fc5832014-02-05 16:38:25 -0800115 sp<GLConsumer> mSurfaceTexture;
116 SkMatrix* mTransform;
sergeyv00eb43d2017-02-13 14:34:15 -0800117 bool mGLContextAttached;
John Reck04fc5832014-02-05 16:38:25 -0800118 bool mUpdateTexImage;
119
120 Layer* mLayer;
sergeyv3e9999b2017-01-19 15:37:02 -0800121 Layer::Api mLayerApi;
122 CreateLayerFn mCreateLayerFn;
John Reckd72e0a32014-05-29 18:56:11 -0700123
John Reck04fc5832014-02-05 16:38:25 -0800124 void doUpdateTexImage();
Greg Daniel45ec62b2017-01-04 14:27:00 -0500125 void doUpdateVkTexImage();
John Reck04fc5832014-02-05 16:38:25 -0800126};
127
128} /* namespace uirenderer */
129} /* namespace android */