2010-10-22 18:59:26 -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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LOG_TAG "OpenGLRenderer"
|
|
|
|
|
2010-11-10 11:59:15 -08:00
|
|
|
#include <utils/Log.h>
|
2011-03-24 10:51:31 -07:00
|
|
|
#include <utils/String8.h>
|
2010-11-10 11:59:15 -08:00
|
|
|
|
2010-10-22 18:59:26 -07:00
|
|
|
#include "Caches.h"
|
2012-03-05 13:44:35 -08:00
|
|
|
#include "DisplayListRenderer.h"
|
2010-11-10 19:01:29 -08:00
|
|
|
#include "Properties.h"
|
2011-02-02 20:28:09 -08:00
|
|
|
#include "LayerRenderer.h"
|
2014-02-14 13:13:41 -08:00
|
|
|
#include "ShadowTessellator.h"
|
2010-10-22 18:59:26 -07:00
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
|
|
|
#ifdef USE_OPENGL_RENDERER
|
|
|
|
using namespace uirenderer;
|
|
|
|
ANDROID_SINGLETON_STATIC_INSTANCE(Caches);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace uirenderer {
|
|
|
|
|
2011-07-18 15:00:43 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Macros
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#if DEBUG_CACHE_FLUSH
|
2011-12-20 16:23:08 +00:00
|
|
|
#define FLUSH_LOGD(...) ALOGD(__VA_ARGS__)
|
2011-07-18 15:00:43 -07:00
|
|
|
#else
|
|
|
|
#define FLUSH_LOGD(...)
|
|
|
|
#endif
|
|
|
|
|
2010-10-22 18:59:26 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Constructors/destructor
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-06-04 18:00:09 -07:00
|
|
|
Caches::Caches(): Singleton<Caches>(),
|
|
|
|
mExtensions(Extensions::getInstance()), mInitialized(false) {
|
2011-11-09 20:10:18 -08:00
|
|
|
init();
|
2012-07-13 18:25:35 -07:00
|
|
|
initFont();
|
2012-05-12 16:18:58 -07:00
|
|
|
initConstraints();
|
2012-08-06 14:51:10 -07:00
|
|
|
initProperties();
|
2013-05-09 11:50:12 -07:00
|
|
|
initStaticProperties();
|
2013-03-01 14:31:04 -08:00
|
|
|
initExtensions();
|
2013-12-15 17:10:19 -08:00
|
|
|
initTempProperties();
|
2010-11-10 19:01:29 -08:00
|
|
|
|
|
|
|
mDebugLevel = readDebugLevel();
|
2011-12-20 16:23:08 +00:00
|
|
|
ALOGD("Enabling debug mode %d", mDebugLevel);
|
2010-10-22 18:59:26 -07:00
|
|
|
}
|
|
|
|
|
Pack preloaded framework assets in a texture atlas
When the Android runtime starts, the system preloads a series of assets
in the Zygote process. These assets are shared across all processes.
Unfortunately, each one of these assets is later uploaded in its own
OpenGL texture, once per process. This wastes memory and generates
unnecessary OpenGL state changes.
This CL introduces an asset server that provides an atlas to all processes.
Note: bitmaps used by skia shaders are *not* sampled from the atlas.
It's an uncommon use case and would require extra texture transforms
in the GL shaders.
WHAT IS THE ASSETS ATLAS
The "assets atlas" is a single, shareable graphic buffer that contains
all the system's preloaded bitmap drawables (this includes 9-patches.)
The atlas is made of two distinct objects: the graphic buffer that
contains the actual pixels and the map which indicates where each
preloaded bitmap can be found in the atlas (essentially a pair of
x and y coordinates.)
HOW IS THE ASSETS ATLAS GENERATED
Because we need to support a wide variety of devices and because it
is easy to change the list of preloaded drawables, the atlas is
generated at runtime, during the startup phase of the system process.
There are several steps that lead to the atlas generation:
1. If the device is booting for the first time, or if the device was
updated, we need to find the best atlas configuration. To do so,
the atlas service tries a number of width, height and algorithm
variations that allows us to pack as many assets as possible while
using as little memory as possible. Once a best configuration is found,
it gets written to disk in /data/system/framework_atlas
2. Given a best configuration (algorithm variant, dimensions and
number of bitmaps that can be packed in the atlas), the atlas service
packs all the preloaded bitmaps into a single graphic buffer object.
3. The packing is done using Skia in a temporary native bitmap. The
Skia bitmap is then copied into the graphic buffer using OpenGL ES
to benefit from texture swizzling.
HOW PROCESSES USE THE ATLAS
Whenever a process' hardware renderer initializes its EGL context,
it queries the atlas service for the graphic buffer and the map.
It is important to remember that both the context and the map will
be valid for the lifetime of the hardware renderer (if the system
process goes down, all apps get killed as well.)
Every time the hardware renderer needs to render a bitmap, it first
checks whether the bitmap can be found in the assets atlas. When
the bitmap is part of the atlas, texture coordinates are remapped
appropriately before rendering.
Change-Id: I8eaecf53e7f6a33d90da3d0047c5ceec89ea3af0
2013-04-17 18:54:38 -07:00
|
|
|
bool Caches::init() {
|
|
|
|
if (mInitialized) return false;
|
2011-11-09 20:10:18 -08:00
|
|
|
|
|
|
|
glGenBuffers(1, &meshBuffer);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, meshBuffer);
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, sizeof(gMeshVertices), gMeshVertices, GL_STATIC_DRAW);
|
|
|
|
|
|
|
|
mCurrentBuffer = meshBuffer;
|
2011-12-13 13:11:32 -08:00
|
|
|
mCurrentIndicesBuffer = 0;
|
2011-12-12 20:35:21 -08:00
|
|
|
mCurrentPositionPointer = this;
|
2012-09-25 12:00:29 -07:00
|
|
|
mCurrentPositionStride = 0;
|
2011-12-12 20:35:21 -08:00
|
|
|
mCurrentTexCoordsPointer = this;
|
2013-04-08 19:40:31 -07:00
|
|
|
mCurrentPixelBuffer = 0;
|
2011-12-12 20:35:21 -08:00
|
|
|
|
2011-12-13 13:11:32 -08:00
|
|
|
mTexCoordsArrayEnabled = false;
|
|
|
|
|
2012-07-13 18:25:35 -07:00
|
|
|
glDisable(GL_SCISSOR_TEST);
|
2012-07-13 15:28:31 -07:00
|
|
|
scissorEnabled = false;
|
2011-12-14 19:23:32 -08:00
|
|
|
mScissorX = mScissorY = mScissorWidth = mScissorHeight = 0;
|
|
|
|
|
2011-12-13 14:55:06 -08:00
|
|
|
glActiveTexture(gTextureUnits[0]);
|
|
|
|
mTextureUnit = 0;
|
|
|
|
|
2011-11-09 20:10:18 -08:00
|
|
|
mRegionMesh = NULL;
|
Pack preloaded framework assets in a texture atlas
When the Android runtime starts, the system preloads a series of assets
in the Zygote process. These assets are shared across all processes.
Unfortunately, each one of these assets is later uploaded in its own
OpenGL texture, once per process. This wastes memory and generates
unnecessary OpenGL state changes.
This CL introduces an asset server that provides an atlas to all processes.
Note: bitmaps used by skia shaders are *not* sampled from the atlas.
It's an uncommon use case and would require extra texture transforms
in the GL shaders.
WHAT IS THE ASSETS ATLAS
The "assets atlas" is a single, shareable graphic buffer that contains
all the system's preloaded bitmap drawables (this includes 9-patches.)
The atlas is made of two distinct objects: the graphic buffer that
contains the actual pixels and the map which indicates where each
preloaded bitmap can be found in the atlas (essentially a pair of
x and y coordinates.)
HOW IS THE ASSETS ATLAS GENERATED
Because we need to support a wide variety of devices and because it
is easy to change the list of preloaded drawables, the atlas is
generated at runtime, during the startup phase of the system process.
There are several steps that lead to the atlas generation:
1. If the device is booting for the first time, or if the device was
updated, we need to find the best atlas configuration. To do so,
the atlas service tries a number of width, height and algorithm
variations that allows us to pack as many assets as possible while
using as little memory as possible. Once a best configuration is found,
it gets written to disk in /data/system/framework_atlas
2. Given a best configuration (algorithm variant, dimensions and
number of bitmaps that can be packed in the atlas), the atlas service
packs all the preloaded bitmaps into a single graphic buffer object.
3. The packing is done using Skia in a temporary native bitmap. The
Skia bitmap is then copied into the graphic buffer using OpenGL ES
to benefit from texture swizzling.
HOW PROCESSES USE THE ATLAS
Whenever a process' hardware renderer initializes its EGL context,
it queries the atlas service for the graphic buffer and the map.
It is important to remember that both the context and the map will
be valid for the lifetime of the hardware renderer (if the system
process goes down, all apps get killed as well.)
Every time the hardware renderer needs to render a bitmap, it first
checks whether the bitmap can be found in the assets atlas. When
the bitmap is part of the atlas, texture coordinates are remapped
appropriately before rendering.
Change-Id: I8eaecf53e7f6a33d90da3d0047c5ceec89ea3af0
2013-04-17 18:54:38 -07:00
|
|
|
mMeshIndices = 0;
|
2014-02-14 13:13:41 -08:00
|
|
|
mShadowStripsIndices = 0;
|
2011-11-09 20:10:18 -08:00
|
|
|
blend = false;
|
|
|
|
lastSrcMode = GL_ZERO;
|
|
|
|
lastDstMode = GL_ZERO;
|
|
|
|
currentProgram = NULL;
|
|
|
|
|
2012-09-27 17:55:46 -07:00
|
|
|
mFunctorsCount = 0;
|
|
|
|
|
2013-02-06 15:29:46 -08:00
|
|
|
debugLayersUpdates = false;
|
|
|
|
debugOverdraw = false;
|
2013-02-25 14:15:37 -08:00
|
|
|
debugStencilClip = kStencilHide;
|
2013-02-06 15:29:46 -08:00
|
|
|
|
Pack preloaded framework assets in a texture atlas
When the Android runtime starts, the system preloads a series of assets
in the Zygote process. These assets are shared across all processes.
Unfortunately, each one of these assets is later uploaded in its own
OpenGL texture, once per process. This wastes memory and generates
unnecessary OpenGL state changes.
This CL introduces an asset server that provides an atlas to all processes.
Note: bitmaps used by skia shaders are *not* sampled from the atlas.
It's an uncommon use case and would require extra texture transforms
in the GL shaders.
WHAT IS THE ASSETS ATLAS
The "assets atlas" is a single, shareable graphic buffer that contains
all the system's preloaded bitmap drawables (this includes 9-patches.)
The atlas is made of two distinct objects: the graphic buffer that
contains the actual pixels and the map which indicates where each
preloaded bitmap can be found in the atlas (essentially a pair of
x and y coordinates.)
HOW IS THE ASSETS ATLAS GENERATED
Because we need to support a wide variety of devices and because it
is easy to change the list of preloaded drawables, the atlas is
generated at runtime, during the startup phase of the system process.
There are several steps that lead to the atlas generation:
1. If the device is booting for the first time, or if the device was
updated, we need to find the best atlas configuration. To do so,
the atlas service tries a number of width, height and algorithm
variations that allows us to pack as many assets as possible while
using as little memory as possible. Once a best configuration is found,
it gets written to disk in /data/system/framework_atlas
2. Given a best configuration (algorithm variant, dimensions and
number of bitmaps that can be packed in the atlas), the atlas service
packs all the preloaded bitmaps into a single graphic buffer object.
3. The packing is done using Skia in a temporary native bitmap. The
Skia bitmap is then copied into the graphic buffer using OpenGL ES
to benefit from texture swizzling.
HOW PROCESSES USE THE ATLAS
Whenever a process' hardware renderer initializes its EGL context,
it queries the atlas service for the graphic buffer and the map.
It is important to remember that both the context and the map will
be valid for the lifetime of the hardware renderer (if the system
process goes down, all apps get killed as well.)
Every time the hardware renderer needs to render a bitmap, it first
checks whether the bitmap can be found in the assets atlas. When
the bitmap is part of the atlas, texture coordinates are remapped
appropriately before rendering.
Change-Id: I8eaecf53e7f6a33d90da3d0047c5ceec89ea3af0
2013-04-17 18:54:38 -07:00
|
|
|
patchCache.init(*this);
|
|
|
|
|
2011-11-09 20:10:18 -08:00
|
|
|
mInitialized = true;
|
Pack preloaded framework assets in a texture atlas
When the Android runtime starts, the system preloads a series of assets
in the Zygote process. These assets are shared across all processes.
Unfortunately, each one of these assets is later uploaded in its own
OpenGL texture, once per process. This wastes memory and generates
unnecessary OpenGL state changes.
This CL introduces an asset server that provides an atlas to all processes.
Note: bitmaps used by skia shaders are *not* sampled from the atlas.
It's an uncommon use case and would require extra texture transforms
in the GL shaders.
WHAT IS THE ASSETS ATLAS
The "assets atlas" is a single, shareable graphic buffer that contains
all the system's preloaded bitmap drawables (this includes 9-patches.)
The atlas is made of two distinct objects: the graphic buffer that
contains the actual pixels and the map which indicates where each
preloaded bitmap can be found in the atlas (essentially a pair of
x and y coordinates.)
HOW IS THE ASSETS ATLAS GENERATED
Because we need to support a wide variety of devices and because it
is easy to change the list of preloaded drawables, the atlas is
generated at runtime, during the startup phase of the system process.
There are several steps that lead to the atlas generation:
1. If the device is booting for the first time, or if the device was
updated, we need to find the best atlas configuration. To do so,
the atlas service tries a number of width, height and algorithm
variations that allows us to pack as many assets as possible while
using as little memory as possible. Once a best configuration is found,
it gets written to disk in /data/system/framework_atlas
2. Given a best configuration (algorithm variant, dimensions and
number of bitmaps that can be packed in the atlas), the atlas service
packs all the preloaded bitmaps into a single graphic buffer object.
3. The packing is done using Skia in a temporary native bitmap. The
Skia bitmap is then copied into the graphic buffer using OpenGL ES
to benefit from texture swizzling.
HOW PROCESSES USE THE ATLAS
Whenever a process' hardware renderer initializes its EGL context,
it queries the atlas service for the graphic buffer and the map.
It is important to remember that both the context and the map will
be valid for the lifetime of the hardware renderer (if the system
process goes down, all apps get killed as well.)
Every time the hardware renderer needs to render a bitmap, it first
checks whether the bitmap can be found in the assets atlas. When
the bitmap is part of the atlas, texture coordinates are remapped
appropriately before rendering.
Change-Id: I8eaecf53e7f6a33d90da3d0047c5ceec89ea3af0
2013-04-17 18:54:38 -07:00
|
|
|
|
2013-06-04 18:00:09 -07:00
|
|
|
resetBoundTextures();
|
|
|
|
|
Pack preloaded framework assets in a texture atlas
When the Android runtime starts, the system preloads a series of assets
in the Zygote process. These assets are shared across all processes.
Unfortunately, each one of these assets is later uploaded in its own
OpenGL texture, once per process. This wastes memory and generates
unnecessary OpenGL state changes.
This CL introduces an asset server that provides an atlas to all processes.
Note: bitmaps used by skia shaders are *not* sampled from the atlas.
It's an uncommon use case and would require extra texture transforms
in the GL shaders.
WHAT IS THE ASSETS ATLAS
The "assets atlas" is a single, shareable graphic buffer that contains
all the system's preloaded bitmap drawables (this includes 9-patches.)
The atlas is made of two distinct objects: the graphic buffer that
contains the actual pixels and the map which indicates where each
preloaded bitmap can be found in the atlas (essentially a pair of
x and y coordinates.)
HOW IS THE ASSETS ATLAS GENERATED
Because we need to support a wide variety of devices and because it
is easy to change the list of preloaded drawables, the atlas is
generated at runtime, during the startup phase of the system process.
There are several steps that lead to the atlas generation:
1. If the device is booting for the first time, or if the device was
updated, we need to find the best atlas configuration. To do so,
the atlas service tries a number of width, height and algorithm
variations that allows us to pack as many assets as possible while
using as little memory as possible. Once a best configuration is found,
it gets written to disk in /data/system/framework_atlas
2. Given a best configuration (algorithm variant, dimensions and
number of bitmaps that can be packed in the atlas), the atlas service
packs all the preloaded bitmaps into a single graphic buffer object.
3. The packing is done using Skia in a temporary native bitmap. The
Skia bitmap is then copied into the graphic buffer using OpenGL ES
to benefit from texture swizzling.
HOW PROCESSES USE THE ATLAS
Whenever a process' hardware renderer initializes its EGL context,
it queries the atlas service for the graphic buffer and the map.
It is important to remember that both the context and the map will
be valid for the lifetime of the hardware renderer (if the system
process goes down, all apps get killed as well.)
Every time the hardware renderer needs to render a bitmap, it first
checks whether the bitmap can be found in the assets atlas. When
the bitmap is part of the atlas, texture coordinates are remapped
appropriately before rendering.
Change-Id: I8eaecf53e7f6a33d90da3d0047c5ceec89ea3af0
2013-04-17 18:54:38 -07:00
|
|
|
return true;
|
2011-11-09 20:10:18 -08:00
|
|
|
}
|
|
|
|
|
2012-07-13 18:25:35 -07:00
|
|
|
void Caches::initFont() {
|
|
|
|
fontRenderer = GammaFontRenderer::createRenderer();
|
|
|
|
}
|
|
|
|
|
2012-05-12 16:18:58 -07:00
|
|
|
void Caches::initExtensions() {
|
2013-02-06 16:51:04 -08:00
|
|
|
if (mExtensions.hasDebugMarker()) {
|
2012-05-12 16:18:58 -07:00
|
|
|
eventMark = glInsertEventMarkerEXT;
|
2013-03-01 14:31:04 -08:00
|
|
|
|
2013-03-08 13:12:16 -08:00
|
|
|
startMark = glPushGroupMarkerEXT;
|
|
|
|
endMark = glPopGroupMarkerEXT;
|
2012-05-12 16:18:58 -07:00
|
|
|
} else {
|
|
|
|
eventMark = eventMarkNull;
|
|
|
|
startMark = startMarkNull;
|
|
|
|
endMark = endMarkNull;
|
|
|
|
}
|
|
|
|
|
2013-03-01 14:31:04 -08:00
|
|
|
if (mExtensions.hasDebugLabel() && (drawDeferDisabled || drawReorderDisabled)) {
|
2012-05-12 16:18:58 -07:00
|
|
|
setLabel = glLabelObjectEXT;
|
|
|
|
getLabel = glGetObjectLabelEXT;
|
|
|
|
} else {
|
|
|
|
setLabel = setLabelNull;
|
|
|
|
getLabel = getLabelNull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Caches::initConstraints() {
|
|
|
|
GLint maxTextureUnits;
|
|
|
|
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
|
|
|
|
if (maxTextureUnits < REQUIRED_TEXTURE_UNITS_COUNT) {
|
|
|
|
ALOGW("At least %d texture units are required!", REQUIRED_TEXTURE_UNITS_COUNT);
|
|
|
|
}
|
|
|
|
|
|
|
|
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
|
|
|
|
}
|
|
|
|
|
2013-05-09 11:50:12 -07:00
|
|
|
void Caches::initStaticProperties() {
|
|
|
|
gpuPixelBuffersEnabled = false;
|
|
|
|
|
|
|
|
// OpenGL ES 3.0+ specific features
|
2013-06-13 14:29:40 -07:00
|
|
|
if (mExtensions.hasPixelBufferObjects()) {
|
2013-05-09 11:50:12 -07:00
|
|
|
char property[PROPERTY_VALUE_MAX];
|
|
|
|
if (property_get(PROPERTY_ENABLE_GPU_PIXEL_BUFFERS, property, "true") > 0) {
|
|
|
|
gpuPixelBuffersEnabled = !strcmp(property, "true");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-29 17:52:58 -08:00
|
|
|
bool Caches::initProperties() {
|
|
|
|
bool prevDebugLayersUpdates = debugLayersUpdates;
|
|
|
|
bool prevDebugOverdraw = debugOverdraw;
|
2013-02-25 14:15:37 -08:00
|
|
|
StencilClipDebug prevDebugStencilClip = debugStencilClip;
|
2012-11-29 17:52:58 -08:00
|
|
|
|
2012-08-06 14:51:10 -07:00
|
|
|
char property[PROPERTY_VALUE_MAX];
|
|
|
|
if (property_get(PROPERTY_DEBUG_LAYERS_UPDATES, property, NULL) > 0) {
|
|
|
|
INIT_LOGD(" Layers updates debug enabled: %s", property);
|
|
|
|
debugLayersUpdates = !strcmp(property, "true");
|
|
|
|
} else {
|
|
|
|
debugLayersUpdates = false;
|
|
|
|
}
|
2012-09-21 19:15:00 -07:00
|
|
|
|
2013-08-21 11:53:18 -07:00
|
|
|
debugOverdraw = false;
|
2012-09-21 19:15:00 -07:00
|
|
|
if (property_get(PROPERTY_DEBUG_OVERDRAW, property, NULL) > 0) {
|
|
|
|
INIT_LOGD(" Overdraw debug enabled: %s", property);
|
2013-08-21 11:53:18 -07:00
|
|
|
if (!strcmp(property, "show")) {
|
|
|
|
debugOverdraw = true;
|
|
|
|
mOverdrawDebugColorSet = kColorSet_Default;
|
|
|
|
} else if (!strcmp(property, "show_deuteranomaly")) {
|
|
|
|
debugOverdraw = true;
|
|
|
|
mOverdrawDebugColorSet = kColorSet_Deuteranomaly;
|
|
|
|
}
|
2012-09-21 19:15:00 -07:00
|
|
|
}
|
2012-11-29 17:52:58 -08:00
|
|
|
|
2013-02-25 14:15:37 -08:00
|
|
|
// See Properties.h for valid values
|
|
|
|
if (property_get(PROPERTY_DEBUG_STENCIL_CLIP, property, NULL) > 0) {
|
|
|
|
INIT_LOGD(" Stencil clip debug enabled: %s", property);
|
|
|
|
if (!strcmp(property, "hide")) {
|
|
|
|
debugStencilClip = kStencilHide;
|
|
|
|
} else if (!strcmp(property, "highlight")) {
|
|
|
|
debugStencilClip = kStencilShowHighlight;
|
|
|
|
} else if (!strcmp(property, "region")) {
|
|
|
|
debugStencilClip = kStencilShowRegion;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
debugStencilClip = kStencilHide;
|
|
|
|
}
|
|
|
|
|
2013-03-01 14:31:04 -08:00
|
|
|
if (property_get(PROPERTY_DISABLE_DRAW_DEFER, property, "false")) {
|
|
|
|
drawDeferDisabled = !strcasecmp(property, "true");
|
|
|
|
INIT_LOGD(" Draw defer %s", drawDeferDisabled ? "disabled" : "enabled");
|
|
|
|
} else {
|
|
|
|
INIT_LOGD(" Draw defer enabled");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (property_get(PROPERTY_DISABLE_DRAW_REORDER, property, "false")) {
|
|
|
|
drawReorderDisabled = !strcasecmp(property, "true");
|
|
|
|
INIT_LOGD(" Draw reorder %s", drawReorderDisabled ? "disabled" : "enabled");
|
|
|
|
} else {
|
|
|
|
INIT_LOGD(" Draw reorder enabled");
|
|
|
|
}
|
|
|
|
|
2012-11-29 17:52:58 -08:00
|
|
|
return (prevDebugLayersUpdates != debugLayersUpdates) ||
|
2013-02-25 14:15:37 -08:00
|
|
|
(prevDebugOverdraw != debugOverdraw) ||
|
|
|
|
(prevDebugStencilClip != debugStencilClip);
|
2012-08-06 14:51:10 -07:00
|
|
|
}
|
|
|
|
|
2011-11-09 20:10:18 -08:00
|
|
|
void Caches::terminate() {
|
|
|
|
if (!mInitialized) return;
|
|
|
|
|
|
|
|
glDeleteBuffers(1, &meshBuffer);
|
|
|
|
mCurrentBuffer = 0;
|
|
|
|
|
Pack preloaded framework assets in a texture atlas
When the Android runtime starts, the system preloads a series of assets
in the Zygote process. These assets are shared across all processes.
Unfortunately, each one of these assets is later uploaded in its own
OpenGL texture, once per process. This wastes memory and generates
unnecessary OpenGL state changes.
This CL introduces an asset server that provides an atlas to all processes.
Note: bitmaps used by skia shaders are *not* sampled from the atlas.
It's an uncommon use case and would require extra texture transforms
in the GL shaders.
WHAT IS THE ASSETS ATLAS
The "assets atlas" is a single, shareable graphic buffer that contains
all the system's preloaded bitmap drawables (this includes 9-patches.)
The atlas is made of two distinct objects: the graphic buffer that
contains the actual pixels and the map which indicates where each
preloaded bitmap can be found in the atlas (essentially a pair of
x and y coordinates.)
HOW IS THE ASSETS ATLAS GENERATED
Because we need to support a wide variety of devices and because it
is easy to change the list of preloaded drawables, the atlas is
generated at runtime, during the startup phase of the system process.
There are several steps that lead to the atlas generation:
1. If the device is booting for the first time, or if the device was
updated, we need to find the best atlas configuration. To do so,
the atlas service tries a number of width, height and algorithm
variations that allows us to pack as many assets as possible while
using as little memory as possible. Once a best configuration is found,
it gets written to disk in /data/system/framework_atlas
2. Given a best configuration (algorithm variant, dimensions and
number of bitmaps that can be packed in the atlas), the atlas service
packs all the preloaded bitmaps into a single graphic buffer object.
3. The packing is done using Skia in a temporary native bitmap. The
Skia bitmap is then copied into the graphic buffer using OpenGL ES
to benefit from texture swizzling.
HOW PROCESSES USE THE ATLAS
Whenever a process' hardware renderer initializes its EGL context,
it queries the atlas service for the graphic buffer and the map.
It is important to remember that both the context and the map will
be valid for the lifetime of the hardware renderer (if the system
process goes down, all apps get killed as well.)
Every time the hardware renderer needs to render a bitmap, it first
checks whether the bitmap can be found in the assets atlas. When
the bitmap is part of the atlas, texture coordinates are remapped
appropriately before rendering.
Change-Id: I8eaecf53e7f6a33d90da3d0047c5ceec89ea3af0
2013-04-17 18:54:38 -07:00
|
|
|
glDeleteBuffers(1, &mMeshIndices);
|
2010-10-27 18:57:51 -07:00
|
|
|
delete[] mRegionMesh;
|
Pack preloaded framework assets in a texture atlas
When the Android runtime starts, the system preloads a series of assets
in the Zygote process. These assets are shared across all processes.
Unfortunately, each one of these assets is later uploaded in its own
OpenGL texture, once per process. This wastes memory and generates
unnecessary OpenGL state changes.
This CL introduces an asset server that provides an atlas to all processes.
Note: bitmaps used by skia shaders are *not* sampled from the atlas.
It's an uncommon use case and would require extra texture transforms
in the GL shaders.
WHAT IS THE ASSETS ATLAS
The "assets atlas" is a single, shareable graphic buffer that contains
all the system's preloaded bitmap drawables (this includes 9-patches.)
The atlas is made of two distinct objects: the graphic buffer that
contains the actual pixels and the map which indicates where each
preloaded bitmap can be found in the atlas (essentially a pair of
x and y coordinates.)
HOW IS THE ASSETS ATLAS GENERATED
Because we need to support a wide variety of devices and because it
is easy to change the list of preloaded drawables, the atlas is
generated at runtime, during the startup phase of the system process.
There are several steps that lead to the atlas generation:
1. If the device is booting for the first time, or if the device was
updated, we need to find the best atlas configuration. To do so,
the atlas service tries a number of width, height and algorithm
variations that allows us to pack as many assets as possible while
using as little memory as possible. Once a best configuration is found,
it gets written to disk in /data/system/framework_atlas
2. Given a best configuration (algorithm variant, dimensions and
number of bitmaps that can be packed in the atlas), the atlas service
packs all the preloaded bitmaps into a single graphic buffer object.
3. The packing is done using Skia in a temporary native bitmap. The
Skia bitmap is then copied into the graphic buffer using OpenGL ES
to benefit from texture swizzling.
HOW PROCESSES USE THE ATLAS
Whenever a process' hardware renderer initializes its EGL context,
it queries the atlas service for the graphic buffer and the map.
It is important to remember that both the context and the map will
be valid for the lifetime of the hardware renderer (if the system
process goes down, all apps get killed as well.)
Every time the hardware renderer needs to render a bitmap, it first
checks whether the bitmap can be found in the assets atlas. When
the bitmap is part of the atlas, texture coordinates are remapped
appropriately before rendering.
Change-Id: I8eaecf53e7f6a33d90da3d0047c5ceec89ea3af0
2013-04-17 18:54:38 -07:00
|
|
|
mMeshIndices = 0;
|
2011-11-09 20:10:18 -08:00
|
|
|
mRegionMesh = NULL;
|
|
|
|
|
2014-02-14 13:13:41 -08:00
|
|
|
glDeleteBuffers(1, &mShadowStripsIndices);
|
|
|
|
mShadowStripsIndices = 0;
|
|
|
|
|
2011-11-09 20:10:18 -08:00
|
|
|
fboCache.clear();
|
|
|
|
|
|
|
|
programCache.clear();
|
|
|
|
currentProgram = NULL;
|
|
|
|
|
Pack preloaded framework assets in a texture atlas
When the Android runtime starts, the system preloads a series of assets
in the Zygote process. These assets are shared across all processes.
Unfortunately, each one of these assets is later uploaded in its own
OpenGL texture, once per process. This wastes memory and generates
unnecessary OpenGL state changes.
This CL introduces an asset server that provides an atlas to all processes.
Note: bitmaps used by skia shaders are *not* sampled from the atlas.
It's an uncommon use case and would require extra texture transforms
in the GL shaders.
WHAT IS THE ASSETS ATLAS
The "assets atlas" is a single, shareable graphic buffer that contains
all the system's preloaded bitmap drawables (this includes 9-patches.)
The atlas is made of two distinct objects: the graphic buffer that
contains the actual pixels and the map which indicates where each
preloaded bitmap can be found in the atlas (essentially a pair of
x and y coordinates.)
HOW IS THE ASSETS ATLAS GENERATED
Because we need to support a wide variety of devices and because it
is easy to change the list of preloaded drawables, the atlas is
generated at runtime, during the startup phase of the system process.
There are several steps that lead to the atlas generation:
1. If the device is booting for the first time, or if the device was
updated, we need to find the best atlas configuration. To do so,
the atlas service tries a number of width, height and algorithm
variations that allows us to pack as many assets as possible while
using as little memory as possible. Once a best configuration is found,
it gets written to disk in /data/system/framework_atlas
2. Given a best configuration (algorithm variant, dimensions and
number of bitmaps that can be packed in the atlas), the atlas service
packs all the preloaded bitmaps into a single graphic buffer object.
3. The packing is done using Skia in a temporary native bitmap. The
Skia bitmap is then copied into the graphic buffer using OpenGL ES
to benefit from texture swizzling.
HOW PROCESSES USE THE ATLAS
Whenever a process' hardware renderer initializes its EGL context,
it queries the atlas service for the graphic buffer and the map.
It is important to remember that both the context and the map will
be valid for the lifetime of the hardware renderer (if the system
process goes down, all apps get killed as well.)
Every time the hardware renderer needs to render a bitmap, it first
checks whether the bitmap can be found in the assets atlas. When
the bitmap is part of the atlas, texture coordinates are remapped
appropriately before rendering.
Change-Id: I8eaecf53e7f6a33d90da3d0047c5ceec89ea3af0
2013-04-17 18:54:38 -07:00
|
|
|
assetAtlas.terminate();
|
|
|
|
|
|
|
|
patchCache.clear();
|
|
|
|
|
2013-08-16 18:38:29 -07:00
|
|
|
clearGarbage();
|
|
|
|
|
2011-11-09 20:10:18 -08:00
|
|
|
mInitialized = false;
|
2010-10-27 18:57:51 -07:00
|
|
|
}
|
|
|
|
|
2010-11-10 11:59:15 -08:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Debug
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-08-21 11:53:18 -07:00
|
|
|
uint32_t Caches::getOverdrawColor(uint32_t amount) const {
|
|
|
|
static uint32_t sOverdrawColors[2][4] = {
|
|
|
|
{ 0x2f0000ff, 0x2f00ff00, 0x3fff0000, 0x7fff0000 },
|
|
|
|
{ 0x2f0000ff, 0x4fffff00, 0x5fff8ad8, 0x7fff0000 }
|
|
|
|
};
|
|
|
|
if (amount < 1) amount = 1;
|
|
|
|
if (amount > 4) amount = 4;
|
|
|
|
return sOverdrawColors[mOverdrawDebugColorSet][amount - 1];
|
|
|
|
}
|
|
|
|
|
2010-11-10 11:59:15 -08:00
|
|
|
void Caches::dumpMemoryUsage() {
|
2011-03-24 10:51:31 -07:00
|
|
|
String8 stringLog;
|
|
|
|
dumpMemoryUsage(stringLog);
|
2011-12-20 16:23:08 +00:00
|
|
|
ALOGD("%s", stringLog.string());
|
2011-03-24 10:51:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void Caches::dumpMemoryUsage(String8 &log) {
|
|
|
|
log.appendFormat("Current memory usage / total memory usage (bytes):\n");
|
|
|
|
log.appendFormat(" TextureCache %8d / %8d\n",
|
|
|
|
textureCache.getSize(), textureCache.getMaxSize());
|
|
|
|
log.appendFormat(" LayerCache %8d / %8d\n",
|
|
|
|
layerCache.getSize(), layerCache.getMaxSize());
|
2013-02-12 16:08:55 -08:00
|
|
|
log.appendFormat(" RenderBufferCache %8d / %8d\n",
|
|
|
|
renderBufferCache.getSize(), renderBufferCache.getMaxSize());
|
2011-03-24 10:51:31 -07:00
|
|
|
log.appendFormat(" GradientCache %8d / %8d\n",
|
|
|
|
gradientCache.getSize(), gradientCache.getMaxSize());
|
|
|
|
log.appendFormat(" PathCache %8d / %8d\n",
|
|
|
|
pathCache.getSize(), pathCache.getMaxSize());
|
|
|
|
log.appendFormat(" TextDropShadowCache %8d / %8d\n", dropShadowCache.getSize(),
|
2010-11-10 11:59:15 -08:00
|
|
|
dropShadowCache.getMaxSize());
|
Pack preloaded framework assets in a texture atlas
When the Android runtime starts, the system preloads a series of assets
in the Zygote process. These assets are shared across all processes.
Unfortunately, each one of these assets is later uploaded in its own
OpenGL texture, once per process. This wastes memory and generates
unnecessary OpenGL state changes.
This CL introduces an asset server that provides an atlas to all processes.
Note: bitmaps used by skia shaders are *not* sampled from the atlas.
It's an uncommon use case and would require extra texture transforms
in the GL shaders.
WHAT IS THE ASSETS ATLAS
The "assets atlas" is a single, shareable graphic buffer that contains
all the system's preloaded bitmap drawables (this includes 9-patches.)
The atlas is made of two distinct objects: the graphic buffer that
contains the actual pixels and the map which indicates where each
preloaded bitmap can be found in the atlas (essentially a pair of
x and y coordinates.)
HOW IS THE ASSETS ATLAS GENERATED
Because we need to support a wide variety of devices and because it
is easy to change the list of preloaded drawables, the atlas is
generated at runtime, during the startup phase of the system process.
There are several steps that lead to the atlas generation:
1. If the device is booting for the first time, or if the device was
updated, we need to find the best atlas configuration. To do so,
the atlas service tries a number of width, height and algorithm
variations that allows us to pack as many assets as possible while
using as little memory as possible. Once a best configuration is found,
it gets written to disk in /data/system/framework_atlas
2. Given a best configuration (algorithm variant, dimensions and
number of bitmaps that can be packed in the atlas), the atlas service
packs all the preloaded bitmaps into a single graphic buffer object.
3. The packing is done using Skia in a temporary native bitmap. The
Skia bitmap is then copied into the graphic buffer using OpenGL ES
to benefit from texture swizzling.
HOW PROCESSES USE THE ATLAS
Whenever a process' hardware renderer initializes its EGL context,
it queries the atlas service for the graphic buffer and the map.
It is important to remember that both the context and the map will
be valid for the lifetime of the hardware renderer (if the system
process goes down, all apps get killed as well.)
Every time the hardware renderer needs to render a bitmap, it first
checks whether the bitmap can be found in the assets atlas. When
the bitmap is part of the atlas, texture coordinates are remapped
appropriately before rendering.
Change-Id: I8eaecf53e7f6a33d90da3d0047c5ceec89ea3af0
2013-04-17 18:54:38 -07:00
|
|
|
log.appendFormat(" PatchCache %8d / %8d\n",
|
|
|
|
patchCache.getSize(), patchCache.getMaxSize());
|
2012-07-13 18:25:35 -07:00
|
|
|
for (uint32_t i = 0; i < fontRenderer->getFontRendererCount(); i++) {
|
2013-06-25 14:25:17 -07:00
|
|
|
const uint32_t sizeA8 = fontRenderer->getFontRendererSize(i, GL_ALPHA);
|
|
|
|
const uint32_t sizeRGBA = fontRenderer->getFontRendererSize(i, GL_RGBA);
|
|
|
|
log.appendFormat(" FontRenderer %d A8 %8d / %8d\n", i, sizeA8, sizeA8);
|
|
|
|
log.appendFormat(" FontRenderer %d RGBA %8d / %8d\n", i, sizeRGBA, sizeRGBA);
|
|
|
|
log.appendFormat(" FontRenderer %d total %8d / %8d\n", i, sizeA8 + sizeRGBA,
|
|
|
|
sizeA8 + sizeRGBA);
|
2010-11-10 11:59:15 -08:00
|
|
|
}
|
2011-05-27 10:21:07 -07:00
|
|
|
log.appendFormat("Other:\n");
|
2011-03-24 10:51:31 -07:00
|
|
|
log.appendFormat(" FboCache %8d / %8d\n",
|
|
|
|
fboCache.getSize(), fboCache.getMaxSize());
|
2010-11-10 11:59:15 -08:00
|
|
|
|
|
|
|
uint32_t total = 0;
|
|
|
|
total += textureCache.getSize();
|
|
|
|
total += layerCache.getSize();
|
2013-02-12 16:08:55 -08:00
|
|
|
total += renderBufferCache.getSize();
|
2010-11-10 11:59:15 -08:00
|
|
|
total += gradientCache.getSize();
|
|
|
|
total += pathCache.getSize();
|
|
|
|
total += dropShadowCache.getSize();
|
Pack preloaded framework assets in a texture atlas
When the Android runtime starts, the system preloads a series of assets
in the Zygote process. These assets are shared across all processes.
Unfortunately, each one of these assets is later uploaded in its own
OpenGL texture, once per process. This wastes memory and generates
unnecessary OpenGL state changes.
This CL introduces an asset server that provides an atlas to all processes.
Note: bitmaps used by skia shaders are *not* sampled from the atlas.
It's an uncommon use case and would require extra texture transforms
in the GL shaders.
WHAT IS THE ASSETS ATLAS
The "assets atlas" is a single, shareable graphic buffer that contains
all the system's preloaded bitmap drawables (this includes 9-patches.)
The atlas is made of two distinct objects: the graphic buffer that
contains the actual pixels and the map which indicates where each
preloaded bitmap can be found in the atlas (essentially a pair of
x and y coordinates.)
HOW IS THE ASSETS ATLAS GENERATED
Because we need to support a wide variety of devices and because it
is easy to change the list of preloaded drawables, the atlas is
generated at runtime, during the startup phase of the system process.
There are several steps that lead to the atlas generation:
1. If the device is booting for the first time, or if the device was
updated, we need to find the best atlas configuration. To do so,
the atlas service tries a number of width, height and algorithm
variations that allows us to pack as many assets as possible while
using as little memory as possible. Once a best configuration is found,
it gets written to disk in /data/system/framework_atlas
2. Given a best configuration (algorithm variant, dimensions and
number of bitmaps that can be packed in the atlas), the atlas service
packs all the preloaded bitmaps into a single graphic buffer object.
3. The packing is done using Skia in a temporary native bitmap. The
Skia bitmap is then copied into the graphic buffer using OpenGL ES
to benefit from texture swizzling.
HOW PROCESSES USE THE ATLAS
Whenever a process' hardware renderer initializes its EGL context,
it queries the atlas service for the graphic buffer and the map.
It is important to remember that both the context and the map will
be valid for the lifetime of the hardware renderer (if the system
process goes down, all apps get killed as well.)
Every time the hardware renderer needs to render a bitmap, it first
checks whether the bitmap can be found in the assets atlas. When
the bitmap is part of the atlas, texture coordinates are remapped
appropriately before rendering.
Change-Id: I8eaecf53e7f6a33d90da3d0047c5ceec89ea3af0
2013-04-17 18:54:38 -07:00
|
|
|
total += patchCache.getSize();
|
2012-07-13 18:25:35 -07:00
|
|
|
for (uint32_t i = 0; i < fontRenderer->getFontRendererCount(); i++) {
|
2013-06-25 14:25:17 -07:00
|
|
|
total += fontRenderer->getFontRendererSize(i, GL_ALPHA);
|
|
|
|
total += fontRenderer->getFontRendererSize(i, GL_RGBA);
|
2010-11-10 11:59:15 -08:00
|
|
|
}
|
|
|
|
|
2011-03-24 10:51:31 -07:00
|
|
|
log.appendFormat("Total memory usage:\n");
|
|
|
|
log.appendFormat(" %d bytes, %.2f MB\n", total, total / 1024.0f / 1024.0f);
|
2010-11-10 11:59:15 -08:00
|
|
|
}
|
|
|
|
|
2010-11-11 15:36:56 -08:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Memory management
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void Caches::clearGarbage() {
|
|
|
|
textureCache.clearGarbage();
|
|
|
|
pathCache.clearGarbage();
|
2013-06-26 15:45:41 -07:00
|
|
|
patchCache.clearGarbage();
|
2011-01-12 12:53:32 -08:00
|
|
|
|
2014-03-12 13:56:30 -07:00
|
|
|
Vector<RenderNode*> displayLists;
|
2012-09-25 22:52:40 -07:00
|
|
|
Vector<Layer*> layers;
|
|
|
|
|
|
|
|
{ // scope for the lock
|
|
|
|
Mutex::Autolock _l(mGarbageLock);
|
|
|
|
displayLists = mDisplayListGarbage;
|
|
|
|
layers = mLayerGarbage;
|
|
|
|
mDisplayListGarbage.clear();
|
|
|
|
mLayerGarbage.clear();
|
|
|
|
}
|
2011-01-12 12:53:32 -08:00
|
|
|
|
2012-09-25 22:52:40 -07:00
|
|
|
size_t count = displayLists.size();
|
2011-01-12 12:53:32 -08:00
|
|
|
for (size_t i = 0; i < count; i++) {
|
2014-03-12 13:56:30 -07:00
|
|
|
RenderNode* displayList = displayLists.itemAt(i);
|
2012-09-25 22:52:40 -07:00
|
|
|
delete displayList;
|
2011-01-12 12:53:32 -08:00
|
|
|
}
|
2012-03-05 13:44:35 -08:00
|
|
|
|
2012-09-25 22:52:40 -07:00
|
|
|
count = layers.size();
|
2012-03-05 13:44:35 -08:00
|
|
|
for (size_t i = 0; i < count; i++) {
|
2012-09-25 22:52:40 -07:00
|
|
|
Layer* layer = layers.itemAt(i);
|
|
|
|
delete layer;
|
2012-03-05 13:44:35 -08:00
|
|
|
}
|
2012-09-25 22:52:40 -07:00
|
|
|
layers.clear();
|
2011-01-12 12:53:32 -08:00
|
|
|
}
|
|
|
|
|
2011-01-13 12:13:20 -08:00
|
|
|
void Caches::deleteLayerDeferred(Layer* layer) {
|
2011-01-12 12:53:32 -08:00
|
|
|
Mutex::Autolock _l(mGarbageLock);
|
2011-01-13 12:13:20 -08:00
|
|
|
mLayerGarbage.push(layer);
|
2010-11-11 15:36:56 -08:00
|
|
|
}
|
|
|
|
|
2014-03-12 13:56:30 -07:00
|
|
|
void Caches::deleteDisplayListDeferred(RenderNode* displayList) {
|
2012-03-05 13:44:35 -08:00
|
|
|
Mutex::Autolock _l(mGarbageLock);
|
|
|
|
mDisplayListGarbage.push(displayList);
|
|
|
|
}
|
|
|
|
|
2011-07-18 15:00:43 -07:00
|
|
|
void Caches::flush(FlushMode mode) {
|
|
|
|
FLUSH_LOGD("Flushing caches (mode %d)", mode);
|
|
|
|
|
2013-08-16 14:44:38 -07:00
|
|
|
// We must stop tasks before clearing caches
|
|
|
|
if (mode > kFlushMode_Layers) {
|
|
|
|
tasks.stop();
|
|
|
|
}
|
|
|
|
|
2011-07-18 15:00:43 -07:00
|
|
|
switch (mode) {
|
|
|
|
case kFlushMode_Full:
|
|
|
|
textureCache.clear();
|
|
|
|
patchCache.clear();
|
|
|
|
dropShadowCache.clear();
|
|
|
|
gradientCache.clear();
|
2012-07-13 18:25:35 -07:00
|
|
|
fontRenderer->clear();
|
2013-08-16 13:55:29 -07:00
|
|
|
fboCache.clear();
|
2012-07-31 21:16:07 -07:00
|
|
|
dither.clear();
|
2011-07-18 15:00:43 -07:00
|
|
|
// fall through
|
|
|
|
case kFlushMode_Moderate:
|
2012-07-13 18:25:35 -07:00
|
|
|
fontRenderer->flush();
|
2011-11-04 15:12:29 -07:00
|
|
|
textureCache.flush();
|
2011-07-18 15:00:43 -07:00
|
|
|
pathCache.clear();
|
2011-07-27 16:28:21 -07:00
|
|
|
// fall through
|
|
|
|
case kFlushMode_Layers:
|
|
|
|
layerCache.clear();
|
2013-02-12 16:08:55 -08:00
|
|
|
renderBufferCache.clear();
|
2011-07-18 15:00:43 -07:00
|
|
|
break;
|
|
|
|
}
|
Fix texture corruption
When memory gets low on a device, activities flush everything they can.
Hardware-accelerated activites, such as Launcher, flush GL resources and destroy
the GL context. However, some resources were still hanging around, due to deferred
destruction policies (we don't delete layers until the DisplayLists they are in
are finalized, to ensure we don't deref deleted objects). This meant that we were
referring to obsolete GL data in these objects. in particular, it meant that we might
come around later, after a new GL context was created, and delete a texture object
that was incorrect. We use the layer's "texture id" to refer to the texture underlying the
layer. But if there's a new GL context, then this texture ID is no longer valid, and
we may be deleting the texture that a different object (layer, icon, whatever) is referring
to, because the driver may return that same ID under the new GL context.
The fix is to more aggressively delete things that we know will not be used again
when the GL context is destroyed. In particular, we delete all resources being used
by all DisplayLists at GL context destruction time.
Issue #7195815 Textures corruption on all devices, in many apps
Change-Id: I52d2d208173690dbb794a83402d38f14ea4c6c22
2012-09-30 12:14:13 -07:00
|
|
|
|
|
|
|
clearGarbage();
|
2011-07-18 15:00:43 -07:00
|
|
|
}
|
|
|
|
|
2010-10-27 18:57:51 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// VBO
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-12-12 20:35:21 -08:00
|
|
|
bool Caches::bindMeshBuffer() {
|
|
|
|
return bindMeshBuffer(meshBuffer);
|
2010-10-22 18:59:26 -07:00
|
|
|
}
|
|
|
|
|
2011-12-12 20:35:21 -08:00
|
|
|
bool Caches::bindMeshBuffer(const GLuint buffer) {
|
2010-10-25 18:42:25 -07:00
|
|
|
if (mCurrentBuffer != buffer) {
|
2010-10-22 18:59:26 -07:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
2010-10-25 18:42:25 -07:00
|
|
|
mCurrentBuffer = buffer;
|
2011-12-12 20:35:21 -08:00
|
|
|
return true;
|
2010-10-22 18:59:26 -07:00
|
|
|
}
|
2011-12-12 20:35:21 -08:00
|
|
|
return false;
|
2010-10-22 18:59:26 -07:00
|
|
|
}
|
|
|
|
|
2011-12-12 20:35:21 -08:00
|
|
|
bool Caches::unbindMeshBuffer() {
|
2010-10-25 18:42:25 -07:00
|
|
|
if (mCurrentBuffer) {
|
2010-10-22 18:59:26 -07:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
2010-10-25 18:42:25 -07:00
|
|
|
mCurrentBuffer = 0;
|
2011-12-12 20:35:21 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-14 13:13:41 -08:00
|
|
|
bool Caches::bindIndicesBufferInternal(const GLuint buffer) {
|
2011-12-13 13:11:32 -08:00
|
|
|
if (mCurrentIndicesBuffer != buffer) {
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer);
|
|
|
|
mCurrentIndicesBuffer = buffer;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-14 13:13:41 -08:00
|
|
|
bool Caches::bindQuadIndicesBuffer() {
|
Pack preloaded framework assets in a texture atlas
When the Android runtime starts, the system preloads a series of assets
in the Zygote process. These assets are shared across all processes.
Unfortunately, each one of these assets is later uploaded in its own
OpenGL texture, once per process. This wastes memory and generates
unnecessary OpenGL state changes.
This CL introduces an asset server that provides an atlas to all processes.
Note: bitmaps used by skia shaders are *not* sampled from the atlas.
It's an uncommon use case and would require extra texture transforms
in the GL shaders.
WHAT IS THE ASSETS ATLAS
The "assets atlas" is a single, shareable graphic buffer that contains
all the system's preloaded bitmap drawables (this includes 9-patches.)
The atlas is made of two distinct objects: the graphic buffer that
contains the actual pixels and the map which indicates where each
preloaded bitmap can be found in the atlas (essentially a pair of
x and y coordinates.)
HOW IS THE ASSETS ATLAS GENERATED
Because we need to support a wide variety of devices and because it
is easy to change the list of preloaded drawables, the atlas is
generated at runtime, during the startup phase of the system process.
There are several steps that lead to the atlas generation:
1. If the device is booting for the first time, or if the device was
updated, we need to find the best atlas configuration. To do so,
the atlas service tries a number of width, height and algorithm
variations that allows us to pack as many assets as possible while
using as little memory as possible. Once a best configuration is found,
it gets written to disk in /data/system/framework_atlas
2. Given a best configuration (algorithm variant, dimensions and
number of bitmaps that can be packed in the atlas), the atlas service
packs all the preloaded bitmaps into a single graphic buffer object.
3. The packing is done using Skia in a temporary native bitmap. The
Skia bitmap is then copied into the graphic buffer using OpenGL ES
to benefit from texture swizzling.
HOW PROCESSES USE THE ATLAS
Whenever a process' hardware renderer initializes its EGL context,
it queries the atlas service for the graphic buffer and the map.
It is important to remember that both the context and the map will
be valid for the lifetime of the hardware renderer (if the system
process goes down, all apps get killed as well.)
Every time the hardware renderer needs to render a bitmap, it first
checks whether the bitmap can be found in the assets atlas. When
the bitmap is part of the atlas, texture coordinates are remapped
appropriately before rendering.
Change-Id: I8eaecf53e7f6a33d90da3d0047c5ceec89ea3af0
2013-04-17 18:54:38 -07:00
|
|
|
if (!mMeshIndices) {
|
2013-06-18 15:53:53 -07:00
|
|
|
uint16_t* regionIndices = new uint16_t[gMaxNumberOfQuads * 6];
|
|
|
|
for (uint32_t i = 0; i < gMaxNumberOfQuads; i++) {
|
Pack preloaded framework assets in a texture atlas
When the Android runtime starts, the system preloads a series of assets
in the Zygote process. These assets are shared across all processes.
Unfortunately, each one of these assets is later uploaded in its own
OpenGL texture, once per process. This wastes memory and generates
unnecessary OpenGL state changes.
This CL introduces an asset server that provides an atlas to all processes.
Note: bitmaps used by skia shaders are *not* sampled from the atlas.
It's an uncommon use case and would require extra texture transforms
in the GL shaders.
WHAT IS THE ASSETS ATLAS
The "assets atlas" is a single, shareable graphic buffer that contains
all the system's preloaded bitmap drawables (this includes 9-patches.)
The atlas is made of two distinct objects: the graphic buffer that
contains the actual pixels and the map which indicates where each
preloaded bitmap can be found in the atlas (essentially a pair of
x and y coordinates.)
HOW IS THE ASSETS ATLAS GENERATED
Because we need to support a wide variety of devices and because it
is easy to change the list of preloaded drawables, the atlas is
generated at runtime, during the startup phase of the system process.
There are several steps that lead to the atlas generation:
1. If the device is booting for the first time, or if the device was
updated, we need to find the best atlas configuration. To do so,
the atlas service tries a number of width, height and algorithm
variations that allows us to pack as many assets as possible while
using as little memory as possible. Once a best configuration is found,
it gets written to disk in /data/system/framework_atlas
2. Given a best configuration (algorithm variant, dimensions and
number of bitmaps that can be packed in the atlas), the atlas service
packs all the preloaded bitmaps into a single graphic buffer object.
3. The packing is done using Skia in a temporary native bitmap. The
Skia bitmap is then copied into the graphic buffer using OpenGL ES
to benefit from texture swizzling.
HOW PROCESSES USE THE ATLAS
Whenever a process' hardware renderer initializes its EGL context,
it queries the atlas service for the graphic buffer and the map.
It is important to remember that both the context and the map will
be valid for the lifetime of the hardware renderer (if the system
process goes down, all apps get killed as well.)
Every time the hardware renderer needs to render a bitmap, it first
checks whether the bitmap can be found in the assets atlas. When
the bitmap is part of the atlas, texture coordinates are remapped
appropriately before rendering.
Change-Id: I8eaecf53e7f6a33d90da3d0047c5ceec89ea3af0
2013-04-17 18:54:38 -07:00
|
|
|
uint16_t quad = i * 4;
|
|
|
|
int index = i * 6;
|
|
|
|
regionIndices[index ] = quad; // top-left
|
|
|
|
regionIndices[index + 1] = quad + 1; // top-right
|
|
|
|
regionIndices[index + 2] = quad + 2; // bottom-left
|
|
|
|
regionIndices[index + 3] = quad + 2; // bottom-left
|
|
|
|
regionIndices[index + 4] = quad + 1; // top-right
|
|
|
|
regionIndices[index + 5] = quad + 3; // bottom-right
|
|
|
|
}
|
|
|
|
|
|
|
|
glGenBuffers(1, &mMeshIndices);
|
2014-02-14 13:13:41 -08:00
|
|
|
bool force = bindIndicesBufferInternal(mMeshIndices);
|
2013-06-18 15:53:53 -07:00
|
|
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, gMaxNumberOfQuads * 6 * sizeof(uint16_t),
|
Pack preloaded framework assets in a texture atlas
When the Android runtime starts, the system preloads a series of assets
in the Zygote process. These assets are shared across all processes.
Unfortunately, each one of these assets is later uploaded in its own
OpenGL texture, once per process. This wastes memory and generates
unnecessary OpenGL state changes.
This CL introduces an asset server that provides an atlas to all processes.
Note: bitmaps used by skia shaders are *not* sampled from the atlas.
It's an uncommon use case and would require extra texture transforms
in the GL shaders.
WHAT IS THE ASSETS ATLAS
The "assets atlas" is a single, shareable graphic buffer that contains
all the system's preloaded bitmap drawables (this includes 9-patches.)
The atlas is made of two distinct objects: the graphic buffer that
contains the actual pixels and the map which indicates where each
preloaded bitmap can be found in the atlas (essentially a pair of
x and y coordinates.)
HOW IS THE ASSETS ATLAS GENERATED
Because we need to support a wide variety of devices and because it
is easy to change the list of preloaded drawables, the atlas is
generated at runtime, during the startup phase of the system process.
There are several steps that lead to the atlas generation:
1. If the device is booting for the first time, or if the device was
updated, we need to find the best atlas configuration. To do so,
the atlas service tries a number of width, height and algorithm
variations that allows us to pack as many assets as possible while
using as little memory as possible. Once a best configuration is found,
it gets written to disk in /data/system/framework_atlas
2. Given a best configuration (algorithm variant, dimensions and
number of bitmaps that can be packed in the atlas), the atlas service
packs all the preloaded bitmaps into a single graphic buffer object.
3. The packing is done using Skia in a temporary native bitmap. The
Skia bitmap is then copied into the graphic buffer using OpenGL ES
to benefit from texture swizzling.
HOW PROCESSES USE THE ATLAS
Whenever a process' hardware renderer initializes its EGL context,
it queries the atlas service for the graphic buffer and the map.
It is important to remember that both the context and the map will
be valid for the lifetime of the hardware renderer (if the system
process goes down, all apps get killed as well.)
Every time the hardware renderer needs to render a bitmap, it first
checks whether the bitmap can be found in the assets atlas. When
the bitmap is part of the atlas, texture coordinates are remapped
appropriately before rendering.
Change-Id: I8eaecf53e7f6a33d90da3d0047c5ceec89ea3af0
2013-04-17 18:54:38 -07:00
|
|
|
regionIndices, GL_STATIC_DRAW);
|
|
|
|
|
|
|
|
delete[] regionIndices;
|
|
|
|
return force;
|
|
|
|
}
|
|
|
|
|
2014-02-14 13:13:41 -08:00
|
|
|
return bindIndicesBufferInternal(mMeshIndices);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Caches::bindShadowIndicesBuffer() {
|
|
|
|
if (!mShadowStripsIndices) {
|
2014-03-11 16:52:30 -07:00
|
|
|
uint16_t* shadowIndices = new uint16_t[MAX_SHADOW_INDEX_COUNT];
|
2014-02-14 13:13:41 -08:00
|
|
|
ShadowTessellator::generateShadowIndices(shadowIndices);
|
|
|
|
glGenBuffers(1, &mShadowStripsIndices);
|
|
|
|
bool force = bindIndicesBufferInternal(mShadowStripsIndices);
|
2014-03-11 16:52:30 -07:00
|
|
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, MAX_SHADOW_INDEX_COUNT * sizeof(uint16_t),
|
2014-02-14 13:13:41 -08:00
|
|
|
shadowIndices, GL_STATIC_DRAW);
|
|
|
|
|
|
|
|
delete[] shadowIndices;
|
|
|
|
return force;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bindIndicesBufferInternal(mShadowStripsIndices);
|
Pack preloaded framework assets in a texture atlas
When the Android runtime starts, the system preloads a series of assets
in the Zygote process. These assets are shared across all processes.
Unfortunately, each one of these assets is later uploaded in its own
OpenGL texture, once per process. This wastes memory and generates
unnecessary OpenGL state changes.
This CL introduces an asset server that provides an atlas to all processes.
Note: bitmaps used by skia shaders are *not* sampled from the atlas.
It's an uncommon use case and would require extra texture transforms
in the GL shaders.
WHAT IS THE ASSETS ATLAS
The "assets atlas" is a single, shareable graphic buffer that contains
all the system's preloaded bitmap drawables (this includes 9-patches.)
The atlas is made of two distinct objects: the graphic buffer that
contains the actual pixels and the map which indicates where each
preloaded bitmap can be found in the atlas (essentially a pair of
x and y coordinates.)
HOW IS THE ASSETS ATLAS GENERATED
Because we need to support a wide variety of devices and because it
is easy to change the list of preloaded drawables, the atlas is
generated at runtime, during the startup phase of the system process.
There are several steps that lead to the atlas generation:
1. If the device is booting for the first time, or if the device was
updated, we need to find the best atlas configuration. To do so,
the atlas service tries a number of width, height and algorithm
variations that allows us to pack as many assets as possible while
using as little memory as possible. Once a best configuration is found,
it gets written to disk in /data/system/framework_atlas
2. Given a best configuration (algorithm variant, dimensions and
number of bitmaps that can be packed in the atlas), the atlas service
packs all the preloaded bitmaps into a single graphic buffer object.
3. The packing is done using Skia in a temporary native bitmap. The
Skia bitmap is then copied into the graphic buffer using OpenGL ES
to benefit from texture swizzling.
HOW PROCESSES USE THE ATLAS
Whenever a process' hardware renderer initializes its EGL context,
it queries the atlas service for the graphic buffer and the map.
It is important to remember that both the context and the map will
be valid for the lifetime of the hardware renderer (if the system
process goes down, all apps get killed as well.)
Every time the hardware renderer needs to render a bitmap, it first
checks whether the bitmap can be found in the assets atlas. When
the bitmap is part of the atlas, texture coordinates are remapped
appropriately before rendering.
Change-Id: I8eaecf53e7f6a33d90da3d0047c5ceec89ea3af0
2013-04-17 18:54:38 -07:00
|
|
|
}
|
|
|
|
|
2011-12-13 13:11:32 -08:00
|
|
|
bool Caches::unbindIndicesBuffer() {
|
|
|
|
if (mCurrentIndicesBuffer) {
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
|
|
mCurrentIndicesBuffer = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-04-08 19:40:31 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// PBO
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
bool Caches::bindPixelBuffer(const GLuint buffer) {
|
|
|
|
if (mCurrentPixelBuffer != buffer) {
|
|
|
|
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer);
|
|
|
|
mCurrentPixelBuffer = buffer;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Caches::unbindPixelBuffer() {
|
|
|
|
if (mCurrentPixelBuffer) {
|
|
|
|
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
|
|
|
mCurrentPixelBuffer = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-13 20:26:50 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Meshes and textures
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-12-03 10:38:55 -08:00
|
|
|
void Caches::bindPositionVertexPointer(bool force, const GLvoid* vertices, GLsizei stride) {
|
2012-09-25 12:00:29 -07:00
|
|
|
if (force || vertices != mCurrentPositionPointer || stride != mCurrentPositionStride) {
|
|
|
|
GLuint slot = currentProgram->position;
|
2011-12-12 20:35:21 -08:00
|
|
|
glVertexAttribPointer(slot, 2, GL_FLOAT, GL_FALSE, stride, vertices);
|
|
|
|
mCurrentPositionPointer = vertices;
|
2012-09-25 12:00:29 -07:00
|
|
|
mCurrentPositionStride = stride;
|
2010-10-22 18:59:26 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-03 10:38:55 -08:00
|
|
|
void Caches::bindTexCoordsVertexPointer(bool force, const GLvoid* vertices, GLsizei stride) {
|
2013-02-13 18:39:43 -08:00
|
|
|
if (force || vertices != mCurrentTexCoordsPointer || stride != mCurrentTexCoordsStride) {
|
2012-09-25 12:00:29 -07:00
|
|
|
GLuint slot = currentProgram->texCoords;
|
2013-02-13 18:39:43 -08:00
|
|
|
glVertexAttribPointer(slot, 2, GL_FLOAT, GL_FALSE, stride, vertices);
|
2011-12-12 20:35:21 -08:00
|
|
|
mCurrentTexCoordsPointer = vertices;
|
2013-02-13 18:39:43 -08:00
|
|
|
mCurrentTexCoordsStride = stride;
|
2011-12-12 20:35:21 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Caches::resetVertexPointers() {
|
|
|
|
mCurrentPositionPointer = this;
|
|
|
|
mCurrentTexCoordsPointer = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Caches::resetTexCoordsVertexPointer() {
|
|
|
|
mCurrentTexCoordsPointer = this;
|
|
|
|
}
|
|
|
|
|
2011-12-13 13:11:32 -08:00
|
|
|
void Caches::enableTexCoordsVertexArray() {
|
|
|
|
if (!mTexCoordsArrayEnabled) {
|
|
|
|
glEnableVertexAttribArray(Program::kBindingTexCoords);
|
2011-12-13 18:39:19 -08:00
|
|
|
mCurrentTexCoordsPointer = this;
|
2011-12-13 13:11:32 -08:00
|
|
|
mTexCoordsArrayEnabled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-13 18:39:43 -08:00
|
|
|
void Caches::disableTexCoordsVertexArray() {
|
2011-12-13 13:11:32 -08:00
|
|
|
if (mTexCoordsArrayEnabled) {
|
|
|
|
glDisableVertexAttribArray(Program::kBindingTexCoords);
|
|
|
|
mTexCoordsArrayEnabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-13 14:55:06 -08:00
|
|
|
void Caches::activeTexture(GLuint textureUnit) {
|
|
|
|
if (mTextureUnit != textureUnit) {
|
|
|
|
glActiveTexture(gTextureUnits[textureUnit]);
|
|
|
|
mTextureUnit = textureUnit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-22 16:16:06 -07:00
|
|
|
void Caches::resetActiveTexture() {
|
|
|
|
mTextureUnit = -1;
|
|
|
|
}
|
|
|
|
|
2013-06-04 18:00:09 -07:00
|
|
|
void Caches::bindTexture(GLuint texture) {
|
|
|
|
if (mBoundTextures[mTextureUnit] != texture) {
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture);
|
|
|
|
mBoundTextures[mTextureUnit] = texture;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Caches::bindTexture(GLenum target, GLuint texture) {
|
|
|
|
if (mBoundTextures[mTextureUnit] != texture) {
|
|
|
|
glBindTexture(target, texture);
|
|
|
|
mBoundTextures[mTextureUnit] = texture;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-06 14:02:54 -07:00
|
|
|
void Caches::deleteTexture(GLuint texture) {
|
|
|
|
// When glDeleteTextures() is called on a currently bound texture,
|
|
|
|
// OpenGL ES specifies that the texture is then considered unbound
|
|
|
|
// Consider the following series of calls:
|
|
|
|
//
|
|
|
|
// glGenTextures -> creates texture name 2
|
|
|
|
// glBindTexture(2)
|
|
|
|
// glDeleteTextures(2) -> 2 is now unbound
|
|
|
|
// glGenTextures -> can return 2 again
|
|
|
|
//
|
|
|
|
// If we don't call glBindTexture(2) after the second glGenTextures
|
|
|
|
// call, any texture operation will be performed on the default
|
|
|
|
// texture (name=0)
|
|
|
|
|
|
|
|
for (int i = 0; i < REQUIRED_TEXTURE_UNITS_COUNT; i++) {
|
|
|
|
if (mBoundTextures[i] == texture) {
|
|
|
|
mBoundTextures[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
glDeleteTextures(1, &texture);
|
|
|
|
}
|
|
|
|
|
2013-06-04 18:00:09 -07:00
|
|
|
void Caches::resetBoundTextures() {
|
|
|
|
memset(mBoundTextures, 0, REQUIRED_TEXTURE_UNITS_COUNT * sizeof(GLuint));
|
|
|
|
}
|
|
|
|
|
2012-09-13 20:26:50 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Scissor
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-07-17 17:32:48 -07:00
|
|
|
bool Caches::setScissor(GLint x, GLint y, GLint width, GLint height) {
|
2012-07-13 15:28:31 -07:00
|
|
|
if (scissorEnabled && (x != mScissorX || y != mScissorY ||
|
|
|
|
width != mScissorWidth || height != mScissorHeight)) {
|
|
|
|
|
2012-10-16 17:36:16 -07:00
|
|
|
if (x < 0) {
|
|
|
|
width += x;
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
if (y < 0) {
|
|
|
|
height += y;
|
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
if (width < 0) {
|
|
|
|
width = 0;
|
|
|
|
}
|
|
|
|
if (height < 0) {
|
|
|
|
height = 0;
|
|
|
|
}
|
2011-12-14 19:23:32 -08:00
|
|
|
glScissor(x, y, width, height);
|
|
|
|
|
|
|
|
mScissorX = x;
|
|
|
|
mScissorY = y;
|
|
|
|
mScissorWidth = width;
|
|
|
|
mScissorHeight = height;
|
2012-07-17 17:32:48 -07:00
|
|
|
|
|
|
|
return true;
|
2011-12-14 19:23:32 -08:00
|
|
|
}
|
2012-07-17 17:32:48 -07:00
|
|
|
return false;
|
2011-12-14 19:23:32 -08:00
|
|
|
}
|
|
|
|
|
2012-07-17 17:32:48 -07:00
|
|
|
bool Caches::enableScissor() {
|
2012-07-13 15:28:31 -07:00
|
|
|
if (!scissorEnabled) {
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
scissorEnabled = true;
|
2012-10-07 14:05:59 -07:00
|
|
|
resetScissor();
|
2012-07-17 17:32:48 -07:00
|
|
|
return true;
|
2012-07-13 15:28:31 -07:00
|
|
|
}
|
2012-07-17 17:32:48 -07:00
|
|
|
return false;
|
2012-07-13 15:28:31 -07:00
|
|
|
}
|
|
|
|
|
2012-07-17 17:32:48 -07:00
|
|
|
bool Caches::disableScissor() {
|
2012-07-13 15:28:31 -07:00
|
|
|
if (scissorEnabled) {
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
scissorEnabled = false;
|
2012-07-17 17:32:48 -07:00
|
|
|
return true;
|
2012-07-13 15:28:31 -07:00
|
|
|
}
|
2012-07-17 17:32:48 -07:00
|
|
|
return false;
|
2012-07-13 15:28:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void Caches::setScissorEnabled(bool enabled) {
|
|
|
|
if (scissorEnabled != enabled) {
|
|
|
|
if (enabled) glEnable(GL_SCISSOR_TEST);
|
|
|
|
else glDisable(GL_SCISSOR_TEST);
|
|
|
|
scissorEnabled = enabled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-03 14:13:39 -08:00
|
|
|
void Caches::resetScissor() {
|
|
|
|
mScissorX = mScissorY = mScissorWidth = mScissorHeight = 0;
|
|
|
|
}
|
|
|
|
|
2012-09-13 20:26:50 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Tiling
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-01-31 17:45:55 -08:00
|
|
|
void Caches::startTiling(GLuint x, GLuint y, GLuint width, GLuint height, bool discard) {
|
2013-02-06 16:51:04 -08:00
|
|
|
if (mExtensions.hasTiledRendering() && !debugOverdraw) {
|
2013-01-31 17:45:55 -08:00
|
|
|
glStartTilingQCOM(x, y, width, height, (discard ? GL_NONE : GL_COLOR_BUFFER_BIT0_QCOM));
|
2012-09-13 20:26:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Caches::endTiling() {
|
2013-02-06 16:51:04 -08:00
|
|
|
if (mExtensions.hasTiledRendering() && !debugOverdraw) {
|
2012-09-19 17:25:38 -07:00
|
|
|
glEndTilingQCOM(GL_COLOR_BUFFER_BIT0_QCOM);
|
2012-09-13 20:26:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-27 17:55:46 -07:00
|
|
|
bool Caches::hasRegisteredFunctors() {
|
|
|
|
return mFunctorsCount > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Caches::registerFunctors(uint32_t functorCount) {
|
|
|
|
mFunctorsCount += functorCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Caches::unregisterFunctors(uint32_t functorCount) {
|
|
|
|
if (functorCount > mFunctorsCount) {
|
|
|
|
mFunctorsCount = 0;
|
|
|
|
} else {
|
|
|
|
mFunctorsCount -= functorCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-13 20:26:50 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Regions
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-10-27 18:57:51 -07:00
|
|
|
TextureVertex* Caches::getRegionMesh() {
|
|
|
|
// Create the mesh, 2 triangles and 4 vertices per rectangle in the region
|
|
|
|
if (!mRegionMesh) {
|
2013-06-18 15:53:53 -07:00
|
|
|
mRegionMesh = new TextureVertex[gMaxNumberOfQuads * 4];
|
2010-10-27 18:57:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return mRegionMesh;
|
|
|
|
}
|
|
|
|
|
2013-12-15 17:10:19 -08:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Temporary Properties
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void Caches::initTempProperties() {
|
2014-03-07 18:27:49 -08:00
|
|
|
propertyAmbientShadowStrength = 25;
|
|
|
|
propertySpotShadowStrength = 25;
|
2014-01-17 10:34:10 -08:00
|
|
|
|
|
|
|
propertyLightPosXScale = 0.5f;
|
|
|
|
propertyLightPosYScale = 0.0f;
|
|
|
|
propertyLightPosZScale = 1.0f;
|
2013-12-15 17:10:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Caches::setTempProperty(const char* name, const char* value) {
|
|
|
|
ALOGD("setting property %s to %s", name, value);
|
2014-03-11 10:48:43 -07:00
|
|
|
if (!strcmp(name, "ambientShadowStrength")) {
|
2014-02-13 17:09:45 -08:00
|
|
|
propertyAmbientShadowStrength = atoi(value);
|
|
|
|
ALOGD("ambient shadow strength = 0x%x out of 0xff", propertyAmbientShadowStrength);
|
|
|
|
return;
|
|
|
|
} else if (!strcmp(name, "spotShadowStrength")) {
|
|
|
|
propertySpotShadowStrength = atoi(value);
|
|
|
|
ALOGD("spot shadow strength = 0x%x out of 0xff", propertySpotShadowStrength);
|
2013-12-15 17:10:19 -08:00
|
|
|
return;
|
2014-01-17 10:34:10 -08:00
|
|
|
} else if (!strcmp(name, "lightPosXScale")) {
|
|
|
|
propertyLightPosXScale = fmin(fmax(atof(value), 0.0), 1.0);
|
|
|
|
ALOGD("lightPos X Scale = %.2f", propertyLightPosXScale);
|
|
|
|
return;
|
|
|
|
} else if (!strcmp(name, "lightPosYScale")) {
|
|
|
|
propertyLightPosYScale = fmin(fmax(atof(value), 0.0), 1.0);
|
|
|
|
ALOGD("lightPos Y Scale = %.2f", propertyLightPosXScale);
|
|
|
|
return;
|
|
|
|
} else if (!strcmp(name, "lightPosZScale")) {
|
|
|
|
propertyLightPosZScale = fmin(fmax(atof(value), 0.0), 1.0);
|
|
|
|
ALOGD("lightPos Z Scale = %.2f", propertyLightPosXScale);
|
|
|
|
return;
|
2013-12-15 17:10:19 -08:00
|
|
|
}
|
|
|
|
ALOGD(" failed");
|
|
|
|
}
|
|
|
|
|
2010-10-22 18:59:26 -07:00
|
|
|
}; // namespace uirenderer
|
|
|
|
}; // namespace android
|