DeferredLayerUpdater.h revision 25fbb3fa1138675379102a44405852555cefccbd
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 25#include "Layer.h" 26#include "OpenGLRenderer.h" 27#include "Rect.h" 28#include "RenderNode.h" 29 30namespace android { 31namespace uirenderer { 32 33typedef void (*LayerDestroyer)(Layer* layer); 34 35// Container to hold the properties a layer should be set to at the start 36// of a render pass 37class DeferredLayerUpdater : public VirtualLightRefBase { 38public: 39 // Note that DeferredLayerUpdater assumes it is taking ownership of the layer 40 // and will not call incrementRef on it as a result. 41 ANDROID_API DeferredLayerUpdater(Layer* layer, LayerDestroyer = 0); 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 77 ANDROID_API void setPaint(const SkPaint* paint); 78 79 ANDROID_API bool apply(TreeInfo& info); 80 81 ANDROID_API Layer* backingLayer() { 82 return mLayer; 83 } 84 85private: 86 // Generic properties 87 uint32_t mWidth; 88 uint32_t mHeight; 89 bool mBlend; 90 SkColorFilter* mColorFilter; 91 int mAlpha; 92 SkXfermode::Mode mMode; 93 94 sp<GLConsumer> mSurfaceTexture; 95 SkMatrix* mTransform; 96 bool mNeedsGLContextAttach; 97 bool mUpdateTexImage; 98 99 Layer* mLayer; 100 Caches& mCaches; 101 102 LayerDestroyer mDestroyer; 103 104 void doUpdateTexImage(); 105}; 106 107} /* namespace uirenderer */ 108} /* namespace android */ 109 110#endif /* DEFERREDLAYERUPDATE_H_ */ 111