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
|
|
|
|
2013-12-10 12:28:58 -05:00
|
|
|
#include <cutils/compiler.h>
|
2010-07-08 19:17:03 -07:00
|
|
|
#include <sys/types.h>
|
2014-04-04 16:20:08 -07:00
|
|
|
#include <utils/StrongPointer.h>
|
2014-11-01 18:37:39 -07:00
|
|
|
#include <utils/RefBase.h>
|
2014-12-22 17:16:56 -08:00
|
|
|
#include <memory>
|
2010-07-08 19:17:03 -07:00
|
|
|
|
2010-07-06 11:39:32 -07:00
|
|
|
#include <GLES2/gl2.h>
|
2015-11-10 12:19:17 -08:00
|
|
|
#include <GpuMemoryTracker.h>
|
2010-07-06 11:39:32 -07:00
|
|
|
|
2010-10-27 18:57:51 -07:00
|
|
|
#include <ui/Region.h>
|
|
|
|
|
2012-08-14 16:44:52 -04:00
|
|
|
#include <SkPaint.h>
|
2016-10-07 15:59:20 -04:00
|
|
|
#include <SkBlendMode.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
|
|
|
#include "Rect.h"
|
2013-02-06 16:51:04 -08:00
|
|
|
#include "RenderBuffer.h"
|
2011-07-07 20:50:11 -07:00
|
|
|
#include "Texture.h"
|
2011-01-16 12:54:25 -08:00
|
|
|
#include "Vertex.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
|
|
|
|
2012-03-02 13:37:47 -08:00
|
|
|
// Forward declarations
|
2013-06-04 18:00:09 -07:00
|
|
|
class Caches;
|
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
|
|
|
/**
|
2010-10-05 18:14:38 -07:00
|
|
|
* A layer has dimensions and is backed by an OpenGL texture or FBO.
|
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:
|
2014-09-10 13:04:31 -07:00
|
|
|
// layer lifecycle, controlled from outside
|
2015-08-20 15:14:06 -07:00
|
|
|
enum class State {
|
|
|
|
Uncached = 0,
|
|
|
|
InCache = 1,
|
|
|
|
FailedToCache = 2,
|
|
|
|
RemovedFromCache = 3,
|
|
|
|
DeletedFromCache = 4,
|
|
|
|
InGarbageList = 5,
|
2014-09-10 13:04:31 -07:00
|
|
|
};
|
|
|
|
State state; // public for logging/debugging purposes
|
|
|
|
|
2016-07-06 16:10:09 -07:00
|
|
|
Layer(RenderState& renderState, uint32_t layerWidth, uint32_t layerHeight);
|
2012-09-05 11:40:29 -07:00
|
|
|
~Layer();
|
2010-10-08 15:49:53 -07:00
|
|
|
|
2013-02-06 16:51:04 -08:00
|
|
|
inline uint32_t getWidth() const {
|
2015-11-10 12:19:17 -08:00
|
|
|
return texture.mWidth;
|
2011-07-07 20:50:11 -07:00
|
|
|
}
|
|
|
|
|
2013-02-06 16:51:04 -08:00
|
|
|
inline uint32_t getHeight() const {
|
2015-11-10 12:19:17 -08:00
|
|
|
return texture.mHeight;
|
2011-07-07 20:50:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void setSize(uint32_t width, uint32_t height) {
|
2016-10-25 15:21:50 -07:00
|
|
|
texture.updateSize(width, height, texture.internalFormat(), texture.format(),
|
|
|
|
texture.target());
|
2011-07-07 20:50:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void setBlend(bool blend) {
|
|
|
|
texture.blend = blend;
|
|
|
|
}
|
|
|
|
|
2013-02-06 16:51:04 -08:00
|
|
|
inline bool isBlend() const {
|
2011-07-07 20:50:11 -07:00
|
|
|
return texture.blend;
|
|
|
|
}
|
|
|
|
|
2014-02-25 18:50:17 -08:00
|
|
|
inline void setForceFilter(bool forceFilter) {
|
|
|
|
this->forceFilter = forceFilter;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool getForceFilter() const {
|
|
|
|
return forceFilter;
|
|
|
|
}
|
|
|
|
|
2011-07-07 20:50:11 -07:00
|
|
|
inline void setAlpha(int alpha) {
|
|
|
|
this->alpha = alpha;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-02-06 16:51:04 -08:00
|
|
|
inline int getAlpha() const {
|
2011-07-07 20:50:11 -07:00
|
|
|
return alpha;
|
|
|
|
}
|
|
|
|
|
2016-10-07 15:59:20 -04:00
|
|
|
inline SkBlendMode getMode() const {
|
2011-07-07 20:50:11 -07:00
|
|
|
return mode;
|
|
|
|
}
|
|
|
|
|
2015-02-19 09:51:53 -08:00
|
|
|
inline GLuint getTextureId() const {
|
2015-11-10 12:19:17 -08:00
|
|
|
return texture.id();
|
2011-07-07 20:50:11 -07:00
|
|
|
}
|
2015-02-19 09:51:53 -08:00
|
|
|
|
|
|
|
inline Texture& getTexture() {
|
|
|
|
return texture;
|
|
|
|
}
|
2011-07-07 20:50:11 -07:00
|
|
|
|
2013-02-06 16:51:04 -08:00
|
|
|
inline GLenum getRenderTarget() const {
|
2016-10-25 15:21:50 -07:00
|
|
|
return texture.target();
|
2011-07-07 20:50:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void setRenderTarget(GLenum renderTarget) {
|
2016-10-25 15:21:50 -07:00
|
|
|
texture.mTarget = renderTarget;
|
2011-07-07 20:50:11 -07:00
|
|
|
}
|
|
|
|
|
2016-03-22 16:01:08 -07:00
|
|
|
inline bool isRenderable() const {
|
2016-10-25 15:21:50 -07:00
|
|
|
return texture.target() != GL_NONE;
|
2016-03-22 16:01:08 -07:00
|
|
|
}
|
|
|
|
|
2011-11-30 20:21:23 -08:00
|
|
|
void setWrap(GLenum wrap, bool bindTexture = false, bool force = false) {
|
2016-10-25 15:21:50 -07:00
|
|
|
texture.setWrap(wrap, bindTexture, force);
|
2011-07-07 20:50:11 -07:00
|
|
|
}
|
|
|
|
|
2011-11-30 20:21:23 -08:00
|
|
|
void setFilter(GLenum filter, bool bindTexture = false, bool force = false) {
|
2016-10-25 15:21:50 -07:00
|
|
|
texture.setFilter(filter, bindTexture, force);
|
2011-07-07 20:50:11 -07:00
|
|
|
}
|
|
|
|
|
2013-12-10 12:28:58 -05:00
|
|
|
inline SkColorFilter* getColorFilter() const {
|
2011-07-07 20:50:11 -07:00
|
|
|
return colorFilter;
|
|
|
|
}
|
|
|
|
|
2016-07-06 16:10:09 -07:00
|
|
|
void setColorFilter(SkColorFilter* filter);
|
2013-01-18 16:42:51 -08:00
|
|
|
|
2013-06-04 18:00:09 -07:00
|
|
|
void bindTexture() const;
|
|
|
|
void generateTexture();
|
2012-09-25 12:17:14 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* When the caller frees the texture itself, the caller
|
|
|
|
* must call this method to tell this layer that it lost
|
|
|
|
* the texture.
|
|
|
|
*/
|
2016-07-06 16:10:09 -07:00
|
|
|
void clearTexture();
|
2013-01-18 16:42:51 -08:00
|
|
|
|
2011-07-07 20:50:11 -07:00
|
|
|
inline mat4& getTexTransform() {
|
|
|
|
return texTransform;
|
2011-04-27 14:21:41 -07:00
|
|
|
}
|
|
|
|
|
2011-08-16 13:55:02 -07:00
|
|
|
inline mat4& getTransform() {
|
|
|
|
return transform;
|
|
|
|
}
|
|
|
|
|
2014-10-31 14:49:06 -07:00
|
|
|
/**
|
|
|
|
* Posts a decStrong call to the appropriate thread.
|
|
|
|
* Thread-safe.
|
|
|
|
*/
|
|
|
|
void postDecStrong();
|
|
|
|
|
2015-01-29 10:17:57 -08:00
|
|
|
/**
|
|
|
|
* Lost the GL context but the layer is still around, mark it invalid internally
|
|
|
|
* so the dtor knows not to do any GL work
|
|
|
|
*/
|
|
|
|
void onGlContextLost();
|
|
|
|
|
2011-07-07 20:50:11 -07:00
|
|
|
private:
|
2013-06-04 18:00:09 -07:00
|
|
|
Caches& caches;
|
|
|
|
|
2014-06-23 13:13:08 -07:00
|
|
|
RenderState& renderState;
|
|
|
|
|
2010-10-08 15:49:53 -07:00
|
|
|
/**
|
2011-07-07 20:50:11 -07:00
|
|
|
* The texture backing this layer.
|
2010-10-08 15:49:53 -07:00
|
|
|
*/
|
2011-07-07 20:50:11 -07:00
|
|
|
Texture texture;
|
|
|
|
|
2011-01-06 10:04:23 -08:00
|
|
|
/**
|
|
|
|
* Color filter used to draw this layer. Optional.
|
|
|
|
*/
|
2015-03-02 17:50:26 -08:00
|
|
|
SkColorFilter* colorFilter = nullptr;
|
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
|
|
|
*/
|
2015-03-02 17:50:26 -08:00
|
|
|
int alpha = 255;
|
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
|
|
|
*/
|
2016-10-07 15:59:20 -04:00
|
|
|
SkBlendMode mode = SkBlendMode::kSrcOver;
|
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;
|
|
|
|
|
2010-07-06 11:39:32 -07:00
|
|
|
}; // struct Layer
|
|
|
|
|
|
|
|
}; // namespace uirenderer
|
|
|
|
}; // namespace android
|