DeferredLayerUpdater.h revision d72e0a339b54af0c4e731513bbad120dff694723
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 "OpenGLRenderer.h"
2704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck#include "Rect.h"
28113e0824d6bddf4376240681f9cf6a2deded9498John Reck#include "RenderNode.h"
2904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
3004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Recknamespace android {
3104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Recknamespace uirenderer {
3204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
33d72e0a339b54af0c4e731513bbad120dff694723John Recktypedef void (*LayerDestroyer)(Layer* layer);
34d72e0a339b54af0c4e731513bbad120dff694723John Reck
3504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck// Container to hold the properties a layer should be set to at the start
3604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck// of a render pass
37d72e0a339b54af0c4e731513bbad120dff694723John Reckclass DeferredLayerUpdater : public VirtualLightRefBase {
3804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reckpublic:
39a39dd595791b41222ab310b5e8a76a64faa8ba5cJohn Reck    // Note that DeferredLayerUpdater assumes it is taking ownership of the layer
40a39dd595791b41222ab310b5e8a76a64faa8ba5cJohn Reck    // and will not call incrementRef on it as a result.
41d72e0a339b54af0c4e731513bbad120dff694723John Reck    ANDROID_API DeferredLayerUpdater(Layer* layer, LayerDestroyer = 0);
4204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    ANDROID_API ~DeferredLayerUpdater();
4304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
4404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    ANDROID_API bool setSize(uint32_t width, uint32_t height) {
4504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        if (mWidth != width || mHeight != height) {
4604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck            mWidth = width;
4704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck            mHeight = height;
4804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck            return true;
4904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        }
5004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        return false;
5104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    }
5204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John 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;
6504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        }
6604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    }
6704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
6804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    ANDROID_API void updateTexImage() {
6904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        mUpdateTexImage = true;
7004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    }
7104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
7204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    ANDROID_API void setTransform(const SkMatrix* matrix) {
7304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        delete mTransform;
7404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        mTransform = matrix ? new SkMatrix(*matrix) : 0;
7504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    }
7604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
77e18264b079481a244b30e3f71012c53bbd861f92John Reck    ANDROID_API void setDisplayList(RenderNode* displayList,
7804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck                int left, int top, int right, int bottom);
7904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
80674554fc36932ca50b15bba41ac6f650254d4e72Derek Sollenberger    ANDROID_API void setPaint(const SkPaint* paint);
8104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
82860d155f866cc15a725e7ce03763280987f24901John Reck    ANDROID_API bool apply(TreeInfo& info);
8304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
8404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    ANDROID_API Layer* backingLayer() {
8504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        return mLayer;
8604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    }
8704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
8804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reckprivate:
8904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    // Generic properties
9004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    uint32_t mWidth;
9104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    uint32_t mHeight;
9204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    bool mBlend;
9304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    SkColorFilter* mColorFilter;
9404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    int mAlpha;
9504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    SkXfermode::Mode mMode;
9604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
9704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    // Layer type specific properties
9804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    // displayList and surfaceTexture are mutually exclusive, only 1 may be set
9904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    // dirtyRect is only valid if displayList is set
100087bc0c14bdccf7c258dce0cdef46a69a839b427John Reck    sp<RenderNode> mDisplayList;
10104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    Rect mDirtyRect;
10204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    sp<GLConsumer> mSurfaceTexture;
10304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    SkMatrix* mTransform;
10404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    bool mNeedsGLContextAttach;
10504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    bool mUpdateTexImage;
10604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
10704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    Layer* mLayer;
10804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    Caches& mCaches;
10904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
110d72e0a339b54af0c4e731513bbad120dff694723John Reck    LayerDestroyer mDestroyer;
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