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 | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 27 | #include "RenderNode.h" |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 28 | |
| 29 | namespace android { |
| 30 | namespace uirenderer { |
| 31 | |
John Reck | d72e0a3 | 2014-05-29 18:56:11 -0700 | [diff] [blame] | 32 | typedef void (*LayerDestroyer)(Layer* layer); |
| 33 | |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 34 | // Container to hold the properties a layer should be set to at the start |
| 35 | // of a render pass |
John Reck | d72e0a3 | 2014-05-29 18:56:11 -0700 | [diff] [blame] | 36 | class DeferredLayerUpdater : public VirtualLightRefBase { |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 37 | public: |
John Reck | a39dd59 | 2014-02-14 16:59:37 -0800 | [diff] [blame] | 38 | // Note that DeferredLayerUpdater assumes it is taking ownership of the layer |
| 39 | // and will not call incrementRef on it as a result. |
John Reck | d72e0a3 | 2014-05-29 18:56:11 -0700 | [diff] [blame] | 40 | ANDROID_API DeferredLayerUpdater(Layer* layer, LayerDestroyer = 0); |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 41 | ANDROID_API ~DeferredLayerUpdater(); |
| 42 | |
| 43 | ANDROID_API bool setSize(uint32_t width, uint32_t height) { |
| 44 | if (mWidth != width || mHeight != height) { |
| 45 | mWidth = width; |
| 46 | mHeight = height; |
| 47 | return true; |
| 48 | } |
| 49 | return false; |
| 50 | } |
| 51 | |
| 52 | ANDROID_API bool setBlend(bool blend) { |
| 53 | if (blend != mBlend) { |
| 54 | mBlend = blend; |
| 55 | return true; |
| 56 | } |
| 57 | return false; |
| 58 | } |
| 59 | |
| 60 | ANDROID_API void setSurfaceTexture(const sp<GLConsumer>& texture, bool needsAttach) { |
| 61 | if (texture.get() != mSurfaceTexture.get()) { |
| 62 | mNeedsGLContextAttach = needsAttach; |
| 63 | mSurfaceTexture = texture; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | ANDROID_API void updateTexImage() { |
| 68 | mUpdateTexImage = true; |
| 69 | } |
| 70 | |
| 71 | ANDROID_API void setTransform(const SkMatrix* matrix) { |
| 72 | delete mTransform; |
| 73 | mTransform = matrix ? new SkMatrix(*matrix) : 0; |
| 74 | } |
| 75 | |
Derek Sollenberger | 674554f | 2014-02-19 16:47:32 +0000 | [diff] [blame] | 76 | ANDROID_API void setPaint(const SkPaint* paint); |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 77 | |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 78 | ANDROID_API bool apply(); |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 79 | |
| 80 | ANDROID_API Layer* backingLayer() { |
| 81 | return mLayer; |
| 82 | } |
| 83 | |
John Reck | 918ad52 | 2014-06-27 14:45:25 -0700 | [diff] [blame] | 84 | ANDROID_API void detachSurfaceTexture(); |
| 85 | |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 86 | private: |
| 87 | // Generic properties |
| 88 | uint32_t mWidth; |
| 89 | uint32_t mHeight; |
| 90 | bool mBlend; |
| 91 | SkColorFilter* mColorFilter; |
| 92 | int mAlpha; |
| 93 | SkXfermode::Mode mMode; |
| 94 | |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 95 | sp<GLConsumer> mSurfaceTexture; |
| 96 | SkMatrix* mTransform; |
| 97 | bool mNeedsGLContextAttach; |
| 98 | bool mUpdateTexImage; |
| 99 | |
| 100 | Layer* mLayer; |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 101 | Caches& mCaches; |
| 102 | |
John Reck | d72e0a3 | 2014-05-29 18:56:11 -0700 | [diff] [blame] | 103 | LayerDestroyer mDestroyer; |
| 104 | |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 105 | void doUpdateTexImage(); |
| 106 | }; |
| 107 | |
| 108 | } /* namespace uirenderer */ |
| 109 | } /* namespace android */ |
| 110 | |
| 111 | #endif /* DEFERREDLAYERUPDATE_H_ */ |