DeferredLayerUpdater.h revision e889298cd6ae1fc0d76bc00d7d12586db03eb261
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 "DisplayList.h" 26#include "Layer.h" 27#include "OpenGLRenderer.h" 28#include "Rect.h" 29 30namespace android { 31namespace uirenderer { 32 33// Container to hold the properties a layer should be set to at the start 34// of a render pass 35class DeferredLayerUpdater { 36public: 37 ANDROID_API DeferredLayerUpdater(Layer* layer, OpenGLRenderer* renderer = 0); 38 ANDROID_API ~DeferredLayerUpdater(); 39 40 ANDROID_API bool setSize(uint32_t width, uint32_t height) { 41 if (mWidth != width || mHeight != height) { 42 mWidth = width; 43 mHeight = height; 44 return true; 45 } 46 return false; 47 } 48 49 ANDROID_API bool setBlend(bool blend) { 50 if (blend != mBlend) { 51 mBlend = blend; 52 return true; 53 } 54 return false; 55 } 56 57 ANDROID_API void setSurfaceTexture(const sp<GLConsumer>& texture, bool needsAttach) { 58 if (texture.get() != mSurfaceTexture.get()) { 59 mNeedsGLContextAttach = needsAttach; 60 mSurfaceTexture = texture; 61 } 62 } 63 64 ANDROID_API void updateTexImage() { 65 mUpdateTexImage = true; 66 } 67 68 ANDROID_API void setTransform(const SkMatrix* matrix) { 69 delete mTransform; 70 mTransform = matrix ? new SkMatrix(*matrix) : 0; 71 } 72 73 ANDROID_API void setDisplayList(DisplayList* displayList, 74 int left, int top, int right, int bottom); 75 76 ANDROID_API void setPaint(const SkPaint* paint); 77 78 ANDROID_API bool apply(); 79 ANDROID_API void applyDeferred(DeferredLayerUpdater* deferredApply); 80 81 ANDROID_API Layer* backingLayer() { 82 return mLayer; 83 } 84 85 ANDROID_API Layer* detachBackingLayer() { 86 Layer* layer = mLayer; 87 mLayer = 0; 88 return layer; 89 } 90 91private: 92 // Generic properties 93 uint32_t mWidth; 94 uint32_t mHeight; 95 bool mBlend; 96 SkColorFilter* mColorFilter; 97 int mAlpha; 98 SkXfermode::Mode mMode; 99 100 // Layer type specific properties 101 // displayList and surfaceTexture are mutually exclusive, only 1 may be set 102 // dirtyRect is only valid if displayList is set 103 DisplayList* mDisplayList; 104 Rect mDirtyRect; 105 sp<GLConsumer> mSurfaceTexture; 106 SkMatrix* mTransform; 107 bool mNeedsGLContextAttach; 108 bool mUpdateTexImage; 109 110 Layer* mLayer; 111 OpenGLRenderer* mRenderer; 112 Caches& mCaches; 113 114 void doUpdateTexImage(); 115}; 116 117} /* namespace uirenderer */ 118} /* namespace android */ 119 120#endif /* DEFERREDLAYERUPDATE_H_ */ 121