2010-07-06 11:39:32 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 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
|
2010-07-06 11:39:32 -07:00
|
|
|
|
2015-11-10 12:19:17 -08:00
|
|
|
#include <GpuMemoryTracker.h>
|
2017-11-03 10:12:19 -07:00
|
|
|
#include <utils/RefBase.h>
|
2010-07-06 11:39:32 -07:00
|
|
|
|
2018-04-20 16:13:31 -04:00
|
|
|
#include <SkColorFilter.h>
|
|
|
|
#include <SkColorSpace.h>
|
2016-10-07 15:59:20 -04:00
|
|
|
#include <SkBlendMode.h>
|
2017-11-03 10:12:19 -07:00
|
|
|
#include <SkPaint.h>
|
2010-07-06 11:39:32 -07:00
|
|
|
|
2013-12-10 12:28:58 -05:00
|
|
|
#include "Matrix.h"
|
2010-07-06 11:39:32 -07:00
|
|
|
|
|
|
|
namespace android {
|
|
|
|
namespace uirenderer {
|
|
|
|
|
2010-10-08 15:49:53 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Layers
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2010-07-06 11:39:32 -07:00
|
|
|
|
2014-06-23 13:13:08 -07:00
|
|
|
class RenderState;
|
2012-03-02 13:37:47 -08:00
|
|
|
|
2010-07-06 11:39:32 -07:00
|
|
|
/**
|
2017-01-09 14:15:41 -05:00
|
|
|
* A layer has dimensions and is backed by a backend specific texture or framebuffer.
|
2010-07-06 11:39:32 -07:00
|
|
|
*/
|
2015-11-10 12:19:17 -08:00
|
|
|
class Layer : public VirtualLightRefBase, GpuMemoryTracker {
|
2014-01-02 16:46:18 -08:00
|
|
|
public:
|
2017-01-09 14:15:41 -05:00
|
|
|
enum class Api {
|
|
|
|
OpenGL = 0,
|
|
|
|
Vulkan = 1,
|
2014-09-10 13:04:31 -07:00
|
|
|
};
|
|
|
|
|
2017-11-03 10:12:19 -07:00
|
|
|
Api getApi() const { return mApi; }
|
2017-01-09 14:15:41 -05:00
|
|
|
|
2012-09-05 11:40:29 -07:00
|
|
|
~Layer();
|
2010-10-08 15:49:53 -07:00
|
|
|
|
2017-01-09 14:15:41 -05:00
|
|
|
virtual uint32_t getWidth() const = 0;
|
2011-07-07 20:50:11 -07:00
|
|
|
|
2017-01-09 14:15:41 -05:00
|
|
|
virtual uint32_t getHeight() const = 0;
|
2011-07-07 20:50:11 -07:00
|
|
|
|
2017-01-09 14:15:41 -05:00
|
|
|
virtual void setSize(uint32_t width, uint32_t height) = 0;
|
2011-07-07 20:50:11 -07:00
|
|
|
|
2017-01-09 14:15:41 -05:00
|
|
|
virtual void setBlend(bool blend) = 0;
|
2011-07-07 20:50:11 -07:00
|
|
|
|
2017-01-09 14:15:41 -05:00
|
|
|
virtual bool isBlend() const = 0;
|
2011-07-07 20:50:11 -07:00
|
|
|
|
2017-11-03 10:12:19 -07:00
|
|
|
inline void setForceFilter(bool forceFilter) { this->forceFilter = forceFilter; }
|
2014-02-25 18:50:17 -08:00
|
|
|
|
2017-11-03 10:12:19 -07:00
|
|
|
inline bool getForceFilter() const { return forceFilter; }
|
2014-02-25 18:50:17 -08:00
|
|
|
|
2017-11-03 10:12:19 -07:00
|
|
|
inline void setAlpha(int alpha) { this->alpha = alpha; }
|
2011-07-07 20:50:11 -07:00
|
|
|
|
2016-10-07 15:59:20 -04:00
|
|
|
inline void setAlpha(int alpha, SkBlendMode mode) {
|
2011-07-07 20:50:11 -07:00
|
|
|
this->alpha = alpha;
|
|
|
|
this->mode = mode;
|
|
|
|
}
|
|
|
|
|
2017-11-03 10:12:19 -07:00
|
|
|
inline int getAlpha() const { return alpha; }
|
2011-07-07 20:50:11 -07:00
|
|
|
|
2017-11-03 10:12:19 -07:00
|
|
|
inline SkBlendMode getMode() const { return mode; }
|
2011-07-07 20:50:11 -07:00
|
|
|
|
2018-04-20 16:13:31 -04:00
|
|
|
inline SkColorFilter* getColorFilter() const { return mColorFilter.get(); }
|
2011-07-07 20:50:11 -07:00
|
|
|
|
2018-04-20 16:13:31 -04:00
|
|
|
void setColorFilter(sk_sp<SkColorFilter> filter);
|
|
|
|
|
|
|
|
void setDataSpace(android_dataspace dataspace);
|
|
|
|
|
|
|
|
void setColorSpace(sk_sp<SkColorSpace> colorSpace);
|
|
|
|
|
|
|
|
inline sk_sp<SkColorFilter> getColorSpaceWithFilter() const { return mColorSpaceWithFilter; }
|
2013-01-18 16:42:51 -08:00
|
|
|
|
2017-11-03 10:12:19 -07:00
|
|
|
inline mat4& getTexTransform() { return texTransform; }
|
2011-04-27 14:21:41 -07:00
|
|
|
|
2017-11-03 10:12:19 -07:00
|
|
|
inline mat4& getTransform() { return transform; }
|
2011-08-16 13:55:02 -07:00
|
|
|
|
2014-10-31 14:49:06 -07:00
|
|
|
/**
|
|
|
|
* Posts a decStrong call to the appropriate thread.
|
|
|
|
* Thread-safe.
|
|
|
|
*/
|
|
|
|
void postDecStrong();
|
|
|
|
|
2017-01-09 14:15:41 -05:00
|
|
|
protected:
|
2018-04-20 16:13:31 -04:00
|
|
|
Layer(RenderState& renderState, Api api, sk_sp<SkColorFilter>, int alpha,
|
2017-11-03 10:12:19 -07:00
|
|
|
SkBlendMode mode);
|
2013-06-04 18:00:09 -07:00
|
|
|
|
2017-01-09 14:15:41 -05:00
|
|
|
RenderState& mRenderState;
|
2014-06-23 13:13:08 -07:00
|
|
|
|
2017-01-09 14:15:41 -05:00
|
|
|
private:
|
2018-04-20 16:13:31 -04:00
|
|
|
void buildColorSpaceWithFilter();
|
|
|
|
|
2017-01-09 14:15:41 -05:00
|
|
|
Api mApi;
|
2011-07-07 20:50:11 -07:00
|
|
|
|
2011-01-06 10:04:23 -08:00
|
|
|
/**
|
|
|
|
* Color filter used to draw this layer. Optional.
|
|
|
|
*/
|
2018-04-20 16:13:31 -04:00
|
|
|
sk_sp<SkColorFilter> mColorFilter;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Colorspace of the contents of the layer. Optional.
|
|
|
|
*/
|
|
|
|
android_dataspace mCurrentDataspace = HAL_DATASPACE_UNKNOWN;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A color filter that is the combination of the mColorFilter and mColorSpace. Optional.
|
|
|
|
*/
|
|
|
|
sk_sp<SkColorFilter> mColorSpaceWithFilter;
|
2011-01-16 12:54:25 -08:00
|
|
|
|
2014-02-25 18:50:17 -08:00
|
|
|
/**
|
|
|
|
* Indicates raster data backing the layer is scaled, requiring filtration.
|
|
|
|
*/
|
2015-03-02 17:50:26 -08:00
|
|
|
bool forceFilter = false;
|
2014-02-25 18:50:17 -08:00
|
|
|
|
2011-01-16 12:54:25 -08:00
|
|
|
/**
|
2011-07-07 20:50:11 -07:00
|
|
|
* Opacity of the layer.
|
New widget: TextureView
Bug #4343984
TextureView can be used to render media content (video, OpenGL,
RenderScript) inside a View.
The key difference with SurfaceView is that TextureView does
not create a new Surface. This gives the ability to seamlessly
transform, animate, fade, etc. a TextureView, which was hard
if not impossible to do with a SurfaceView.
A TextureView also interacts perfectly with ScrollView,
ListView, etc. It allows application to embed media content
in a much more flexible way than before.
For instance, to render the camera preview at 50% opacity,
all you need to do is the following:
mTextureView.setAlpha(0.5f);
Camera c = Camera.open();
c.setPreviewTexture(mTextureView.getSurfaceTexture());
c.startPreview();
TextureView uses a SurfaceTexture to get the job done. More
APIs are required to make it easy to create OpenGL contexts
for a TextureView. It can currently be done with a bit of
JNI code.
Change-Id: Iaa7953097ab5beb8437bcbbfa03b2df5b7f80cd7
2011-04-28 18:40:04 -07:00
|
|
|
*/
|
2017-01-19 15:37:02 -08:00
|
|
|
int alpha;
|
2014-02-25 18:50:17 -08:00
|
|
|
|
New widget: TextureView
Bug #4343984
TextureView can be used to render media content (video, OpenGL,
RenderScript) inside a View.
The key difference with SurfaceView is that TextureView does
not create a new Surface. This gives the ability to seamlessly
transform, animate, fade, etc. a TextureView, which was hard
if not impossible to do with a SurfaceView.
A TextureView also interacts perfectly with ScrollView,
ListView, etc. It allows application to embed media content
in a much more flexible way than before.
For instance, to render the camera preview at 50% opacity,
all you need to do is the following:
mTextureView.setAlpha(0.5f);
Camera c = Camera.open();
c.setPreviewTexture(mTextureView.getSurfaceTexture());
c.startPreview();
TextureView uses a SurfaceTexture to get the job done. More
APIs are required to make it easy to create OpenGL contexts
for a TextureView. It can currently be done with a bit of
JNI code.
Change-Id: Iaa7953097ab5beb8437bcbbfa03b2df5b7f80cd7
2011-04-28 18:40:04 -07:00
|
|
|
/**
|
2011-07-07 20:50:11 -07:00
|
|
|
* Blending mode of the layer.
|
New widget: TextureView
Bug #4343984
TextureView can be used to render media content (video, OpenGL,
RenderScript) inside a View.
The key difference with SurfaceView is that TextureView does
not create a new Surface. This gives the ability to seamlessly
transform, animate, fade, etc. a TextureView, which was hard
if not impossible to do with a SurfaceView.
A TextureView also interacts perfectly with ScrollView,
ListView, etc. It allows application to embed media content
in a much more flexible way than before.
For instance, to render the camera preview at 50% opacity,
all you need to do is the following:
mTextureView.setAlpha(0.5f);
Camera c = Camera.open();
c.setPreviewTexture(mTextureView.getSurfaceTexture());
c.startPreview();
TextureView uses a SurfaceTexture to get the job done. More
APIs are required to make it easy to create OpenGL contexts
for a TextureView. It can currently be done with a bit of
JNI code.
Change-Id: Iaa7953097ab5beb8437bcbbfa03b2df5b7f80cd7
2011-04-28 18:40:04 -07:00
|
|
|
*/
|
2017-01-19 15:37:02 -08:00
|
|
|
SkBlendMode mode;
|
New widget: TextureView
Bug #4343984
TextureView can be used to render media content (video, OpenGL,
RenderScript) inside a View.
The key difference with SurfaceView is that TextureView does
not create a new Surface. This gives the ability to seamlessly
transform, animate, fade, etc. a TextureView, which was hard
if not impossible to do with a SurfaceView.
A TextureView also interacts perfectly with ScrollView,
ListView, etc. It allows application to embed media content
in a much more flexible way than before.
For instance, to render the camera preview at 50% opacity,
all you need to do is the following:
mTextureView.setAlpha(0.5f);
Camera c = Camera.open();
c.setPreviewTexture(mTextureView.getSurfaceTexture());
c.startPreview();
TextureView uses a SurfaceTexture to get the job done. More
APIs are required to make it easy to create OpenGL contexts
for a TextureView. It can currently be done with a bit of
JNI code.
Change-Id: Iaa7953097ab5beb8437bcbbfa03b2df5b7f80cd7
2011-04-28 18:40:04 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Optional texture coordinates transform.
|
|
|
|
*/
|
|
|
|
mat4 texTransform;
|
2011-05-02 17:24:22 -07:00
|
|
|
|
2011-08-16 13:55:02 -07:00
|
|
|
/**
|
|
|
|
* Optional transform.
|
|
|
|
*/
|
|
|
|
mat4 transform;
|
|
|
|
|
2017-11-03 10:12:19 -07:00
|
|
|
}; // struct Layer
|
2010-07-06 11:39:32 -07:00
|
|
|
|
2017-11-03 10:12:19 -07:00
|
|
|
}; // namespace uirenderer
|
|
|
|
}; // namespace android
|