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" |
| 26 | #include "OpenGLRenderer.h" |
| 27 | #include "Rect.h" |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 28 | #include "RenderNode.h" |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 29 | |
| 30 | namespace android { |
| 31 | namespace uirenderer { |
| 32 | |
John Reck | d72e0a3 | 2014-05-29 18:56:11 -0700 | [diff] [blame] | 33 | typedef void (*LayerDestroyer)(Layer* layer); |
| 34 | |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 35 | // Container to hold the properties a layer should be set to at the start |
| 36 | // of a render pass |
John Reck | d72e0a3 | 2014-05-29 18:56:11 -0700 | [diff] [blame] | 37 | class DeferredLayerUpdater : public VirtualLightRefBase { |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 38 | public: |
John Reck | a39dd59 | 2014-02-14 16:59:37 -0800 | [diff] [blame] | 39 | // Note that DeferredLayerUpdater assumes it is taking ownership of the layer |
| 40 | // and will not call incrementRef on it as a result. |
John Reck | d72e0a3 | 2014-05-29 18:56:11 -0700 | [diff] [blame] | 41 | ANDROID_API DeferredLayerUpdater(Layer* layer, LayerDestroyer = 0); |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 42 | ANDROID_API ~DeferredLayerUpdater(); |
| 43 | |
| 44 | ANDROID_API bool setSize(uint32_t width, uint32_t height) { |
| 45 | if (mWidth != width || mHeight != height) { |
| 46 | mWidth = width; |
| 47 | mHeight = height; |
| 48 | return true; |
| 49 | } |
| 50 | return false; |
| 51 | } |
| 52 | |
| 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; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | ANDROID_API void updateTexImage() { |
| 69 | mUpdateTexImage = true; |
| 70 | } |
| 71 | |
| 72 | ANDROID_API void setTransform(const SkMatrix* matrix) { |
| 73 | delete mTransform; |
| 74 | mTransform = matrix ? new SkMatrix(*matrix) : 0; |
| 75 | } |
| 76 | |
John Reck | e18264b | 2014-03-12 13:56:30 -0700 | [diff] [blame] | 77 | ANDROID_API void setDisplayList(RenderNode* displayList, |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 78 | int left, int top, int right, int bottom); |
| 79 | |
Derek Sollenberger | 674554f | 2014-02-19 16:47:32 +0000 | [diff] [blame] | 80 | ANDROID_API void setPaint(const SkPaint* paint); |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 81 | |
John Reck | 860d155 | 2014-04-11 19:15:05 -0700 | [diff] [blame] | 82 | ANDROID_API bool apply(TreeInfo& info); |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 83 | |
| 84 | ANDROID_API Layer* backingLayer() { |
| 85 | return mLayer; |
| 86 | } |
| 87 | |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 88 | private: |
| 89 | // Generic properties |
| 90 | uint32_t mWidth; |
| 91 | uint32_t mHeight; |
| 92 | bool mBlend; |
| 93 | SkColorFilter* mColorFilter; |
| 94 | int mAlpha; |
| 95 | SkXfermode::Mode mMode; |
| 96 | |
| 97 | // Layer type specific properties |
| 98 | // displayList and surfaceTexture are mutually exclusive, only 1 may be set |
| 99 | // dirtyRect is only valid if displayList is set |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 100 | sp<RenderNode> mDisplayList; |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 101 | Rect mDirtyRect; |
| 102 | sp<GLConsumer> mSurfaceTexture; |
| 103 | SkMatrix* mTransform; |
| 104 | bool mNeedsGLContextAttach; |
| 105 | bool mUpdateTexImage; |
| 106 | |
| 107 | Layer* mLayer; |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 108 | Caches& mCaches; |
| 109 | |
John Reck | d72e0a3 | 2014-05-29 18:56:11 -0700 | [diff] [blame] | 110 | LayerDestroyer mDestroyer; |
| 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_ */ |