blob: 4c323b861002c141596bec6d97ae5ef123b39e9b [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>
Stan Iliev564ca3e2018-09-04 22:00:00 +000020#include <SkImage.h>
John Reck04fc5832014-02-05 16:38:25 -080021#include <SkMatrix.h>
John Reck1bcacfd2017-11-03 10:12:19 -070022#include <cutils/compiler.h>
Stan Iliev564ca3e2018-09-04 22:00:00 +000023#include <map>
Derek Sollenbergerbe3876c2018-04-20 16:13:31 -040024#include <system/graphics.h>
John Reck04fc5832014-02-05 16:38:25 -080025#include <utils/StrongPointer.h>
26
Greg Daniel8cd3edf2017-01-09 14:15:41 -050027#include <GLES2/gl2.h>
28#include <GLES2/gl2ext.h>
29
Stan Iliev564ca3e2018-09-04 22:00:00 +000030#include "surfacetexture/SurfaceTexture.h"
John Reck04fc5832014-02-05 16:38:25 -080031#include "Layer.h"
John Reck04fc5832014-02-05 16:38:25 -080032#include "Rect.h"
33
34namespace android {
35namespace uirenderer {
36
sergeyv3e9999b2017-01-19 15:37:02 -080037class RenderState;
38
John Reck04fc5832014-02-05 16:38:25 -080039// Container to hold the properties a layer should be set to at the start
40// of a render pass
John Reckd72e0a32014-05-29 18:56:11 -070041class DeferredLayerUpdater : public VirtualLightRefBase {
John Reck04fc5832014-02-05 16:38:25 -080042public:
John Recka39dd592014-02-14 16:59:37 -080043 // Note that DeferredLayerUpdater assumes it is taking ownership of the layer
44 // and will not call incrementRef on it as a result.
Stan Iliev564ca3e2018-09-04 22:00:00 +000045 ANDROID_API explicit DeferredLayerUpdater(RenderState& renderState);
sergeyv3e9999b2017-01-19 15:37:02 -080046
John Reck04fc5832014-02-05 16:38:25 -080047 ANDROID_API ~DeferredLayerUpdater();
48
Dan Stozaa41f29c2014-11-12 12:35:42 -080049 ANDROID_API bool setSize(int width, int height) {
John Reck04fc5832014-02-05 16:38:25 -080050 if (mWidth != width || mHeight != height) {
51 mWidth = width;
52 mHeight = height;
53 return true;
54 }
55 return false;
56 }
57
John Reck417ed6d2016-03-22 16:01:08 -070058 int getWidth() { return mWidth; }
59 int getHeight() { return mHeight; }
60
John Reck04fc5832014-02-05 16:38:25 -080061 ANDROID_API bool setBlend(bool blend) {
62 if (blend != mBlend) {
63 mBlend = blend;
64 return true;
65 }
66 return false;
67 }
68
Stan Iliev564ca3e2018-09-04 22:00:00 +000069 ANDROID_API void setSurfaceTexture(const sp<SurfaceTexture>& consumer) {
70 if (consumer.get() != mSurfaceTexture.get()) {
71 mSurfaceTexture = consumer;
Chris Craik48f650c2015-03-10 11:03:39 -070072
Stan Iliev564ca3e2018-09-04 22:00:00 +000073 GLenum target = consumer->getCurrentTextureTarget();
Chris Craik48f650c2015-03-10 11:03:39 -070074 LOG_ALWAYS_FATAL_IF(target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES,
Stan Iliev564ca3e2018-09-04 22:00:00 +000075 "set unsupported SurfaceTexture with target %x", target);
John Reck04fc5832014-02-05 16:38:25 -080076 }
77 }
78
John Reck1bcacfd2017-11-03 10:12:19 -070079 ANDROID_API void updateTexImage() { mUpdateTexImage = true; }
John Reck04fc5832014-02-05 16:38:25 -080080
81 ANDROID_API void setTransform(const SkMatrix* matrix) {
82 delete mTransform;
Chris Craikd41c4d82015-01-05 15:51:13 -080083 mTransform = matrix ? new SkMatrix(*matrix) : nullptr;
John Reck04fc5832014-02-05 16:38:25 -080084 }
85
John Reck1bcacfd2017-11-03 10:12:19 -070086 SkMatrix* getTransform() { return mTransform; }
John Reck417ed6d2016-03-22 16:01:08 -070087
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 Reck1bcacfd2017-11-03 10:12:19 -070092 Layer* backingLayer() { return mLayer; }
John Reck04fc5832014-02-05 16:38:25 -080093
Chris Craikd2dfd8f2015-12-16 14:27:20 -080094 void detachSurfaceTexture();
John Reck918ad522014-06-27 14:45:25 -070095
Stan Iliev564ca3e2018-09-04 22:00:00 +000096 void updateLayer(bool forceFilter, const SkMatrix& textureTransform,
97 android_dataspace dataspace, const sk_sp<SkImage>& layerImage);
Derek Sollenberger56ad6ec2016-07-22 12:13:32 -040098
sergeyv3e9999b2017-01-19 15:37:02 -080099 void destroyLayer();
100
John Reck04fc5832014-02-05 16:38:25 -0800101private:
sergeyv3e9999b2017-01-19 15:37:02 -0800102 RenderState& mRenderState;
103
John Reck04fc5832014-02-05 16:38:25 -0800104 // Generic properties
sergeyv3e9999b2017-01-19 15:37:02 -0800105 int mWidth = 0;
106 int mHeight = 0;
107 bool mBlend = false;
Derek Sollenbergerbe3876c2018-04-20 16:13:31 -0400108 sk_sp<SkColorFilter> mColorFilter;
sergeyv3e9999b2017-01-19 15:37:02 -0800109 int mAlpha = 255;
110 SkBlendMode mMode = SkBlendMode::kSrcOver;
Stan Iliev564ca3e2018-09-04 22:00:00 +0000111 sp<SurfaceTexture> mSurfaceTexture;
John Reck04fc5832014-02-05 16:38:25 -0800112 SkMatrix* mTransform;
sergeyv00eb43d2017-02-13 14:34:15 -0800113 bool mGLContextAttached;
John Reck04fc5832014-02-05 16:38:25 -0800114 bool mUpdateTexImage;
115
116 Layer* mLayer;
John Reck04fc5832014-02-05 16:38:25 -0800117};
118
119} /* namespace uirenderer */
120} /* namespace android */