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