blob: a91c111933c4a8939aef2afb6efbb93d5c13b4b7 [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
Derek Sollenberger28a4d992018-09-20 13:37:24 -040030#include "renderstate/RenderState.h"
Stan Iliev564ca3e2018-09-04 22:00:00 +000031#include "surfacetexture/SurfaceTexture.h"
John Reck04fc5832014-02-05 16:38:25 -080032#include "Layer.h"
John Reck04fc5832014-02-05 16:38:25 -080033#include "Rect.h"
34
35namespace android {
36namespace uirenderer {
37
sergeyv3e9999b2017-01-19 15:37:02 -080038class RenderState;
39
John Reck04fc5832014-02-05 16:38:25 -080040// Container to hold the properties a layer should be set to at the start
41// of a render pass
Derek Sollenberger28a4d992018-09-20 13:37:24 -040042class DeferredLayerUpdater : public VirtualLightRefBase, public IGpuContextCallback {
John Reck04fc5832014-02-05 16:38:25 -080043public:
John Recka39dd592014-02-14 16:59:37 -080044 // Note that DeferredLayerUpdater assumes it is taking ownership of the layer
45 // and will not call incrementRef on it as a result.
Stan Iliev564ca3e2018-09-04 22:00:00 +000046 ANDROID_API explicit DeferredLayerUpdater(RenderState& renderState);
sergeyv3e9999b2017-01-19 15:37:02 -080047
John Reck04fc5832014-02-05 16:38:25 -080048 ANDROID_API ~DeferredLayerUpdater();
49
Dan Stozaa41f29c2014-11-12 12:35:42 -080050 ANDROID_API bool setSize(int width, int height) {
John Reck04fc5832014-02-05 16:38:25 -080051 if (mWidth != width || mHeight != height) {
52 mWidth = width;
53 mHeight = height;
54 return true;
55 }
56 return false;
57 }
58
John Reck417ed6d2016-03-22 16:01:08 -070059 int getWidth() { return mWidth; }
60 int getHeight() { return mHeight; }
61
John Reck04fc5832014-02-05 16:38:25 -080062 ANDROID_API bool setBlend(bool blend) {
63 if (blend != mBlend) {
64 mBlend = blend;
65 return true;
66 }
67 return false;
68 }
69
Stan Iliev564ca3e2018-09-04 22:00:00 +000070 ANDROID_API void setSurfaceTexture(const sp<SurfaceTexture>& consumer) {
71 if (consumer.get() != mSurfaceTexture.get()) {
72 mSurfaceTexture = consumer;
Chris Craik48f650c2015-03-10 11:03:39 -070073
Stan Iliev564ca3e2018-09-04 22:00:00 +000074 GLenum target = consumer->getCurrentTextureTarget();
Chris Craik48f650c2015-03-10 11:03:39 -070075 LOG_ALWAYS_FATAL_IF(target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES,
Stan Iliev564ca3e2018-09-04 22:00:00 +000076 "set unsupported SurfaceTexture with target %x", target);
John Reck04fc5832014-02-05 16:38:25 -080077 }
78 }
79
John Reck1bcacfd2017-11-03 10:12:19 -070080 ANDROID_API void updateTexImage() { mUpdateTexImage = true; }
John Reck04fc5832014-02-05 16:38:25 -080081
82 ANDROID_API void setTransform(const SkMatrix* matrix) {
83 delete mTransform;
Chris Craikd41c4d82015-01-05 15:51:13 -080084 mTransform = matrix ? new SkMatrix(*matrix) : nullptr;
John Reck04fc5832014-02-05 16:38:25 -080085 }
86
John Reck1bcacfd2017-11-03 10:12:19 -070087 SkMatrix* getTransform() { return mTransform; }
John Reck417ed6d2016-03-22 16:01:08 -070088
Derek Sollenberger674554f2014-02-19 16:47:32 +000089 ANDROID_API void setPaint(const SkPaint* paint);
John Reck04fc5832014-02-05 16:38:25 -080090
Chris Craikd2dfd8f2015-12-16 14:27:20 -080091 void apply();
John Reck04fc5832014-02-05 16:38:25 -080092
John Reck1bcacfd2017-11-03 10:12:19 -070093 Layer* backingLayer() { return mLayer; }
John Reck04fc5832014-02-05 16:38:25 -080094
Chris Craikd2dfd8f2015-12-16 14:27:20 -080095 void detachSurfaceTexture();
John Reck918ad522014-06-27 14:45:25 -070096
Stan Iliev564ca3e2018-09-04 22:00:00 +000097 void updateLayer(bool forceFilter, const SkMatrix& textureTransform,
Derek Sollenbergerd01b5912018-10-19 15:55:33 -040098 const sk_sp<SkImage>& layerImage);
Derek Sollenberger56ad6ec2016-07-22 12:13:32 -040099
sergeyv3e9999b2017-01-19 15:37:02 -0800100 void destroyLayer();
101
Derek Sollenberger28a4d992018-09-20 13:37:24 -0400102protected:
103 void onContextDestroyed() override;
104
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;
Derek Sollenbergerbe3876c2018-04-20 16:13:31 -0400112 sk_sp<SkColorFilter> mColorFilter;
sergeyv3e9999b2017-01-19 15:37:02 -0800113 int mAlpha = 255;
114 SkBlendMode mMode = SkBlendMode::kSrcOver;
Stan Iliev564ca3e2018-09-04 22:00:00 +0000115 sp<SurfaceTexture> mSurfaceTexture;
John Reck04fc5832014-02-05 16:38:25 -0800116 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;
John Reck04fc5832014-02-05 16:38:25 -0800121};
122
123} /* namespace uirenderer */
124} /* namespace android */