John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 1 | /* |
| 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 Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 16 | |
| 17 | #pragma once |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 18 | |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 19 | #include <SkColorFilter.h> |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 20 | #include <SkImage.h> |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 21 | #include <SkMatrix.h> |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 22 | #include <cutils/compiler.h> |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 23 | #include <map> |
Derek Sollenberger | be3876c | 2018-04-20 16:13:31 -0400 | [diff] [blame] | 24 | #include <system/graphics.h> |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 25 | #include <utils/StrongPointer.h> |
| 26 | |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 27 | #include <GLES2/gl2.h> |
| 28 | #include <GLES2/gl2ext.h> |
| 29 | |
Derek Sollenberger | 28a4d99 | 2018-09-20 13:37:24 -0400 | [diff] [blame] | 30 | #include "renderstate/RenderState.h" |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 31 | #include "surfacetexture/SurfaceTexture.h" |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 32 | #include "Layer.h" |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 33 | #include "Rect.h" |
| 34 | |
| 35 | namespace android { |
| 36 | namespace uirenderer { |
| 37 | |
sergeyv | 3e9999b | 2017-01-19 15:37:02 -0800 | [diff] [blame] | 38 | class RenderState; |
| 39 | |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 40 | // Container to hold the properties a layer should be set to at the start |
| 41 | // of a render pass |
Derek Sollenberger | 28a4d99 | 2018-09-20 13:37:24 -0400 | [diff] [blame] | 42 | class DeferredLayerUpdater : public VirtualLightRefBase, public IGpuContextCallback { |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 43 | public: |
John Reck | a39dd59 | 2014-02-14 16:59:37 -0800 | [diff] [blame] | 44 | // Note that DeferredLayerUpdater assumes it is taking ownership of the layer |
| 45 | // and will not call incrementRef on it as a result. |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 46 | ANDROID_API explicit DeferredLayerUpdater(RenderState& renderState); |
sergeyv | 3e9999b | 2017-01-19 15:37:02 -0800 | [diff] [blame] | 47 | |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 48 | ANDROID_API ~DeferredLayerUpdater(); |
| 49 | |
Dan Stoza | a41f29c | 2014-11-12 12:35:42 -0800 | [diff] [blame] | 50 | ANDROID_API bool setSize(int width, int height) { |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 51 | if (mWidth != width || mHeight != height) { |
| 52 | mWidth = width; |
| 53 | mHeight = height; |
| 54 | return true; |
| 55 | } |
| 56 | return false; |
| 57 | } |
| 58 | |
John Reck | 417ed6d | 2016-03-22 16:01:08 -0700 | [diff] [blame] | 59 | int getWidth() { return mWidth; } |
| 60 | int getHeight() { return mHeight; } |
| 61 | |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 62 | ANDROID_API bool setBlend(bool blend) { |
| 63 | if (blend != mBlend) { |
| 64 | mBlend = blend; |
| 65 | return true; |
| 66 | } |
| 67 | return false; |
| 68 | } |
| 69 | |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 70 | ANDROID_API void setSurfaceTexture(const sp<SurfaceTexture>& consumer) { |
| 71 | if (consumer.get() != mSurfaceTexture.get()) { |
| 72 | mSurfaceTexture = consumer; |
Chris Craik | 48f650c | 2015-03-10 11:03:39 -0700 | [diff] [blame] | 73 | |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 74 | GLenum target = consumer->getCurrentTextureTarget(); |
Chris Craik | 48f650c | 2015-03-10 11:03:39 -0700 | [diff] [blame] | 75 | LOG_ALWAYS_FATAL_IF(target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES, |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 76 | "set unsupported SurfaceTexture with target %x", target); |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 80 | ANDROID_API void updateTexImage() { mUpdateTexImage = true; } |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 81 | |
| 82 | ANDROID_API void setTransform(const SkMatrix* matrix) { |
| 83 | delete mTransform; |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 84 | mTransform = matrix ? new SkMatrix(*matrix) : nullptr; |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 85 | } |
| 86 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 87 | SkMatrix* getTransform() { return mTransform; } |
John Reck | 417ed6d | 2016-03-22 16:01:08 -0700 | [diff] [blame] | 88 | |
Derek Sollenberger | 674554f | 2014-02-19 16:47:32 +0000 | [diff] [blame] | 89 | ANDROID_API void setPaint(const SkPaint* paint); |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 90 | |
Chris Craik | d2dfd8f | 2015-12-16 14:27:20 -0800 | [diff] [blame] | 91 | void apply(); |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 92 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 93 | Layer* backingLayer() { return mLayer; } |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 94 | |
Chris Craik | d2dfd8f | 2015-12-16 14:27:20 -0800 | [diff] [blame] | 95 | void detachSurfaceTexture(); |
John Reck | 918ad52 | 2014-06-27 14:45:25 -0700 | [diff] [blame] | 96 | |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 97 | void updateLayer(bool forceFilter, const SkMatrix& textureTransform, |
Derek Sollenberger | d01b591 | 2018-10-19 15:55:33 -0400 | [diff] [blame] | 98 | const sk_sp<SkImage>& layerImage); |
Derek Sollenberger | 56ad6ec | 2016-07-22 12:13:32 -0400 | [diff] [blame] | 99 | |
sergeyv | 3e9999b | 2017-01-19 15:37:02 -0800 | [diff] [blame] | 100 | void destroyLayer(); |
| 101 | |
Derek Sollenberger | 28a4d99 | 2018-09-20 13:37:24 -0400 | [diff] [blame] | 102 | protected: |
| 103 | void onContextDestroyed() override; |
| 104 | |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 105 | private: |
sergeyv | 3e9999b | 2017-01-19 15:37:02 -0800 | [diff] [blame] | 106 | RenderState& mRenderState; |
| 107 | |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 108 | // Generic properties |
sergeyv | 3e9999b | 2017-01-19 15:37:02 -0800 | [diff] [blame] | 109 | int mWidth = 0; |
| 110 | int mHeight = 0; |
| 111 | bool mBlend = false; |
Derek Sollenberger | be3876c | 2018-04-20 16:13:31 -0400 | [diff] [blame] | 112 | sk_sp<SkColorFilter> mColorFilter; |
sergeyv | 3e9999b | 2017-01-19 15:37:02 -0800 | [diff] [blame] | 113 | int mAlpha = 255; |
| 114 | SkBlendMode mMode = SkBlendMode::kSrcOver; |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 115 | sp<SurfaceTexture> mSurfaceTexture; |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 116 | SkMatrix* mTransform; |
sergeyv | 00eb43d | 2017-02-13 14:34:15 -0800 | [diff] [blame] | 117 | bool mGLContextAttached; |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 118 | bool mUpdateTexImage; |
| 119 | |
| 120 | Layer* mLayer; |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | } /* namespace uirenderer */ |
| 124 | } /* namespace android */ |