DeferredLayerUpdater.h revision 674554fc36932ca50b15bba41ac6f650254d4e72
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 "DisplayList.h"
2604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck#include "Layer.h"
2704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck#include "OpenGLRenderer.h"
2804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck#include "Rect.h"
2904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
3004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Recknamespace android {
3104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Recknamespace uirenderer {
3204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
3304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck// Container to hold the properties a layer should be set to at the start
3404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck// of a render pass
3504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reckclass DeferredLayerUpdater {
3604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reckpublic:
37a39dd595791b41222ab310b5e8a76a64faa8ba5cJohn Reck    // Note that DeferredLayerUpdater assumes it is taking ownership of the layer
38a39dd595791b41222ab310b5e8a76a64faa8ba5cJohn Reck    // and will not call incrementRef on it as a result.
3904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    ANDROID_API DeferredLayerUpdater(Layer* layer, OpenGLRenderer* renderer = 0);
4004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    ANDROID_API ~DeferredLayerUpdater();
4104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
4204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    ANDROID_API bool setSize(uint32_t width, uint32_t height) {
4304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        if (mWidth != width || mHeight != height) {
4404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck            mWidth = width;
4504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck            mHeight = height;
4604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck            return true;
4704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        }
4804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        return false;
4904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    }
5004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
5104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    ANDROID_API bool setBlend(bool blend) {
5204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        if (blend != mBlend) {
5304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck            mBlend = blend;
5404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck            return true;
5504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        }
5604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        return false;
5704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    }
5804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
5904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    ANDROID_API void setSurfaceTexture(const sp<GLConsumer>& texture, bool needsAttach) {
6004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        if (texture.get() != mSurfaceTexture.get()) {
6104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck            mNeedsGLContextAttach = needsAttach;
6204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck            mSurfaceTexture = texture;
6304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        }
6404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    }
6504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
6604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    ANDROID_API void updateTexImage() {
6704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        mUpdateTexImage = true;
6804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    }
6904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
7004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    ANDROID_API void setTransform(const SkMatrix* matrix) {
7104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        delete mTransform;
7204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        mTransform = matrix ? new SkMatrix(*matrix) : 0;
7304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    }
7404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
7504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    ANDROID_API void setDisplayList(DisplayList* displayList,
7604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck                int left, int top, int right, int bottom);
7704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
78674554fc36932ca50b15bba41ac6f650254d4e72Derek Sollenberger    ANDROID_API void setPaint(const SkPaint* paint);
7904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
8004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    ANDROID_API bool apply();
8104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
8204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    ANDROID_API Layer* backingLayer() {
8304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        return mLayer;
8404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    }
8504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
8604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    ANDROID_API Layer* detachBackingLayer() {
8704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        Layer* layer = mLayer;
8804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        mLayer = 0;
8904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck        return layer;
9004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    }
9104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
9204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reckprivate:
9304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    // Generic properties
9404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    uint32_t mWidth;
9504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    uint32_t mHeight;
9604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    bool mBlend;
9704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    SkColorFilter* mColorFilter;
9804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    int mAlpha;
9904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    SkXfermode::Mode mMode;
10004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
10104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    // Layer type specific properties
10204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    // displayList and surfaceTexture are mutually exclusive, only 1 may be set
10304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    // dirtyRect is only valid if displayList is set
10404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    DisplayList* mDisplayList;
10504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    Rect mDirtyRect;
10604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    sp<GLConsumer> mSurfaceTexture;
10704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    SkMatrix* mTransform;
10804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    bool mNeedsGLContextAttach;
10904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    bool mUpdateTexImage;
11004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
11104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    Layer* mLayer;
11204fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    OpenGLRenderer* mRenderer;
11304fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    Caches& mCaches;
11404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
11504fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck    void doUpdateTexImage();
11604fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck};
11704fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
11804fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck} /* namespace uirenderer */
11904fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck} /* namespace android */
12004fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck
12104fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reck#endif /* DEFERREDLAYERUPDATE_H_ */
122