2014-02-05 16:38:25 -08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2016-07-06 16:10:09 -07:00
|
|
|
|
|
|
|
#pragma once
|
2014-02-05 16:38:25 -08:00
|
|
|
|
|
|
|
#include <cutils/compiler.h>
|
|
|
|
#include <gui/GLConsumer.h>
|
|
|
|
#include <SkColorFilter.h>
|
|
|
|
#include <SkMatrix.h>
|
|
|
|
#include <utils/StrongPointer.h>
|
|
|
|
|
2017-01-09 14:15:41 -05:00
|
|
|
#include <GLES2/gl2.h>
|
|
|
|
#include <GLES2/gl2ext.h>
|
|
|
|
|
2014-02-05 16:38:25 -08:00
|
|
|
#include "Layer.h"
|
|
|
|
#include "Rect.h"
|
2014-10-03 15:02:19 -07:00
|
|
|
#include "renderthread/RenderThread.h"
|
2014-02-05 16:38:25 -08:00
|
|
|
|
|
|
|
namespace android {
|
|
|
|
namespace uirenderer {
|
|
|
|
|
2017-01-19 15:37:02 -08:00
|
|
|
class RenderState;
|
|
|
|
|
2014-02-05 16:38:25 -08:00
|
|
|
// Container to hold the properties a layer should be set to at the start
|
|
|
|
// of a render pass
|
2014-05-29 18:56:11 -07:00
|
|
|
class DeferredLayerUpdater : public VirtualLightRefBase {
|
2014-02-05 16:38:25 -08:00
|
|
|
public:
|
2014-02-14 16:59:37 -08:00
|
|
|
// Note that DeferredLayerUpdater assumes it is taking ownership of the layer
|
|
|
|
// and will not call incrementRef on it as a result.
|
2017-01-19 15:37:02 -08:00
|
|
|
typedef std::function<Layer*(RenderState& renderState, uint32_t layerWidth,
|
|
|
|
uint32_t layerHeight, SkColorFilter* colorFilter, int alpha,
|
|
|
|
SkBlendMode mode, bool blend)> CreateLayerFn;
|
|
|
|
ANDROID_API explicit DeferredLayerUpdater(RenderState& renderState,
|
|
|
|
CreateLayerFn createLayerFn, Layer::Api layerApi);
|
|
|
|
|
2014-02-05 16:38:25 -08:00
|
|
|
ANDROID_API ~DeferredLayerUpdater();
|
|
|
|
|
2014-11-12 12:35:42 -08:00
|
|
|
ANDROID_API bool setSize(int width, int height) {
|
2014-02-05 16:38:25 -08:00
|
|
|
if (mWidth != width || mHeight != height) {
|
|
|
|
mWidth = width;
|
|
|
|
mHeight = height;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-22 16:01:08 -07:00
|
|
|
int getWidth() { return mWidth; }
|
|
|
|
int getHeight() { return mHeight; }
|
|
|
|
|
2014-02-05 16:38:25 -08:00
|
|
|
ANDROID_API bool setBlend(bool blend) {
|
|
|
|
if (blend != mBlend) {
|
|
|
|
mBlend = blend;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-02-13 14:34:15 -08:00
|
|
|
ANDROID_API void setSurfaceTexture(const sp<GLConsumer>& texture) {
|
2014-02-05 16:38:25 -08:00
|
|
|
if (texture.get() != mSurfaceTexture.get()) {
|
2017-01-04 14:27:00 -05:00
|
|
|
mSurfaceTexture = texture;
|
2015-03-10 11:03:39 -07:00
|
|
|
|
|
|
|
GLenum target = texture->getCurrentTextureTarget();
|
|
|
|
LOG_ALWAYS_FATAL_IF(target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES,
|
|
|
|
"set unsupported GLConsumer with target %x", target);
|
2014-02-05 16:38:25 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ANDROID_API void updateTexImage() {
|
|
|
|
mUpdateTexImage = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ANDROID_API void setTransform(const SkMatrix* matrix) {
|
|
|
|
delete mTransform;
|
2015-01-05 15:51:13 -08:00
|
|
|
mTransform = matrix ? new SkMatrix(*matrix) : nullptr;
|
2014-02-05 16:38:25 -08:00
|
|
|
}
|
|
|
|
|
2016-03-22 16:01:08 -07:00
|
|
|
SkMatrix* getTransform() {
|
|
|
|
return mTransform;
|
|
|
|
}
|
|
|
|
|
2014-02-19 16:47:32 +00:00
|
|
|
ANDROID_API void setPaint(const SkPaint* paint);
|
2014-02-05 16:38:25 -08:00
|
|
|
|
2015-12-16 14:27:20 -08:00
|
|
|
void apply();
|
2014-02-05 16:38:25 -08:00
|
|
|
|
2014-11-07 07:53:43 -08:00
|
|
|
Layer* backingLayer() {
|
2014-02-05 16:38:25 -08:00
|
|
|
return mLayer;
|
|
|
|
}
|
|
|
|
|
2015-12-16 14:27:20 -08:00
|
|
|
void detachSurfaceTexture();
|
2014-06-27 14:45:25 -07:00
|
|
|
|
2017-02-14 12:37:49 -08:00
|
|
|
void updateLayer(bool forceFilter, const float* textureTransform);
|
2016-07-22 12:13:32 -04:00
|
|
|
|
2017-01-19 15:37:02 -08:00
|
|
|
void destroyLayer();
|
|
|
|
|
|
|
|
Layer::Api getBackingLayerApi() {
|
|
|
|
return mLayerApi;
|
|
|
|
}
|
|
|
|
|
2014-02-05 16:38:25 -08:00
|
|
|
private:
|
2017-01-19 15:37:02 -08:00
|
|
|
RenderState& mRenderState;
|
|
|
|
|
2014-02-05 16:38:25 -08:00
|
|
|
// Generic properties
|
2017-01-19 15:37:02 -08:00
|
|
|
int mWidth = 0;
|
|
|
|
int mHeight = 0;
|
|
|
|
bool mBlend = false;
|
|
|
|
SkColorFilter* mColorFilter = nullptr;
|
|
|
|
int mAlpha = 255;
|
|
|
|
SkBlendMode mMode = SkBlendMode::kSrcOver;
|
2014-02-05 16:38:25 -08:00
|
|
|
sp<GLConsumer> mSurfaceTexture;
|
|
|
|
SkMatrix* mTransform;
|
2017-02-13 14:34:15 -08:00
|
|
|
bool mGLContextAttached;
|
2014-02-05 16:38:25 -08:00
|
|
|
bool mUpdateTexImage;
|
|
|
|
|
|
|
|
Layer* mLayer;
|
2017-01-19 15:37:02 -08:00
|
|
|
Layer::Api mLayerApi;
|
|
|
|
CreateLayerFn mCreateLayerFn;
|
2014-05-29 18:56:11 -07:00
|
|
|
|
2014-02-05 16:38:25 -08:00
|
|
|
void doUpdateTexImage();
|
2017-01-04 14:27:00 -05:00
|
|
|
void doUpdateVkTexImage();
|
2014-02-05 16:38:25 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace uirenderer */
|
|
|
|
} /* namespace android */
|