2010-06-29 21:05:21 -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-07-01 18:26:52 -07:00
|
|
|
#define LOG_TAG "OpenGLRenderer"
|
2014-07-29 09:49:13 -07:00
|
|
|
#define ATRACE_TAG ATRACE_TAG_VIEW
|
2010-07-01 18:26:52 -07:00
|
|
|
|
2010-06-29 21:05:21 -07:00
|
|
|
#include <GLES2/gl2.h>
|
|
|
|
|
2010-10-05 14:58:09 -07:00
|
|
|
#include <SkCanvas.h>
|
|
|
|
|
2013-03-08 17:44:20 -08:00
|
|
|
#include <utils/Mutex.h>
|
2010-09-08 15:15:43 -07:00
|
|
|
|
2012-10-16 18:44:09 -07:00
|
|
|
#include "Caches.h"
|
2010-06-29 21:05:21 -07:00
|
|
|
#include "TextureCache.h"
|
2010-08-23 21:05:08 -07:00
|
|
|
#include "Properties.h"
|
2010-06-29 21:05:21 -07:00
|
|
|
|
|
|
|
namespace android {
|
|
|
|
namespace uirenderer {
|
|
|
|
|
2010-07-01 18:26:52 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Constructors/destructor
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-08-23 21:05:08 -07:00
|
|
|
TextureCache::TextureCache():
|
Inspect SkShader to determine hw shader.
Instead of duplicating internal info about SkShader, inspect the
SkShader installed on the SkPaint.
core/java/android/view/GLES20Canvas.java:
Remove setupModifiers, nResetModifiers, and nSetupShader.
core/jni/android/graphics/Shader.cpp:
Remove calls to create/destroy the (previously) attached SkiaShader.
core/jni/android_view_GLES20Canvas.cpp:
Remove native code for setupShader and resetModifiers.
graphics/java/android/graphics/BitmapShader.java:
graphics/java/android/graphics/ComposeShader.java:
graphics/java/android/graphics/LinearGradient.java:
graphics/java/android/graphics/RadialGradient.java:
graphics/java/android/graphics/Shader.java:
graphics/java/android/graphics/SweepGradient.java:
Remove code keeping track of native SkiaShader.
libs/hwui/Caches.h:
Include Extensions.h.
libs/hwui/DeferredDisplayList.cpp:
Compare shaders on the paint, instead of on DrawModifiers.
libs/hwui/DisplayList.cpp:
libs/hwui/DisplayList.h:
Remove vector of SkiaShaders.
libs/hwui/DisplayListOp.h:
Access the SkShader on mPaint.
Remove SetupShaderOp and ResetShaderOp.
libs/hwui/DisplayListRenderer.cpp:
libs/hwui/DisplayListRenderer.h:
Remove resetShader, setupShader, refShader, and mShaderMap.
libs/hwui/FontRenderer.cpp:
Pass SkShader to setupDrawShader and setupDrawShaderUniforms.
libs/hwui/OpenGLRenderer.cpp:
libs/hwui/OpenGLRenderer.h:
Add LayerShader, a class inheriting from SkShader, to mimic the
behavior of SkiaLayerShader. Unlike SkiaLayerShader, it can be set on
the SkPaint so it can be inspected later.
Set a LayerShader instead of a SkiaLayerShader.
setupDrawShader and setupDrawShaderUniforms now inspect an SkShader
passed in.
Inspect SkShader instead of mDrawModifiers.mShader.
Remove resetShader and setupShader.
setupDrawColorUniforms now takes a boolean indicating whether there is
a shader.
Add an inline function for accessing the SkShader on an SkPaint.
In setupDrawBlending(Layer*, bool), do not check the shader (which will
never be set), but do check whether the color filter may change the
alpha (newly fixed behavior).
In setupDrawBlending(SkPaint, ...), check the SkShader and whether the
color filter affects alpha (the latter is new behavior).
libs/hwui/Renderer.h:
Remove pure virtual functions setupShader and resetShader.
libs/hwui/ResourceCache.cpp:
libs/hwui/ResourceCache.h:
Remove functions for refing/unrefing shaders.
libs/hwui/SkiaShader.cpp:
libs/hwui/SkiaShader.h:
Much of this code was redundant and has been removed.
Convert structs into class with nothing but static functions for
calling describe/setupProgram.
libs/hwui/TextureCache.cpp:
libs/hwui/TextureCache.h:
Use the SkPixelRef as the key to the bitmap Lru cache, since shader
inspection will provide a different SkBitmap pointer (though it will
hold the correct SkPixelRef with the correct generation ID).
tests/CanvasCompare/src/com/android/test/hwuicompare/DisplayModifier.java:
tests/CanvasCompare/src/com/android/test/hwuicompare/ResourceModifiers.java:
Update manual test to have more shaders: radial, sweep, compose,
invalid compose.
BUG:10650594
Change-Id: Iaa7189178bda1c55f96da044d2a9fa602ba36034
2014-05-05 12:50:38 -04:00
|
|
|
mCache(LruCache<const SkPixelRef*, Texture*>::kUnlimitedCapacity),
|
2011-11-04 15:12:29 -07:00
|
|
|
mSize(0), mMaxSize(MB(DEFAULT_TEXTURE_CACHE_SIZE)),
|
|
|
|
mFlushRate(DEFAULT_TEXTURE_CACHE_FLUSH_RATE) {
|
2010-08-23 21:05:08 -07:00
|
|
|
char property[PROPERTY_VALUE_MAX];
|
|
|
|
if (property_get(PROPERTY_TEXTURE_CACHE_SIZE, property, NULL) > 0) {
|
2011-01-21 21:14:15 -08:00
|
|
|
INIT_LOGD(" Setting texture cache size to %sMB", property);
|
2010-08-23 21:05:08 -07:00
|
|
|
setMaxSize(MB(atof(property)));
|
|
|
|
} else {
|
2011-01-21 21:14:15 -08:00
|
|
|
INIT_LOGD(" Using default texture cache size of %.2fMB", DEFAULT_TEXTURE_CACHE_SIZE);
|
2010-08-23 21:05:08 -07:00
|
|
|
}
|
|
|
|
|
2011-11-04 15:12:29 -07:00
|
|
|
if (property_get(PROPERTY_TEXTURE_CACHE_FLUSH_RATE, property, NULL) > 0) {
|
|
|
|
float flushRate = atof(property);
|
|
|
|
INIT_LOGD(" Setting texture cache flush rate to %.2f%%", flushRate * 100.0f);
|
|
|
|
setFlushRate(flushRate);
|
|
|
|
} else {
|
|
|
|
INIT_LOGD(" Using default texture cache flush rate of %.2f%%",
|
|
|
|
DEFAULT_TEXTURE_CACHE_FLUSH_RATE * 100.0f);
|
|
|
|
}
|
|
|
|
|
2010-08-23 21:05:08 -07:00
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
2010-07-02 11:20:34 -07:00
|
|
|
TextureCache::TextureCache(uint32_t maxByteSize):
|
Inspect SkShader to determine hw shader.
Instead of duplicating internal info about SkShader, inspect the
SkShader installed on the SkPaint.
core/java/android/view/GLES20Canvas.java:
Remove setupModifiers, nResetModifiers, and nSetupShader.
core/jni/android/graphics/Shader.cpp:
Remove calls to create/destroy the (previously) attached SkiaShader.
core/jni/android_view_GLES20Canvas.cpp:
Remove native code for setupShader and resetModifiers.
graphics/java/android/graphics/BitmapShader.java:
graphics/java/android/graphics/ComposeShader.java:
graphics/java/android/graphics/LinearGradient.java:
graphics/java/android/graphics/RadialGradient.java:
graphics/java/android/graphics/Shader.java:
graphics/java/android/graphics/SweepGradient.java:
Remove code keeping track of native SkiaShader.
libs/hwui/Caches.h:
Include Extensions.h.
libs/hwui/DeferredDisplayList.cpp:
Compare shaders on the paint, instead of on DrawModifiers.
libs/hwui/DisplayList.cpp:
libs/hwui/DisplayList.h:
Remove vector of SkiaShaders.
libs/hwui/DisplayListOp.h:
Access the SkShader on mPaint.
Remove SetupShaderOp and ResetShaderOp.
libs/hwui/DisplayListRenderer.cpp:
libs/hwui/DisplayListRenderer.h:
Remove resetShader, setupShader, refShader, and mShaderMap.
libs/hwui/FontRenderer.cpp:
Pass SkShader to setupDrawShader and setupDrawShaderUniforms.
libs/hwui/OpenGLRenderer.cpp:
libs/hwui/OpenGLRenderer.h:
Add LayerShader, a class inheriting from SkShader, to mimic the
behavior of SkiaLayerShader. Unlike SkiaLayerShader, it can be set on
the SkPaint so it can be inspected later.
Set a LayerShader instead of a SkiaLayerShader.
setupDrawShader and setupDrawShaderUniforms now inspect an SkShader
passed in.
Inspect SkShader instead of mDrawModifiers.mShader.
Remove resetShader and setupShader.
setupDrawColorUniforms now takes a boolean indicating whether there is
a shader.
Add an inline function for accessing the SkShader on an SkPaint.
In setupDrawBlending(Layer*, bool), do not check the shader (which will
never be set), but do check whether the color filter may change the
alpha (newly fixed behavior).
In setupDrawBlending(SkPaint, ...), check the SkShader and whether the
color filter affects alpha (the latter is new behavior).
libs/hwui/Renderer.h:
Remove pure virtual functions setupShader and resetShader.
libs/hwui/ResourceCache.cpp:
libs/hwui/ResourceCache.h:
Remove functions for refing/unrefing shaders.
libs/hwui/SkiaShader.cpp:
libs/hwui/SkiaShader.h:
Much of this code was redundant and has been removed.
Convert structs into class with nothing but static functions for
calling describe/setupProgram.
libs/hwui/TextureCache.cpp:
libs/hwui/TextureCache.h:
Use the SkPixelRef as the key to the bitmap Lru cache, since shader
inspection will provide a different SkBitmap pointer (though it will
hold the correct SkPixelRef with the correct generation ID).
tests/CanvasCompare/src/com/android/test/hwuicompare/DisplayModifier.java:
tests/CanvasCompare/src/com/android/test/hwuicompare/ResourceModifiers.java:
Update manual test to have more shaders: radial, sweep, compose,
invalid compose.
BUG:10650594
Change-Id: Iaa7189178bda1c55f96da044d2a9fa602ba36034
2014-05-05 12:50:38 -04:00
|
|
|
mCache(LruCache<const SkPixelRef*, Texture*>::kUnlimitedCapacity),
|
2010-07-01 18:26:52 -07:00
|
|
|
mSize(0), mMaxSize(maxByteSize) {
|
2010-08-23 21:05:08 -07:00
|
|
|
init();
|
2010-06-29 21:05:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TextureCache::~TextureCache() {
|
|
|
|
mCache.clear();
|
|
|
|
}
|
|
|
|
|
2010-08-23 21:05:08 -07:00
|
|
|
void TextureCache::init() {
|
|
|
|
mCache.setOnEntryRemovedListener(this);
|
|
|
|
|
|
|
|
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
|
2011-01-23 13:32:12 -08:00
|
|
|
INIT_LOGD(" Maximum texture dimension is %d pixels", mMaxTextureSize);
|
2010-11-10 19:01:29 -08:00
|
|
|
|
|
|
|
mDebugEnabled = readDebugLevel() & kDebugCaches;
|
2010-08-23 21:05:08 -07:00
|
|
|
}
|
|
|
|
|
2010-07-01 18:26:52 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Size management
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-07-02 11:20:34 -07:00
|
|
|
uint32_t TextureCache::getSize() {
|
2010-07-01 18:26:52 -07:00
|
|
|
return mSize;
|
|
|
|
}
|
|
|
|
|
2010-07-02 11:20:34 -07:00
|
|
|
uint32_t TextureCache::getMaxSize() {
|
2010-07-01 18:26:52 -07:00
|
|
|
return mMaxSize;
|
|
|
|
}
|
|
|
|
|
2010-07-02 11:20:34 -07:00
|
|
|
void TextureCache::setMaxSize(uint32_t maxSize) {
|
2010-07-01 18:26:52 -07:00
|
|
|
mMaxSize = maxSize;
|
|
|
|
while (mSize > mMaxSize) {
|
|
|
|
mCache.removeOldest();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-04 15:12:29 -07:00
|
|
|
void TextureCache::setFlushRate(float flushRate) {
|
|
|
|
mFlushRate = fmaxf(0.0f, fminf(1.0f, flushRate));
|
|
|
|
}
|
|
|
|
|
2010-07-01 18:26:52 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Callbacks
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
Inspect SkShader to determine hw shader.
Instead of duplicating internal info about SkShader, inspect the
SkShader installed on the SkPaint.
core/java/android/view/GLES20Canvas.java:
Remove setupModifiers, nResetModifiers, and nSetupShader.
core/jni/android/graphics/Shader.cpp:
Remove calls to create/destroy the (previously) attached SkiaShader.
core/jni/android_view_GLES20Canvas.cpp:
Remove native code for setupShader and resetModifiers.
graphics/java/android/graphics/BitmapShader.java:
graphics/java/android/graphics/ComposeShader.java:
graphics/java/android/graphics/LinearGradient.java:
graphics/java/android/graphics/RadialGradient.java:
graphics/java/android/graphics/Shader.java:
graphics/java/android/graphics/SweepGradient.java:
Remove code keeping track of native SkiaShader.
libs/hwui/Caches.h:
Include Extensions.h.
libs/hwui/DeferredDisplayList.cpp:
Compare shaders on the paint, instead of on DrawModifiers.
libs/hwui/DisplayList.cpp:
libs/hwui/DisplayList.h:
Remove vector of SkiaShaders.
libs/hwui/DisplayListOp.h:
Access the SkShader on mPaint.
Remove SetupShaderOp and ResetShaderOp.
libs/hwui/DisplayListRenderer.cpp:
libs/hwui/DisplayListRenderer.h:
Remove resetShader, setupShader, refShader, and mShaderMap.
libs/hwui/FontRenderer.cpp:
Pass SkShader to setupDrawShader and setupDrawShaderUniforms.
libs/hwui/OpenGLRenderer.cpp:
libs/hwui/OpenGLRenderer.h:
Add LayerShader, a class inheriting from SkShader, to mimic the
behavior of SkiaLayerShader. Unlike SkiaLayerShader, it can be set on
the SkPaint so it can be inspected later.
Set a LayerShader instead of a SkiaLayerShader.
setupDrawShader and setupDrawShaderUniforms now inspect an SkShader
passed in.
Inspect SkShader instead of mDrawModifiers.mShader.
Remove resetShader and setupShader.
setupDrawColorUniforms now takes a boolean indicating whether there is
a shader.
Add an inline function for accessing the SkShader on an SkPaint.
In setupDrawBlending(Layer*, bool), do not check the shader (which will
never be set), but do check whether the color filter may change the
alpha (newly fixed behavior).
In setupDrawBlending(SkPaint, ...), check the SkShader and whether the
color filter affects alpha (the latter is new behavior).
libs/hwui/Renderer.h:
Remove pure virtual functions setupShader and resetShader.
libs/hwui/ResourceCache.cpp:
libs/hwui/ResourceCache.h:
Remove functions for refing/unrefing shaders.
libs/hwui/SkiaShader.cpp:
libs/hwui/SkiaShader.h:
Much of this code was redundant and has been removed.
Convert structs into class with nothing but static functions for
calling describe/setupProgram.
libs/hwui/TextureCache.cpp:
libs/hwui/TextureCache.h:
Use the SkPixelRef as the key to the bitmap Lru cache, since shader
inspection will provide a different SkBitmap pointer (though it will
hold the correct SkPixelRef with the correct generation ID).
tests/CanvasCompare/src/com/android/test/hwuicompare/DisplayModifier.java:
tests/CanvasCompare/src/com/android/test/hwuicompare/ResourceModifiers.java:
Update manual test to have more shaders: radial, sweep, compose,
invalid compose.
BUG:10650594
Change-Id: Iaa7189178bda1c55f96da044d2a9fa602ba36034
2014-05-05 12:50:38 -04:00
|
|
|
void TextureCache::operator()(const SkPixelRef*&, Texture*& texture) {
|
2010-09-08 15:15:43 -07:00
|
|
|
// This will be called already locked
|
2010-07-01 18:26:52 -07:00
|
|
|
if (texture) {
|
2010-09-08 15:15:43 -07:00
|
|
|
mSize -= texture->bitmapSize;
|
2010-11-09 14:35:20 -08:00
|
|
|
TEXTURE_LOGD("TextureCache::callback: name, removed size, mSize = %d, %d, %d",
|
|
|
|
texture->id, texture->bitmapSize, mSize);
|
2010-11-10 19:01:29 -08:00
|
|
|
if (mDebugEnabled) {
|
2011-12-20 16:23:08 +00:00
|
|
|
ALOGD("Texture deleted, size = %d", texture->bitmapSize);
|
2010-11-10 19:01:29 -08:00
|
|
|
}
|
2013-06-06 14:02:54 -07:00
|
|
|
texture->deleteTexture();
|
2010-07-01 18:26:52 -07:00
|
|
|
delete texture;
|
2010-06-29 21:05:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-01 18:26:52 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Caching
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-04-11 19:15:05 -07:00
|
|
|
void TextureCache::resetMarkInUse() {
|
Inspect SkShader to determine hw shader.
Instead of duplicating internal info about SkShader, inspect the
SkShader installed on the SkPaint.
core/java/android/view/GLES20Canvas.java:
Remove setupModifiers, nResetModifiers, and nSetupShader.
core/jni/android/graphics/Shader.cpp:
Remove calls to create/destroy the (previously) attached SkiaShader.
core/jni/android_view_GLES20Canvas.cpp:
Remove native code for setupShader and resetModifiers.
graphics/java/android/graphics/BitmapShader.java:
graphics/java/android/graphics/ComposeShader.java:
graphics/java/android/graphics/LinearGradient.java:
graphics/java/android/graphics/RadialGradient.java:
graphics/java/android/graphics/Shader.java:
graphics/java/android/graphics/SweepGradient.java:
Remove code keeping track of native SkiaShader.
libs/hwui/Caches.h:
Include Extensions.h.
libs/hwui/DeferredDisplayList.cpp:
Compare shaders on the paint, instead of on DrawModifiers.
libs/hwui/DisplayList.cpp:
libs/hwui/DisplayList.h:
Remove vector of SkiaShaders.
libs/hwui/DisplayListOp.h:
Access the SkShader on mPaint.
Remove SetupShaderOp and ResetShaderOp.
libs/hwui/DisplayListRenderer.cpp:
libs/hwui/DisplayListRenderer.h:
Remove resetShader, setupShader, refShader, and mShaderMap.
libs/hwui/FontRenderer.cpp:
Pass SkShader to setupDrawShader and setupDrawShaderUniforms.
libs/hwui/OpenGLRenderer.cpp:
libs/hwui/OpenGLRenderer.h:
Add LayerShader, a class inheriting from SkShader, to mimic the
behavior of SkiaLayerShader. Unlike SkiaLayerShader, it can be set on
the SkPaint so it can be inspected later.
Set a LayerShader instead of a SkiaLayerShader.
setupDrawShader and setupDrawShaderUniforms now inspect an SkShader
passed in.
Inspect SkShader instead of mDrawModifiers.mShader.
Remove resetShader and setupShader.
setupDrawColorUniforms now takes a boolean indicating whether there is
a shader.
Add an inline function for accessing the SkShader on an SkPaint.
In setupDrawBlending(Layer*, bool), do not check the shader (which will
never be set), but do check whether the color filter may change the
alpha (newly fixed behavior).
In setupDrawBlending(SkPaint, ...), check the SkShader and whether the
color filter affects alpha (the latter is new behavior).
libs/hwui/Renderer.h:
Remove pure virtual functions setupShader and resetShader.
libs/hwui/ResourceCache.cpp:
libs/hwui/ResourceCache.h:
Remove functions for refing/unrefing shaders.
libs/hwui/SkiaShader.cpp:
libs/hwui/SkiaShader.h:
Much of this code was redundant and has been removed.
Convert structs into class with nothing but static functions for
calling describe/setupProgram.
libs/hwui/TextureCache.cpp:
libs/hwui/TextureCache.h:
Use the SkPixelRef as the key to the bitmap Lru cache, since shader
inspection will provide a different SkBitmap pointer (though it will
hold the correct SkPixelRef with the correct generation ID).
tests/CanvasCompare/src/com/android/test/hwuicompare/DisplayModifier.java:
tests/CanvasCompare/src/com/android/test/hwuicompare/ResourceModifiers.java:
Update manual test to have more shaders: radial, sweep, compose,
invalid compose.
BUG:10650594
Change-Id: Iaa7189178bda1c55f96da044d2a9fa602ba36034
2014-05-05 12:50:38 -04:00
|
|
|
LruCache<const SkPixelRef*, Texture*>::Iterator iter(mCache);
|
2014-04-11 19:15:05 -07:00
|
|
|
while (iter.next()) {
|
|
|
|
iter.value()->isInUse = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TextureCache::canMakeTextureFromBitmap(const SkBitmap* bitmap) {
|
|
|
|
if (bitmap->width() > mMaxTextureSize || bitmap->height() > mMaxTextureSize) {
|
|
|
|
ALOGW("Bitmap too large to be uploaded into a texture (%dx%d, max=%dx%d)",
|
|
|
|
bitmap->width(), bitmap->height(), mMaxTextureSize, mMaxTextureSize);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns a prepared Texture* that either is already in the cache or can fit
|
|
|
|
// in the cache (and is thus added to the cache)
|
|
|
|
Texture* TextureCache::getCachedTexture(const SkBitmap* bitmap) {
|
Inspect SkShader to determine hw shader.
Instead of duplicating internal info about SkShader, inspect the
SkShader installed on the SkPaint.
core/java/android/view/GLES20Canvas.java:
Remove setupModifiers, nResetModifiers, and nSetupShader.
core/jni/android/graphics/Shader.cpp:
Remove calls to create/destroy the (previously) attached SkiaShader.
core/jni/android_view_GLES20Canvas.cpp:
Remove native code for setupShader and resetModifiers.
graphics/java/android/graphics/BitmapShader.java:
graphics/java/android/graphics/ComposeShader.java:
graphics/java/android/graphics/LinearGradient.java:
graphics/java/android/graphics/RadialGradient.java:
graphics/java/android/graphics/Shader.java:
graphics/java/android/graphics/SweepGradient.java:
Remove code keeping track of native SkiaShader.
libs/hwui/Caches.h:
Include Extensions.h.
libs/hwui/DeferredDisplayList.cpp:
Compare shaders on the paint, instead of on DrawModifiers.
libs/hwui/DisplayList.cpp:
libs/hwui/DisplayList.h:
Remove vector of SkiaShaders.
libs/hwui/DisplayListOp.h:
Access the SkShader on mPaint.
Remove SetupShaderOp and ResetShaderOp.
libs/hwui/DisplayListRenderer.cpp:
libs/hwui/DisplayListRenderer.h:
Remove resetShader, setupShader, refShader, and mShaderMap.
libs/hwui/FontRenderer.cpp:
Pass SkShader to setupDrawShader and setupDrawShaderUniforms.
libs/hwui/OpenGLRenderer.cpp:
libs/hwui/OpenGLRenderer.h:
Add LayerShader, a class inheriting from SkShader, to mimic the
behavior of SkiaLayerShader. Unlike SkiaLayerShader, it can be set on
the SkPaint so it can be inspected later.
Set a LayerShader instead of a SkiaLayerShader.
setupDrawShader and setupDrawShaderUniforms now inspect an SkShader
passed in.
Inspect SkShader instead of mDrawModifiers.mShader.
Remove resetShader and setupShader.
setupDrawColorUniforms now takes a boolean indicating whether there is
a shader.
Add an inline function for accessing the SkShader on an SkPaint.
In setupDrawBlending(Layer*, bool), do not check the shader (which will
never be set), but do check whether the color filter may change the
alpha (newly fixed behavior).
In setupDrawBlending(SkPaint, ...), check the SkShader and whether the
color filter affects alpha (the latter is new behavior).
libs/hwui/Renderer.h:
Remove pure virtual functions setupShader and resetShader.
libs/hwui/ResourceCache.cpp:
libs/hwui/ResourceCache.h:
Remove functions for refing/unrefing shaders.
libs/hwui/SkiaShader.cpp:
libs/hwui/SkiaShader.h:
Much of this code was redundant and has been removed.
Convert structs into class with nothing but static functions for
calling describe/setupProgram.
libs/hwui/TextureCache.cpp:
libs/hwui/TextureCache.h:
Use the SkPixelRef as the key to the bitmap Lru cache, since shader
inspection will provide a different SkBitmap pointer (though it will
hold the correct SkPixelRef with the correct generation ID).
tests/CanvasCompare/src/com/android/test/hwuicompare/DisplayModifier.java:
tests/CanvasCompare/src/com/android/test/hwuicompare/ResourceModifiers.java:
Update manual test to have more shaders: radial, sweep, compose,
invalid compose.
BUG:10650594
Change-Id: Iaa7189178bda1c55f96da044d2a9fa602ba36034
2014-05-05 12:50:38 -04:00
|
|
|
Texture* texture = mCache.get(bitmap->pixelRef());
|
2010-09-08 18:04:33 -07:00
|
|
|
|
2010-06-29 21:05:21 -07:00
|
|
|
if (!texture) {
|
2014-04-11 19:15:05 -07:00
|
|
|
if (!canMakeTextureFromBitmap(bitmap)) {
|
2010-08-07 23:46:15 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-07-02 11:20:34 -07:00
|
|
|
const uint32_t size = bitmap->rowBytes() * bitmap->height();
|
2014-04-11 19:15:05 -07:00
|
|
|
bool canCache = size < mMaxSize;
|
2010-07-01 18:26:52 -07:00
|
|
|
// Don't even try to cache a bitmap that's bigger than the cache
|
2014-04-11 19:15:05 -07:00
|
|
|
while (canCache && mSize + size > mMaxSize) {
|
|
|
|
Texture* oldest = mCache.peekOldestValue();
|
|
|
|
if (oldest && !oldest->isInUse) {
|
2010-07-01 18:26:52 -07:00
|
|
|
mCache.removeOldest();
|
2014-04-11 19:15:05 -07:00
|
|
|
} else {
|
|
|
|
canCache = false;
|
2010-07-01 18:26:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-11 19:15:05 -07:00
|
|
|
if (canCache) {
|
|
|
|
texture = new Texture();
|
|
|
|
texture->bitmapSize = size;
|
|
|
|
generateTexture(bitmap, texture, false);
|
2010-07-01 18:26:52 -07:00
|
|
|
|
|
|
|
mSize += size;
|
2010-11-09 14:35:20 -08:00
|
|
|
TEXTURE_LOGD("TextureCache::get: create texture(%p): name, size, mSize = %d, %d, %d",
|
|
|
|
bitmap, texture->id, size, mSize);
|
2010-11-10 19:01:29 -08:00
|
|
|
if (mDebugEnabled) {
|
2011-12-20 16:23:08 +00:00
|
|
|
ALOGD("Texture created, size = %d", size);
|
2010-11-10 19:01:29 -08:00
|
|
|
}
|
Inspect SkShader to determine hw shader.
Instead of duplicating internal info about SkShader, inspect the
SkShader installed on the SkPaint.
core/java/android/view/GLES20Canvas.java:
Remove setupModifiers, nResetModifiers, and nSetupShader.
core/jni/android/graphics/Shader.cpp:
Remove calls to create/destroy the (previously) attached SkiaShader.
core/jni/android_view_GLES20Canvas.cpp:
Remove native code for setupShader and resetModifiers.
graphics/java/android/graphics/BitmapShader.java:
graphics/java/android/graphics/ComposeShader.java:
graphics/java/android/graphics/LinearGradient.java:
graphics/java/android/graphics/RadialGradient.java:
graphics/java/android/graphics/Shader.java:
graphics/java/android/graphics/SweepGradient.java:
Remove code keeping track of native SkiaShader.
libs/hwui/Caches.h:
Include Extensions.h.
libs/hwui/DeferredDisplayList.cpp:
Compare shaders on the paint, instead of on DrawModifiers.
libs/hwui/DisplayList.cpp:
libs/hwui/DisplayList.h:
Remove vector of SkiaShaders.
libs/hwui/DisplayListOp.h:
Access the SkShader on mPaint.
Remove SetupShaderOp and ResetShaderOp.
libs/hwui/DisplayListRenderer.cpp:
libs/hwui/DisplayListRenderer.h:
Remove resetShader, setupShader, refShader, and mShaderMap.
libs/hwui/FontRenderer.cpp:
Pass SkShader to setupDrawShader and setupDrawShaderUniforms.
libs/hwui/OpenGLRenderer.cpp:
libs/hwui/OpenGLRenderer.h:
Add LayerShader, a class inheriting from SkShader, to mimic the
behavior of SkiaLayerShader. Unlike SkiaLayerShader, it can be set on
the SkPaint so it can be inspected later.
Set a LayerShader instead of a SkiaLayerShader.
setupDrawShader and setupDrawShaderUniforms now inspect an SkShader
passed in.
Inspect SkShader instead of mDrawModifiers.mShader.
Remove resetShader and setupShader.
setupDrawColorUniforms now takes a boolean indicating whether there is
a shader.
Add an inline function for accessing the SkShader on an SkPaint.
In setupDrawBlending(Layer*, bool), do not check the shader (which will
never be set), but do check whether the color filter may change the
alpha (newly fixed behavior).
In setupDrawBlending(SkPaint, ...), check the SkShader and whether the
color filter affects alpha (the latter is new behavior).
libs/hwui/Renderer.h:
Remove pure virtual functions setupShader and resetShader.
libs/hwui/ResourceCache.cpp:
libs/hwui/ResourceCache.h:
Remove functions for refing/unrefing shaders.
libs/hwui/SkiaShader.cpp:
libs/hwui/SkiaShader.h:
Much of this code was redundant and has been removed.
Convert structs into class with nothing but static functions for
calling describe/setupProgram.
libs/hwui/TextureCache.cpp:
libs/hwui/TextureCache.h:
Use the SkPixelRef as the key to the bitmap Lru cache, since shader
inspection will provide a different SkBitmap pointer (though it will
hold the correct SkPixelRef with the correct generation ID).
tests/CanvasCompare/src/com/android/test/hwuicompare/DisplayModifier.java:
tests/CanvasCompare/src/com/android/test/hwuicompare/ResourceModifiers.java:
Update manual test to have more shaders: radial, sweep, compose,
invalid compose.
BUG:10650594
Change-Id: Iaa7189178bda1c55f96da044d2a9fa602ba36034
2014-05-05 12:50:38 -04:00
|
|
|
mCache.put(bitmap->pixelRef(), texture);
|
2010-07-01 18:26:52 -07:00
|
|
|
}
|
2014-04-11 19:15:05 -07:00
|
|
|
} else if (!texture->isInUse && bitmap->getGenerationID() != texture->generation) {
|
|
|
|
// Texture was in the cache but is dirty, re-upload
|
|
|
|
// TODO: Re-adjust the cache size if the bitmap's dimensions have changed
|
2010-06-30 16:05:32 -07:00
|
|
|
generateTexture(bitmap, texture, true);
|
2010-06-29 21:05:21 -07:00
|
|
|
}
|
2010-08-06 11:18:34 -07:00
|
|
|
|
2010-06-29 21:05:21 -07:00
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
2014-04-11 19:15:05 -07:00
|
|
|
bool TextureCache::prefetchAndMarkInUse(const SkBitmap* bitmap) {
|
|
|
|
Texture* texture = getCachedTexture(bitmap);
|
|
|
|
if (texture) {
|
|
|
|
texture->isInUse = true;
|
|
|
|
}
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
Texture* TextureCache::get(const SkBitmap* bitmap) {
|
|
|
|
Texture* texture = getCachedTexture(bitmap);
|
|
|
|
|
|
|
|
if (!texture) {
|
|
|
|
if (!canMakeTextureFromBitmap(bitmap)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint32_t size = bitmap->rowBytes() * bitmap->height();
|
|
|
|
texture = new Texture();
|
|
|
|
texture->bitmapSize = size;
|
|
|
|
generateTexture(bitmap, texture, false);
|
|
|
|
texture->cleanup = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
Texture* TextureCache::getTransient(const SkBitmap* bitmap) {
|
2013-06-04 18:00:09 -07:00
|
|
|
Texture* texture = new Texture();
|
2012-05-14 19:44:40 -07:00
|
|
|
texture->bitmapSize = bitmap->rowBytes() * bitmap->height();
|
|
|
|
texture->cleanup = true;
|
|
|
|
|
|
|
|
generateTexture(bitmap, texture, false);
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
void TextureCache::remove(const SkBitmap* bitmap) {
|
Inspect SkShader to determine hw shader.
Instead of duplicating internal info about SkShader, inspect the
SkShader installed on the SkPaint.
core/java/android/view/GLES20Canvas.java:
Remove setupModifiers, nResetModifiers, and nSetupShader.
core/jni/android/graphics/Shader.cpp:
Remove calls to create/destroy the (previously) attached SkiaShader.
core/jni/android_view_GLES20Canvas.cpp:
Remove native code for setupShader and resetModifiers.
graphics/java/android/graphics/BitmapShader.java:
graphics/java/android/graphics/ComposeShader.java:
graphics/java/android/graphics/LinearGradient.java:
graphics/java/android/graphics/RadialGradient.java:
graphics/java/android/graphics/Shader.java:
graphics/java/android/graphics/SweepGradient.java:
Remove code keeping track of native SkiaShader.
libs/hwui/Caches.h:
Include Extensions.h.
libs/hwui/DeferredDisplayList.cpp:
Compare shaders on the paint, instead of on DrawModifiers.
libs/hwui/DisplayList.cpp:
libs/hwui/DisplayList.h:
Remove vector of SkiaShaders.
libs/hwui/DisplayListOp.h:
Access the SkShader on mPaint.
Remove SetupShaderOp and ResetShaderOp.
libs/hwui/DisplayListRenderer.cpp:
libs/hwui/DisplayListRenderer.h:
Remove resetShader, setupShader, refShader, and mShaderMap.
libs/hwui/FontRenderer.cpp:
Pass SkShader to setupDrawShader and setupDrawShaderUniforms.
libs/hwui/OpenGLRenderer.cpp:
libs/hwui/OpenGLRenderer.h:
Add LayerShader, a class inheriting from SkShader, to mimic the
behavior of SkiaLayerShader. Unlike SkiaLayerShader, it can be set on
the SkPaint so it can be inspected later.
Set a LayerShader instead of a SkiaLayerShader.
setupDrawShader and setupDrawShaderUniforms now inspect an SkShader
passed in.
Inspect SkShader instead of mDrawModifiers.mShader.
Remove resetShader and setupShader.
setupDrawColorUniforms now takes a boolean indicating whether there is
a shader.
Add an inline function for accessing the SkShader on an SkPaint.
In setupDrawBlending(Layer*, bool), do not check the shader (which will
never be set), but do check whether the color filter may change the
alpha (newly fixed behavior).
In setupDrawBlending(SkPaint, ...), check the SkShader and whether the
color filter affects alpha (the latter is new behavior).
libs/hwui/Renderer.h:
Remove pure virtual functions setupShader and resetShader.
libs/hwui/ResourceCache.cpp:
libs/hwui/ResourceCache.h:
Remove functions for refing/unrefing shaders.
libs/hwui/SkiaShader.cpp:
libs/hwui/SkiaShader.h:
Much of this code was redundant and has been removed.
Convert structs into class with nothing but static functions for
calling describe/setupProgram.
libs/hwui/TextureCache.cpp:
libs/hwui/TextureCache.h:
Use the SkPixelRef as the key to the bitmap Lru cache, since shader
inspection will provide a different SkBitmap pointer (though it will
hold the correct SkPixelRef with the correct generation ID).
tests/CanvasCompare/src/com/android/test/hwuicompare/DisplayModifier.java:
tests/CanvasCompare/src/com/android/test/hwuicompare/ResourceModifiers.java:
Update manual test to have more shaders: radial, sweep, compose,
invalid compose.
BUG:10650594
Change-Id: Iaa7189178bda1c55f96da044d2a9fa602ba36034
2014-05-05 12:50:38 -04:00
|
|
|
mCache.remove(bitmap->pixelRef());
|
2010-06-29 21:05:21 -07:00
|
|
|
}
|
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
void TextureCache::removeDeferred(const SkBitmap* bitmap) {
|
2010-09-08 15:15:43 -07:00
|
|
|
Mutex::Autolock _l(mLock);
|
2010-11-11 15:36:56 -08:00
|
|
|
mGarbage.push(bitmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextureCache::clearGarbage() {
|
|
|
|
Mutex::Autolock _l(mLock);
|
|
|
|
size_t count = mGarbage.size();
|
|
|
|
for (size_t i = 0; i < count; i++) {
|
2014-01-09 14:11:57 +09:00
|
|
|
const SkBitmap* bitmap = mGarbage.itemAt(i);
|
Inspect SkShader to determine hw shader.
Instead of duplicating internal info about SkShader, inspect the
SkShader installed on the SkPaint.
core/java/android/view/GLES20Canvas.java:
Remove setupModifiers, nResetModifiers, and nSetupShader.
core/jni/android/graphics/Shader.cpp:
Remove calls to create/destroy the (previously) attached SkiaShader.
core/jni/android_view_GLES20Canvas.cpp:
Remove native code for setupShader and resetModifiers.
graphics/java/android/graphics/BitmapShader.java:
graphics/java/android/graphics/ComposeShader.java:
graphics/java/android/graphics/LinearGradient.java:
graphics/java/android/graphics/RadialGradient.java:
graphics/java/android/graphics/Shader.java:
graphics/java/android/graphics/SweepGradient.java:
Remove code keeping track of native SkiaShader.
libs/hwui/Caches.h:
Include Extensions.h.
libs/hwui/DeferredDisplayList.cpp:
Compare shaders on the paint, instead of on DrawModifiers.
libs/hwui/DisplayList.cpp:
libs/hwui/DisplayList.h:
Remove vector of SkiaShaders.
libs/hwui/DisplayListOp.h:
Access the SkShader on mPaint.
Remove SetupShaderOp and ResetShaderOp.
libs/hwui/DisplayListRenderer.cpp:
libs/hwui/DisplayListRenderer.h:
Remove resetShader, setupShader, refShader, and mShaderMap.
libs/hwui/FontRenderer.cpp:
Pass SkShader to setupDrawShader and setupDrawShaderUniforms.
libs/hwui/OpenGLRenderer.cpp:
libs/hwui/OpenGLRenderer.h:
Add LayerShader, a class inheriting from SkShader, to mimic the
behavior of SkiaLayerShader. Unlike SkiaLayerShader, it can be set on
the SkPaint so it can be inspected later.
Set a LayerShader instead of a SkiaLayerShader.
setupDrawShader and setupDrawShaderUniforms now inspect an SkShader
passed in.
Inspect SkShader instead of mDrawModifiers.mShader.
Remove resetShader and setupShader.
setupDrawColorUniforms now takes a boolean indicating whether there is
a shader.
Add an inline function for accessing the SkShader on an SkPaint.
In setupDrawBlending(Layer*, bool), do not check the shader (which will
never be set), but do check whether the color filter may change the
alpha (newly fixed behavior).
In setupDrawBlending(SkPaint, ...), check the SkShader and whether the
color filter affects alpha (the latter is new behavior).
libs/hwui/Renderer.h:
Remove pure virtual functions setupShader and resetShader.
libs/hwui/ResourceCache.cpp:
libs/hwui/ResourceCache.h:
Remove functions for refing/unrefing shaders.
libs/hwui/SkiaShader.cpp:
libs/hwui/SkiaShader.h:
Much of this code was redundant and has been removed.
Convert structs into class with nothing but static functions for
calling describe/setupProgram.
libs/hwui/TextureCache.cpp:
libs/hwui/TextureCache.h:
Use the SkPixelRef as the key to the bitmap Lru cache, since shader
inspection will provide a different SkBitmap pointer (though it will
hold the correct SkPixelRef with the correct generation ID).
tests/CanvasCompare/src/com/android/test/hwuicompare/DisplayModifier.java:
tests/CanvasCompare/src/com/android/test/hwuicompare/ResourceModifiers.java:
Update manual test to have more shaders: radial, sweep, compose,
invalid compose.
BUG:10650594
Change-Id: Iaa7189178bda1c55f96da044d2a9fa602ba36034
2014-05-05 12:50:38 -04:00
|
|
|
mCache.remove(bitmap->pixelRef());
|
2014-01-09 14:11:57 +09:00
|
|
|
delete bitmap;
|
2010-11-11 15:36:56 -08:00
|
|
|
}
|
|
|
|
mGarbage.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextureCache::clear() {
|
2010-06-29 21:05:21 -07:00
|
|
|
mCache.clear();
|
2011-07-26 18:57:28 -07:00
|
|
|
TEXTURE_LOGD("TextureCache:clear(), mSize = %d", mSize);
|
2010-06-29 21:05:21 -07:00
|
|
|
}
|
|
|
|
|
2011-11-04 15:12:29 -07:00
|
|
|
void TextureCache::flush() {
|
|
|
|
if (mFlushRate >= 1.0f || mCache.size() == 0) return;
|
|
|
|
if (mFlushRate <= 0.0f) {
|
|
|
|
clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t targetSize = uint32_t(mSize * mFlushRate);
|
|
|
|
TEXTURE_LOGD("TextureCache::flush: target size: %d", targetSize);
|
|
|
|
|
|
|
|
while (mSize > targetSize) {
|
|
|
|
mCache.removeOldest();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
void TextureCache::generateTexture(const SkBitmap* bitmap, Texture* texture, bool regenerate) {
|
2010-06-30 17:56:19 -07:00
|
|
|
SkAutoLockPixels alp(*bitmap);
|
2010-09-08 15:15:43 -07:00
|
|
|
|
2010-06-30 17:56:19 -07:00
|
|
|
if (!bitmap->readyToDraw()) {
|
2012-01-06 19:20:56 +00:00
|
|
|
ALOGE("Cannot generate texture from bitmap");
|
2010-06-30 17:56:19 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-29 09:49:13 -07:00
|
|
|
ATRACE_CALL();
|
|
|
|
|
2012-10-17 12:14:11 -07:00
|
|
|
// We could also enable mipmapping if both bitmap dimensions are powers
|
|
|
|
// of 2 but we'd have to deal with size changes. Let's keep this simple
|
2013-02-06 16:51:04 -08:00
|
|
|
const bool canMipMap = Extensions::getInstance().hasNPot();
|
2012-10-17 12:14:11 -07:00
|
|
|
|
2012-10-16 18:44:09 -07:00
|
|
|
// If the texture had mipmap enabled but not anymore,
|
|
|
|
// force a glTexImage2D to discard the mipmap levels
|
2010-09-22 16:10:57 -07:00
|
|
|
const bool resize = !regenerate || bitmap->width() != int(texture->width) ||
|
2012-10-16 18:44:09 -07:00
|
|
|
bitmap->height() != int(texture->height) ||
|
2012-10-17 12:14:11 -07:00
|
|
|
(regenerate && canMipMap && texture->mipMap && !bitmap->hasHardwareMipMap());
|
2010-06-30 16:05:32 -07:00
|
|
|
|
2010-09-22 14:13:32 -07:00
|
|
|
if (!regenerate) {
|
2010-06-30 16:05:32 -07:00
|
|
|
glGenTextures(1, &texture->id);
|
|
|
|
}
|
2010-06-29 21:05:21 -07:00
|
|
|
|
2010-09-22 14:13:32 -07:00
|
|
|
texture->generation = bitmap->getGenerationID();
|
|
|
|
texture->width = bitmap->width();
|
|
|
|
texture->height = bitmap->height();
|
|
|
|
|
2013-06-04 18:00:09 -07:00
|
|
|
Caches::getInstance().bindTexture(texture->id);
|
2010-06-29 21:05:21 -07:00
|
|
|
|
2014-07-08 12:36:44 -04:00
|
|
|
switch (bitmap->colorType()) {
|
|
|
|
case kAlpha_8_SkColorType:
|
2012-10-16 11:25:06 -07:00
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
2013-11-27 20:16:43 +08:00
|
|
|
uploadToTexture(resize, GL_ALPHA, bitmap->rowBytesAsPixels(), bitmap->bytesPerPixel(),
|
2013-09-24 18:44:54 -07:00
|
|
|
texture->width, texture->height, GL_UNSIGNED_BYTE, bitmap->getPixels());
|
2010-09-22 14:13:32 -07:00
|
|
|
texture->blend = true;
|
2010-07-22 18:50:12 -07:00
|
|
|
break;
|
2014-07-08 12:36:44 -04:00
|
|
|
case kRGB_565_SkColorType:
|
2012-10-16 11:25:06 -07:00
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel());
|
2013-11-27 20:16:43 +08:00
|
|
|
uploadToTexture(resize, GL_RGB, bitmap->rowBytesAsPixels(), bitmap->bytesPerPixel(),
|
2013-09-24 18:44:54 -07:00
|
|
|
texture->width, texture->height, GL_UNSIGNED_SHORT_5_6_5, bitmap->getPixels());
|
2010-06-30 17:56:19 -07:00
|
|
|
texture->blend = false;
|
2010-06-29 21:05:21 -07:00
|
|
|
break;
|
2014-07-08 12:36:44 -04:00
|
|
|
case kN32_SkColorType:
|
2012-10-16 11:25:06 -07:00
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel());
|
2013-11-27 20:16:43 +08:00
|
|
|
uploadToTexture(resize, GL_RGBA, bitmap->rowBytesAsPixels(), bitmap->bytesPerPixel(),
|
2013-09-24 18:44:54 -07:00
|
|
|
texture->width, texture->height, GL_UNSIGNED_BYTE, bitmap->getPixels());
|
2010-08-19 14:45:42 -07:00
|
|
|
// Do this after calling getPixels() to make sure Skia's deferred
|
|
|
|
// decoding happened
|
|
|
|
texture->blend = !bitmap->isOpaque();
|
2010-06-29 21:05:21 -07:00
|
|
|
break;
|
2014-07-08 12:36:44 -04:00
|
|
|
case kARGB_4444_SkColorType:
|
|
|
|
case kIndex_8_SkColorType:
|
2012-10-16 11:25:06 -07:00
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel());
|
2010-10-27 18:57:51 -07:00
|
|
|
uploadLoFiTexture(resize, bitmap, texture->width, texture->height);
|
2011-02-24 17:21:29 -08:00
|
|
|
texture->blend = !bitmap->isOpaque();
|
2010-10-27 18:57:51 -07:00
|
|
|
break;
|
2010-06-30 15:51:03 -07:00
|
|
|
default:
|
2014-07-08 12:36:44 -04:00
|
|
|
ALOGW("Unsupported bitmap colorType: %d", bitmap->colorType());
|
2010-06-30 15:51:03 -07:00
|
|
|
break;
|
2010-06-29 21:05:21 -07:00
|
|
|
}
|
|
|
|
|
2012-10-17 12:14:11 -07:00
|
|
|
if (canMipMap) {
|
2012-10-16 18:44:09 -07:00
|
|
|
texture->mipMap = bitmap->hasHardwareMipMap();
|
|
|
|
if (texture->mipMap) {
|
|
|
|
glGenerateMipmap(GL_TEXTURE_2D);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-30 20:21:23 -08:00
|
|
|
if (!regenerate) {
|
|
|
|
texture->setFilter(GL_NEAREST);
|
|
|
|
texture->setWrap(GL_CLAMP_TO_EDGE);
|
|
|
|
}
|
2010-06-29 21:05:21 -07:00
|
|
|
}
|
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
void TextureCache::uploadLoFiTexture(bool resize, const SkBitmap* bitmap,
|
2010-10-05 14:58:09 -07:00
|
|
|
uint32_t width, uint32_t height) {
|
|
|
|
SkBitmap rgbaBitmap;
|
2014-06-16 17:31:48 -04:00
|
|
|
rgbaBitmap.allocPixels(SkImageInfo::MakeN32(width, height, bitmap->alphaType()));
|
2010-10-05 14:58:09 -07:00
|
|
|
rgbaBitmap.eraseColor(0);
|
|
|
|
|
|
|
|
SkCanvas canvas(rgbaBitmap);
|
|
|
|
canvas.drawBitmap(*bitmap, 0.0f, 0.0f, NULL);
|
|
|
|
|
2013-11-27 20:16:43 +08:00
|
|
|
uploadToTexture(resize, GL_RGBA, rgbaBitmap.rowBytesAsPixels(), rgbaBitmap.bytesPerPixel(),
|
|
|
|
width, height, GL_UNSIGNED_BYTE, rgbaBitmap.getPixels());
|
2010-10-05 14:58:09 -07:00
|
|
|
}
|
|
|
|
|
2013-11-27 20:16:43 +08:00
|
|
|
void TextureCache::uploadToTexture(bool resize, GLenum format, GLsizei stride, GLsizei bpp,
|
2013-09-24 18:44:54 -07:00
|
|
|
GLsizei width, GLsizei height, GLenum type, const GLvoid * data) {
|
|
|
|
const bool useStride = stride != width && Extensions::getInstance().hasUnpackRowLength();
|
2013-11-27 20:16:43 +08:00
|
|
|
if ((stride == width) || useStride) {
|
|
|
|
if (useStride) {
|
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, stride);
|
|
|
|
}
|
2013-09-24 18:44:54 -07:00
|
|
|
|
2013-11-27 20:16:43 +08:00
|
|
|
if (resize) {
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, type, data);
|
|
|
|
} else {
|
|
|
|
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, data);
|
|
|
|
}
|
2013-09-24 18:44:54 -07:00
|
|
|
|
2013-11-27 20:16:43 +08:00
|
|
|
if (useStride) {
|
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
|
|
|
}
|
2010-09-22 14:13:32 -07:00
|
|
|
} else {
|
2013-11-27 20:16:43 +08:00
|
|
|
// With OpenGL ES 2.0 we need to copy the bitmap in a temporary buffer
|
|
|
|
// if the stride doesn't match the width
|
|
|
|
|
|
|
|
GLvoid * temp = (GLvoid *) malloc(width * height * bpp);
|
|
|
|
if (!temp) return;
|
|
|
|
|
|
|
|
uint8_t * pDst = (uint8_t *)temp;
|
|
|
|
uint8_t * pSrc = (uint8_t *)data;
|
|
|
|
for (GLsizei i = 0; i < height; i++) {
|
|
|
|
memcpy(pDst, pSrc, width * bpp);
|
|
|
|
pDst += width * bpp;
|
|
|
|
pSrc += stride * bpp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resize) {
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, type, temp);
|
|
|
|
} else {
|
|
|
|
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, temp);
|
|
|
|
}
|
2013-09-24 18:44:54 -07:00
|
|
|
|
2013-11-27 20:16:43 +08:00
|
|
|
free(temp);
|
2013-09-24 18:44:54 -07:00
|
|
|
}
|
2010-09-22 14:13:32 -07:00
|
|
|
}
|
|
|
|
|
2010-06-29 21:05:21 -07:00
|
|
|
}; // namespace uirenderer
|
|
|
|
}; // namespace android
|