DeferredLayerUpdater.h revision d41c4d8c732095ae99c955b6b82f7306633004b1
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.
38749906b468912dab7bf69a86e852deac3e80b0ccJohn Reck    ANDROID_API DeferredLayerUpdater(renderthread::RenderThread& thread, 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
5004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    ANDROID_API bool setBlend(bool blend) {
5104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        if (blend != mBlend) {
5204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck            mBlend = blend;
5304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck            return true;
5404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        }
5504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        return false;
5604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    }
5704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
5804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    ANDROID_API void setSurfaceTexture(const sp<GLConsumer>& texture, bool needsAttach) {
5904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        if (texture.get() != mSurfaceTexture.get()) {
6004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck            mNeedsGLContextAttach = needsAttach;
6104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck            mSurfaceTexture = texture;
6204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        }
6304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    }
6404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
6504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    ANDROID_API void updateTexImage() {
6604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        mUpdateTexImage = true;
6704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    }
6804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
6904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    ANDROID_API void setTransform(const SkMatrix* matrix) {
7004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        delete mTransform;
71d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik        mTransform = matrix ? new SkMatrix(*matrix) : nullptr;
7204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    }
7304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
74674554fc36932ca50b15bba41ac6f650254d4e72Derek Sollenberger    ANDROID_API void setPaint(const SkPaint* paint);
7504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
7668bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    ANDROID_API bool apply();
7704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
7812f5e3433226f0a2886a98b0b8da8d5e947c5cdeJohn Reck    Layer* backingLayer() {
7904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        return mLayer;
8004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    }
8104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
82918ad523b2780e0c893f3d2a32d4ec13f2a7e921John Reck    ANDROID_API void detachSurfaceTexture();
83918ad523b2780e0c893f3d2a32d4ec13f2a7e921John Reck
8404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reckprivate:
8504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    // Generic properties
86a41f29cc000680f402d51972dfad0a46c5a3cb07Dan Stoza    int mWidth;
87a41f29cc000680f402d51972dfad0a46c5a3cb07Dan Stoza    int mHeight;
8804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    bool mBlend;
8904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    SkColorFilter* mColorFilter;
9004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    int mAlpha;
9104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    SkXfermode::Mode mMode;
9204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
9304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    sp<GLConsumer> mSurfaceTexture;
9404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    SkMatrix* mTransform;
9504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    bool mNeedsGLContextAttach;
9604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    bool mUpdateTexImage;
9704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
9804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    Layer* mLayer;
9904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    Caches& mCaches;
100749906b468912dab7bf69a86e852deac3e80b0ccJohn Reck    renderthread::RenderThread& mRenderThread;
101d72e0a339b54af0c4e731513bbad120dff694723John Reck
10204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    void doUpdateTexImage();
10304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck};
10404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
10504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck} /* namespace uirenderer */
10604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck} /* namespace android */
10704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
10804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck#endif /* DEFERREDLAYERUPDATE_H_ */
109