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 | */ |
| 16 | #ifndef DEFERREDLAYERUPDATE_H_ |
| 17 | #define DEFERREDLAYERUPDATE_H_ |
| 18 | |
| 19 | #include <cutils/compiler.h> |
| 20 | #include <gui/GLConsumer.h> |
| 21 | #include <SkColorFilter.h> |
| 22 | #include <SkMatrix.h> |
| 23 | #include <utils/StrongPointer.h> |
| 24 | |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 25 | #include "Layer.h" |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 26 | #include "Rect.h" |
John Reck | 749906b | 2014-10-03 15:02:19 -0700 | [diff] [blame] | 27 | #include "renderthread/RenderThread.h" |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 28 | |
| 29 | namespace android { |
| 30 | namespace uirenderer { |
| 31 | |
| 32 | // Container to hold the properties a layer should be set to at the start |
| 33 | // of a render pass |
John Reck | d72e0a3 | 2014-05-29 18:56:11 -0700 | [diff] [blame] | 34 | class DeferredLayerUpdater : public VirtualLightRefBase { |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 35 | public: |
John Reck | a39dd59 | 2014-02-14 16:59:37 -0800 | [diff] [blame] | 36 | // Note that DeferredLayerUpdater assumes it is taking ownership of the layer |
| 37 | // and will not call incrementRef on it as a result. |
John Reck | c36df95 | 2015-07-29 10:09:36 -0700 | [diff] [blame] | 38 | ANDROID_API DeferredLayerUpdater(Layer* layer); |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 39 | ANDROID_API ~DeferredLayerUpdater(); |
| 40 | |
Dan Stoza | a41f29c | 2014-11-12 12:35:42 -0800 | [diff] [blame] | 41 | ANDROID_API bool setSize(int width, int height) { |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 42 | if (mWidth != width || mHeight != height) { |
| 43 | mWidth = width; |
| 44 | mHeight = height; |
| 45 | return true; |
| 46 | } |
| 47 | return false; |
| 48 | } |
| 49 | |
John Reck | 417ed6d | 2016-03-22 16:01:08 -0700 | [diff] [blame] | 50 | int getWidth() { return mWidth; } |
| 51 | int getHeight() { return mHeight; } |
| 52 | |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 53 | ANDROID_API bool setBlend(bool blend) { |
| 54 | if (blend != mBlend) { |
| 55 | mBlend = blend; |
| 56 | return true; |
| 57 | } |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | ANDROID_API void setSurfaceTexture(const sp<GLConsumer>& texture, bool needsAttach) { |
| 62 | if (texture.get() != mSurfaceTexture.get()) { |
| 63 | mNeedsGLContextAttach = needsAttach; |
| 64 | mSurfaceTexture = texture; |
Chris Craik | 48f650c | 2015-03-10 11:03:39 -0700 | [diff] [blame] | 65 | |
| 66 | GLenum target = texture->getCurrentTextureTarget(); |
| 67 | LOG_ALWAYS_FATAL_IF(target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES, |
| 68 | "set unsupported GLConsumer with target %x", target); |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
| 72 | ANDROID_API void updateTexImage() { |
| 73 | mUpdateTexImage = true; |
| 74 | } |
| 75 | |
| 76 | ANDROID_API void setTransform(const SkMatrix* matrix) { |
| 77 | delete mTransform; |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 78 | mTransform = matrix ? new SkMatrix(*matrix) : nullptr; |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 79 | } |
| 80 | |
John Reck | 417ed6d | 2016-03-22 16:01:08 -0700 | [diff] [blame] | 81 | SkMatrix* getTransform() { |
| 82 | return mTransform; |
| 83 | } |
| 84 | |
Derek Sollenberger | 674554f | 2014-02-19 16:47:32 +0000 | [diff] [blame] | 85 | ANDROID_API void setPaint(const SkPaint* paint); |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 86 | |
Chris Craik | d2dfd8f | 2015-12-16 14:27:20 -0800 | [diff] [blame] | 87 | void apply(); |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 88 | |
John Reck | 12f5e34 | 2014-11-07 07:53:43 -0800 | [diff] [blame] | 89 | Layer* backingLayer() { |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 90 | return mLayer; |
| 91 | } |
| 92 | |
Chris Craik | d2dfd8f | 2015-12-16 14:27:20 -0800 | [diff] [blame] | 93 | void detachSurfaceTexture(); |
John Reck | 918ad52 | 2014-06-27 14:45:25 -0700 | [diff] [blame] | 94 | |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 95 | private: |
| 96 | // Generic properties |
Dan Stoza | a41f29c | 2014-11-12 12:35:42 -0800 | [diff] [blame] | 97 | int mWidth; |
| 98 | int mHeight; |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 99 | bool mBlend; |
| 100 | SkColorFilter* mColorFilter; |
| 101 | int mAlpha; |
| 102 | SkXfermode::Mode mMode; |
| 103 | |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 104 | sp<GLConsumer> mSurfaceTexture; |
| 105 | SkMatrix* mTransform; |
| 106 | bool mNeedsGLContextAttach; |
| 107 | bool mUpdateTexImage; |
| 108 | |
| 109 | Layer* mLayer; |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 110 | Caches& mCaches; |
John Reck | d72e0a3 | 2014-05-29 18:56:11 -0700 | [diff] [blame] | 111 | |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 112 | void doUpdateTexImage(); |
| 113 | }; |
| 114 | |
| 115 | } /* namespace uirenderer */ |
| 116 | } /* namespace android */ |
| 117 | |
| 118 | #endif /* DEFERREDLAYERUPDATE_H_ */ |