104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck/* 204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck * Copyright (C) 2014 The Android Open Source Project 304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck * 404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck * Licensed under the Apache License, Version 2.0 (the "License"); 504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck * you may not use this file except in compliance with the License. 604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck * You may obtain a copy of the License at 704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck * 804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck * http://www.apache.org/licenses/LICENSE-2.0 904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck * 1004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck * Unless required by applicable law or agreed to in writing, software 1104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck * distributed under the License is distributed on an "AS IS" BASIS, 1204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck * See the License for the specific language governing permissions and 1404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck * limitations under the License. 1504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck */ 1604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck#ifndef DEFERREDLAYERUPDATE_H_ 1704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck#define DEFERREDLAYERUPDATE_H_ 1804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck 1904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck#include <cutils/compiler.h> 2004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck#include <gui/GLConsumer.h> 2104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck#include <SkColorFilter.h> 2204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck#include <SkMatrix.h> 2304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck#include <utils/StrongPointer.h> 2404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck 2504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck#include "Layer.h" 2604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck#include "Rect.h" 27749906b468912dab7bf69a86e852deac3e80b0ccJohn Reck#include "renderthread/RenderThread.h" 2804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck 2904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Recknamespace android { 3004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Recknamespace uirenderer { 3104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck 3204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck// Container to hold the properties a layer should be set to at the start 3304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck// of a render pass 34d72e0a339b54af0c4e731513bbad120dff694723John Reckclass DeferredLayerUpdater : public VirtualLightRefBase { 3504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reckpublic: 36a39dd595791b41222ab310b5e8a76a64faa8ba5cJohn Reck // Note that DeferredLayerUpdater assumes it is taking ownership of the layer 37a39dd595791b41222ab310b5e8a76a64faa8ba5cJohn Reck // and will not call incrementRef on it as a result. 38c36df952292b69920d4764a8a37361073fcf4f2cJohn Reck ANDROID_API DeferredLayerUpdater(Layer* layer); 3904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck ANDROID_API ~DeferredLayerUpdater(); 4004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck 41a41f29cc000680f402d51972dfad0a46c5a3cb07Dan Stoza ANDROID_API bool setSize(int width, int height) { 4204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck if (mWidth != width || mHeight != height) { 4304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck mWidth = width; 4404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck mHeight = height; 4504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck return true; 4604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck } 4704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck return false; 4804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck } 4904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck 50417ed6d4337e5409d52f58cc93677c8715193f32John Reck int getWidth() { return mWidth; } 51417ed6d4337e5409d52f58cc93677c8715193f32John Reck int getHeight() { return mHeight; } 52417ed6d4337e5409d52f58cc93677c8715193f32John Reck 5304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck ANDROID_API bool setBlend(bool blend) { 5404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck if (blend != mBlend) { 5504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck mBlend = blend; 5604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck return true; 5704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck } 5804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck return false; 5904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck } 6004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck 6104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck ANDROID_API void setSurfaceTexture(const sp<GLConsumer>& texture, bool needsAttach) { 6204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck if (texture.get() != mSurfaceTexture.get()) { 6304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck mNeedsGLContextAttach = needsAttach; 6404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck mSurfaceTexture = texture; 6548f650cb24e5b028deaff01baddc1d154f78d91aChris Craik 6648f650cb24e5b028deaff01baddc1d154f78d91aChris Craik GLenum target = texture->getCurrentTextureTarget(); 6748f650cb24e5b028deaff01baddc1d154f78d91aChris Craik LOG_ALWAYS_FATAL_IF(target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES, 6848f650cb24e5b028deaff01baddc1d154f78d91aChris Craik "set unsupported GLConsumer with target %x", target); 6904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck } 7004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck } 7104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck 7204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck ANDROID_API void updateTexImage() { 7304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck mUpdateTexImage = true; 7404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck } 7504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck 7604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck ANDROID_API void setTransform(const SkMatrix* matrix) { 7704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck delete mTransform; 78d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik mTransform = matrix ? new SkMatrix(*matrix) : nullptr; 7904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck } 8004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck 81417ed6d4337e5409d52f58cc93677c8715193f32John Reck SkMatrix* getTransform() { 82417ed6d4337e5409d52f58cc93677c8715193f32John Reck return mTransform; 83417ed6d4337e5409d52f58cc93677c8715193f32John Reck } 84417ed6d4337e5409d52f58cc93677c8715193f32John Reck 85674554fc36932ca50b15bba41ac6f650254d4e72Derek Sollenberger ANDROID_API void setPaint(const SkPaint* paint); 8604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck 87d2dfd8f128b632ed99418ab2b32949c939a9a369Chris Craik void apply(); 8804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck 8912f5e3433226f0a2886a98b0b8da8d5e947c5cdeJohn Reck Layer* backingLayer() { 9004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck return mLayer; 9104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck } 9204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck 93d2dfd8f128b632ed99418ab2b32949c939a9a369Chris Craik void detachSurfaceTexture(); 94918ad523b2780e0c893f3d2a32d4ec13f2a7e921John Reck 9504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reckprivate: 9604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck // Generic properties 97a41f29cc000680f402d51972dfad0a46c5a3cb07Dan Stoza int mWidth; 98a41f29cc000680f402d51972dfad0a46c5a3cb07Dan Stoza int mHeight; 9904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck bool mBlend; 10004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck SkColorFilter* mColorFilter; 10104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck int mAlpha; 10204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck SkXfermode::Mode mMode; 10304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck 10404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck sp<GLConsumer> mSurfaceTexture; 10504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck SkMatrix* mTransform; 10604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck bool mNeedsGLContextAttach; 10704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck bool mUpdateTexImage; 10804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck 10904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck Layer* mLayer; 11004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck Caches& mCaches; 111d72e0a339b54af0c4e731513bbad120dff694723John Reck 11204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck void doUpdateTexImage(); 11304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck}; 11404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck 11504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck} /* namespace uirenderer */ 11604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck} /* namespace android */ 11704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck 11804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck#endif /* DEFERREDLAYERUPDATE_H_ */ 119