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.
|
|
|
|
*/
|
|
|
|
|
2010-10-27 18:57:51 -07:00
|
|
|
#ifndef ANDROID_HWUI_LAYER_H
|
|
|
|
#define ANDROID_HWUI_LAYER_H
|
2010-07-06 11:39:32 -07:00
|
|
|
|
2010-07-08 19:17:03 -07:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2010-07-06 11:39:32 -07:00
|
|
|
#include <GLES2/gl2.h>
|
|
|
|
|
2010-10-27 18:57:51 -07:00
|
|
|
#include <ui/Region.h>
|
|
|
|
|
2010-07-06 11:39:32 -07:00
|
|
|
#include <SkXfermode.h>
|
|
|
|
|
|
|
|
#include "Rect.h"
|
2011-01-06 10:04:23 -08:00
|
|
|
#include "SkiaColorFilter.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
|
|
|
|
class OpenGLRenderer;
|
|
|
|
class DisplayList;
|
|
|
|
|
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
|
|
|
*/
|
|
|
|
struct Layer {
|
2011-07-07 20:50:11 -07:00
|
|
|
Layer(const uint32_t layerWidth, const uint32_t layerHeight) {
|
2011-01-16 12:54:25 -08:00
|
|
|
mesh = NULL;
|
|
|
|
meshIndices = NULL;
|
|
|
|
meshElementCount = 0;
|
2011-07-07 20:50:11 -07:00
|
|
|
cacheable = true;
|
|
|
|
textureLayer = false;
|
2011-05-02 17:24:22 -07:00
|
|
|
renderTarget = GL_TEXTURE_2D;
|
2011-07-07 20:50:11 -07:00
|
|
|
texture.width = layerWidth;
|
|
|
|
texture.height = layerHeight;
|
|
|
|
colorFilter = NULL;
|
2012-03-02 13:37:47 -08:00
|
|
|
deferredUpdateScheduled = false;
|
|
|
|
renderer = NULL;
|
|
|
|
displayList = NULL;
|
2011-01-16 12:54:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
~Layer() {
|
|
|
|
if (mesh) delete mesh;
|
|
|
|
if (meshIndices) delete meshIndices;
|
2010-10-08 15:49:53 -07:00
|
|
|
}
|
|
|
|
|
2011-04-27 14:21:41 -07:00
|
|
|
/**
|
|
|
|
* Sets this layer's region to a rectangle. Computes the appropriate
|
|
|
|
* texture coordinates.
|
|
|
|
*/
|
|
|
|
void setRegionAsRect() {
|
|
|
|
const android::Rect& bounds = region.getBounds();
|
|
|
|
regionRect.set(bounds.leftTop().x, bounds.leftTop().y,
|
|
|
|
bounds.rightBottom().x, bounds.rightBottom().y);
|
|
|
|
|
2011-07-07 20:50:11 -07:00
|
|
|
const float texX = 1.0f / float(texture.width);
|
|
|
|
const float texY = 1.0f / float(texture.height);
|
2011-04-27 14:21:41 -07:00
|
|
|
const float height = layer.getHeight();
|
|
|
|
texCoords.set(
|
|
|
|
regionRect.left * texX, (height - regionRect.top) * texY,
|
|
|
|
regionRect.right * texX, (height - regionRect.bottom) * texY);
|
2011-07-07 20:50:11 -07:00
|
|
|
|
|
|
|
regionRect.translate(layer.left, layer.top);
|
|
|
|
}
|
|
|
|
|
2012-03-02 13:37:47 -08:00
|
|
|
void updateDeferred(OpenGLRenderer* renderer, DisplayList* displayList,
|
|
|
|
int left, int top, int right, int bottom) {
|
|
|
|
this->renderer = renderer;
|
|
|
|
this->displayList = displayList;
|
|
|
|
const Rect r(left, top, right, bottom);
|
|
|
|
dirtyRect.unionWith(r);
|
|
|
|
deferredUpdateScheduled = true;
|
|
|
|
}
|
|
|
|
|
2011-07-07 20:50:11 -07:00
|
|
|
inline uint32_t getWidth() {
|
|
|
|
return texture.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint32_t getHeight() {
|
|
|
|
return texture.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setSize(uint32_t width, uint32_t height) {
|
|
|
|
texture.width = width;
|
|
|
|
texture.height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void setBlend(bool blend) {
|
|
|
|
texture.blend = blend;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool isBlend() {
|
|
|
|
return texture.blend;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void setAlpha(int alpha) {
|
|
|
|
this->alpha = alpha;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void setAlpha(int alpha, SkXfermode::Mode mode) {
|
|
|
|
this->alpha = alpha;
|
|
|
|
this->mode = mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int getAlpha() {
|
|
|
|
return alpha;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline SkXfermode::Mode getMode() {
|
|
|
|
return mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void setEmpty(bool empty) {
|
|
|
|
this->empty = empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool isEmpty() {
|
|
|
|
return empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void setFbo(GLuint fbo) {
|
|
|
|
this->fbo = fbo;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline GLuint getFbo() {
|
|
|
|
return fbo;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline GLuint* getTexturePointer() {
|
|
|
|
return &texture.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline GLuint getTexture() {
|
|
|
|
return texture.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline GLenum getRenderTarget() {
|
|
|
|
return renderTarget;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void setRenderTarget(GLenum renderTarget) {
|
|
|
|
this->renderTarget = renderTarget;
|
|
|
|
}
|
|
|
|
|
2011-11-30 20:21:23 -08:00
|
|
|
void setWrap(GLenum wrap, bool bindTexture = false, bool force = false) {
|
|
|
|
texture.setWrap(wrap, bindTexture, force, renderTarget);
|
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) {
|
|
|
|
texture.setFilter(filter, bindTexture, force, renderTarget);
|
2011-07-07 20:50:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool isCacheable() {
|
|
|
|
return cacheable;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void setCacheable(bool cacheable) {
|
|
|
|
this->cacheable = cacheable;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool isTextureLayer() {
|
|
|
|
return textureLayer;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void setTextureLayer(bool textureLayer) {
|
|
|
|
this->textureLayer = textureLayer;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline SkiaColorFilter* getColorFilter() {
|
|
|
|
return colorFilter;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void setColorFilter(SkiaColorFilter* filter) {
|
|
|
|
colorFilter = filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void bindTexture() {
|
|
|
|
glBindTexture(renderTarget, texture.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void generateTexture() {
|
|
|
|
glGenTextures(1, &texture.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void deleteTexture() {
|
|
|
|
if (texture.id) glDeleteTextures(1, &texture.id);
|
|
|
|
}
|
|
|
|
|
2011-07-26 18:57:28 -07:00
|
|
|
inline void deleteFbo() {
|
|
|
|
if (fbo) glDeleteFramebuffers(1, &fbo);
|
|
|
|
}
|
|
|
|
|
2011-07-07 20:50:11 -07:00
|
|
|
inline void allocateTexture(GLenum format, GLenum storage) {
|
|
|
|
glTexImage2D(renderTarget, 0, format, getWidth(), getHeight(), 0, format, storage, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-07-06 11:39:32 -07:00
|
|
|
/**
|
2010-10-08 15:49:53 -07:00
|
|
|
* Bounds of the layer.
|
2010-07-06 11:39:32 -07:00
|
|
|
*/
|
|
|
|
Rect layer;
|
|
|
|
/**
|
2010-10-08 15:49:53 -07:00
|
|
|
* Texture coordinates of the layer.
|
2010-07-06 11:39:32 -07:00
|
|
|
*/
|
2010-10-08 15:49:53 -07:00
|
|
|
Rect texCoords;
|
|
|
|
|
2010-10-05 18:14:38 -07:00
|
|
|
/**
|
2011-07-07 20:50:11 -07:00
|
|
|
* Dirty region indicating what parts of the layer
|
|
|
|
* have been drawn.
|
2010-10-05 18:14:38 -07:00
|
|
|
*/
|
2011-07-07 20:50:11 -07:00
|
|
|
Region region;
|
2010-07-06 11:39:32 -07:00
|
|
|
/**
|
2011-07-07 20:50:11 -07:00
|
|
|
* If the region is a rectangle, coordinates of the
|
|
|
|
* region are stored here.
|
2010-07-06 11:39:32 -07:00
|
|
|
*/
|
2011-07-07 20:50:11 -07:00
|
|
|
Rect regionRect;
|
|
|
|
|
2010-07-06 11:39:32 -07:00
|
|
|
/**
|
2011-07-07 20:50:11 -07:00
|
|
|
* If the layer can be rendered as a mesh, this is non-null.
|
2010-07-06 11:39:32 -07:00
|
|
|
*/
|
2011-07-07 20:50:11 -07:00
|
|
|
TextureVertex* mesh;
|
|
|
|
uint16_t* meshIndices;
|
|
|
|
GLsizei meshElementCount;
|
|
|
|
|
2012-03-02 13:37:47 -08:00
|
|
|
/**
|
|
|
|
* Used for deferred updates.
|
|
|
|
*/
|
|
|
|
bool deferredUpdateScheduled;
|
|
|
|
OpenGLRenderer* renderer;
|
|
|
|
DisplayList* displayList;
|
|
|
|
Rect dirtyRect;
|
|
|
|
|
2011-07-07 20:50:11 -07:00
|
|
|
private:
|
2010-07-06 11:39:32 -07:00
|
|
|
/**
|
2011-07-07 20:50:11 -07:00
|
|
|
* Name of the FBO used to render the layer. If the name is 0
|
|
|
|
* this layer is not backed by an FBO, but a simple texture.
|
2010-07-06 11:39:32 -07:00
|
|
|
*/
|
2011-07-07 20:50:11 -07:00
|
|
|
GLuint fbo;
|
2010-10-08 15:49:53 -07:00
|
|
|
|
2010-09-22 22:48:20 -07:00
|
|
|
/**
|
2010-10-01 00:25:02 -07:00
|
|
|
* Indicates whether this layer has been used already.
|
2010-09-22 22:48:20 -07:00
|
|
|
*/
|
|
|
|
bool empty;
|
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;
|
|
|
|
|
2010-10-08 15:49:53 -07:00
|
|
|
/**
|
2011-07-07 20:50:11 -07:00
|
|
|
* If set to true (by default), the layer can be reused.
|
2010-10-08 15:49:53 -07:00
|
|
|
*/
|
2011-07-07 20:50:11 -07:00
|
|
|
bool cacheable;
|
2010-10-27 18:57:51 -07:00
|
|
|
|
|
|
|
/**
|
2011-07-07 20:50:11 -07:00
|
|
|
* When set to true, this layer must be treated as a texture
|
|
|
|
* layer.
|
2010-10-27 18:57:51 -07:00
|
|
|
*/
|
2011-07-07 20:50:11 -07:00
|
|
|
bool textureLayer;
|
|
|
|
|
2011-03-18 14:34:03 -07:00
|
|
|
/**
|
2011-07-07 20:50:11 -07:00
|
|
|
* Indicates the render target.
|
2011-03-18 14:34:03 -07:00
|
|
|
*/
|
2011-07-07 20:50:11 -07:00
|
|
|
GLenum renderTarget;
|
2011-01-06 10:04:23 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Color filter used to draw this layer. Optional.
|
|
|
|
*/
|
|
|
|
SkiaColorFilter* colorFilter;
|
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
|
|
|
*/
|
2011-07-07 20:50:11 -07:00
|
|
|
int alpha;
|
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
|
|
|
*/
|
2011-07-07 20:50:11 -07:00
|
|
|
SkXfermode::Mode 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;
|
|
|
|
|
2010-07-06 11:39:32 -07:00
|
|
|
}; // struct Layer
|
|
|
|
|
|
|
|
}; // namespace uirenderer
|
|
|
|
}; // namespace android
|
|
|
|
|
2010-10-27 18:57:51 -07:00
|
|
|
#endif // ANDROID_HWUI_LAYER_H
|