DeferredLayerUpdater.h revision 918ad523b2780e0c893f3d2a32d4ec13f2a7e921
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"
27113e0824d6bddf4376240681f9cf6a2deded9498John Reck#include "RenderNode.h"
2804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
2904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Recknamespace android {
3004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Recknamespace uirenderer {
3104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
32d72e0a339b54af0c4e731513bbad120dff694723John Recktypedef void (*LayerDestroyer)(Layer* layer);
33d72e0a339b54af0c4e731513bbad120dff694723John Reck
3404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck// Container to hold the properties a layer should be set to at the start
3504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck// of a render pass
36d72e0a339b54af0c4e731513bbad120dff694723John Reckclass DeferredLayerUpdater : public VirtualLightRefBase {
3704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reckpublic:
38a39dd595791b41222ab310b5e8a76a64faa8ba5cJohn Reck    // Note that DeferredLayerUpdater assumes it is taking ownership of the layer
39a39dd595791b41222ab310b5e8a76a64faa8ba5cJohn Reck    // and will not call incrementRef on it as a result.
40d72e0a339b54af0c4e731513bbad120dff694723John Reck    ANDROID_API DeferredLayerUpdater(Layer* layer, LayerDestroyer = 0);
4104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    ANDROID_API ~DeferredLayerUpdater();
4204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
4304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    ANDROID_API bool setSize(uint32_t width, uint32_t height) {
4404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        if (mWidth != width || mHeight != height) {
4504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck            mWidth = width;
4604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck            mHeight = height;
4704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck            return true;
4804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        }
4904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        return false;
5004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    }
5104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
5204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    ANDROID_API bool setBlend(bool blend) {
5304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        if (blend != mBlend) {
5404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck            mBlend = blend;
5504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck            return true;
5604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        }
5704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        return false;
5804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    }
5904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
6004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    ANDROID_API void setSurfaceTexture(const sp<GLConsumer>& texture, bool needsAttach) {
6104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        if (texture.get() != mSurfaceTexture.get()) {
6204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck            mNeedsGLContextAttach = needsAttach;
6304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck            mSurfaceTexture = texture;
6404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        }
6504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    }
6604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
6704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    ANDROID_API void updateTexImage() {
6804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        mUpdateTexImage = true;
6904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    }
7004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
7104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    ANDROID_API void setTransform(const SkMatrix* matrix) {
7204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        delete mTransform;
7304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        mTransform = matrix ? new SkMatrix(*matrix) : 0;
7404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    }
7504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
76674554fc36932ca50b15bba41ac6f650254d4e72Derek Sollenberger    ANDROID_API void setPaint(const SkPaint* paint);
7704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
7868bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    ANDROID_API bool apply();
7904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
8004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    ANDROID_API Layer* backingLayer() {
8104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        return mLayer;
8204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    }
8304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
84918ad523b2780e0c893f3d2a32d4ec13f2a7e921John Reck    ANDROID_API void detachSurfaceTexture();
85918ad523b2780e0c893f3d2a32d4ec13f2a7e921John Reck
8604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reckprivate:
8704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    // Generic properties
8804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    uint32_t mWidth;
8904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    uint32_t mHeight;
9004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    bool mBlend;
9104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    SkColorFilter* mColorFilter;
9204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    int mAlpha;
9304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    SkXfermode::Mode mMode;
9404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
9504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    sp<GLConsumer> mSurfaceTexture;
9604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    SkMatrix* mTransform;
9704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    bool mNeedsGLContextAttach;
9804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    bool mUpdateTexImage;
9904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
10004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    Layer* mLayer;
10104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    Caches& mCaches;
10204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
103d72e0a339b54af0c4e731513bbad120dff694723John Reck    LayerDestroyer mDestroyer;
104d72e0a339b54af0c4e731513bbad120dff694723John Reck
10504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    void doUpdateTexImage();
10604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck};
10704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
10804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck} /* namespace uirenderer */
10904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck} /* namespace android */
11004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
11104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck#endif /* DEFERREDLAYERUPDATE_H_ */
112