Commit 9b05baad authored by jdduke@chromium.org's avatar jdduke@chromium.org

Support an ALPHA_8 UIResourceBitmap format

Add an ALPHA_8 UIResourceFormat corresponding to the kAlpha_8_SkColorType. Also
plumb this format to its corresponding ALPHA_8 OpenGL format. This is in
preparation for the UIResource-backed Android L overscroll effect,
https://codereview.chromium.org/367173003/.

BUG=389744

Review URL: https://codereview.chromium.org/463663002

Cr-Commit-Position: refs/heads/master@{#289428}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289428 0039d316-1c4b-4281-b951-d872f2087c98
parent 49d43234
...@@ -14,6 +14,7 @@ SkColorType ResourceFormatToSkColorType(ResourceFormat format) { ...@@ -14,6 +14,7 @@ SkColorType ResourceFormatToSkColorType(ResourceFormat format) {
case BGRA_8888: case BGRA_8888:
return kN32_SkColorType; return kN32_SkColorType;
case ETC1: case ETC1:
case ALPHA_8:
case LUMINANCE_8: case LUMINANCE_8:
case RGB_565: case RGB_565:
NOTREACHED(); NOTREACHED();
......
...@@ -15,6 +15,7 @@ enum ResourceFormat { ...@@ -15,6 +15,7 @@ enum ResourceFormat {
RGBA_8888, RGBA_8888,
RGBA_4444, RGBA_4444,
BGRA_8888, BGRA_8888,
ALPHA_8,
LUMINANCE_8, LUMINANCE_8,
RGB_565, RGB_565,
ETC1, ETC1,
......
...@@ -70,6 +70,7 @@ GLenum TextureToStorageFormat(ResourceFormat format) { ...@@ -70,6 +70,7 @@ GLenum TextureToStorageFormat(ResourceFormat format) {
storage_format = GL_BGRA8_EXT; storage_format = GL_BGRA8_EXT;
break; break;
case RGBA_4444: case RGBA_4444:
case ALPHA_8:
case LUMINANCE_8: case LUMINANCE_8:
case RGB_565: case RGB_565:
case ETC1: case ETC1:
...@@ -86,6 +87,7 @@ bool IsFormatSupportedForStorage(ResourceFormat format) { ...@@ -86,6 +87,7 @@ bool IsFormatSupportedForStorage(ResourceFormat format) {
case BGRA_8888: case BGRA_8888:
return true; return true;
case RGBA_4444: case RGBA_4444:
case ALPHA_8:
case LUMINANCE_8: case LUMINANCE_8:
case RGB_565: case RGB_565:
case ETC1: case ETC1:
...@@ -516,6 +518,7 @@ SkCanvas* ResourceProvider::BitmapRasterBuffer::DoLockForWrite() { ...@@ -516,6 +518,7 @@ SkCanvas* ResourceProvider::BitmapRasterBuffer::DoLockForWrite() {
raster_bitmap_.installPixels(info, mapped_buffer_, stride); raster_bitmap_.installPixels(info, mapped_buffer_, stride);
break; break;
} }
case ALPHA_8:
case LUMINANCE_8: case LUMINANCE_8:
case RGB_565: case RGB_565:
case ETC1: case ETC1:
......
...@@ -663,6 +663,7 @@ inline unsigned BitsPerPixel(ResourceFormat format) { ...@@ -663,6 +663,7 @@ inline unsigned BitsPerPixel(ResourceFormat format) {
32, // RGBA_8888 32, // RGBA_8888
16, // RGBA_4444 16, // RGBA_4444
32, // BGRA_8888 32, // BGRA_8888
8, // ALPHA_8
8, // LUMINANCE_8 8, // LUMINANCE_8
16, // RGB_565, 16, // RGB_565,
4 // ETC1 4 // ETC1
...@@ -676,6 +677,7 @@ inline GLenum GLDataType(ResourceFormat format) { ...@@ -676,6 +677,7 @@ inline GLenum GLDataType(ResourceFormat format) {
GL_UNSIGNED_BYTE, // RGBA_8888 GL_UNSIGNED_BYTE, // RGBA_8888
GL_UNSIGNED_SHORT_4_4_4_4, // RGBA_4444 GL_UNSIGNED_SHORT_4_4_4_4, // RGBA_4444
GL_UNSIGNED_BYTE, // BGRA_8888 GL_UNSIGNED_BYTE, // BGRA_8888
GL_UNSIGNED_BYTE, // ALPHA_8
GL_UNSIGNED_BYTE, // LUMINANCE_8 GL_UNSIGNED_BYTE, // LUMINANCE_8
GL_UNSIGNED_SHORT_5_6_5, // RGB_565, GL_UNSIGNED_SHORT_5_6_5, // RGB_565,
GL_UNSIGNED_BYTE // ETC1 GL_UNSIGNED_BYTE // ETC1
...@@ -689,6 +691,7 @@ inline GLenum GLDataFormat(ResourceFormat format) { ...@@ -689,6 +691,7 @@ inline GLenum GLDataFormat(ResourceFormat format) {
GL_RGBA, // RGBA_8888 GL_RGBA, // RGBA_8888
GL_RGBA, // RGBA_4444 GL_RGBA, // RGBA_4444
GL_BGRA_EXT, // BGRA_8888 GL_BGRA_EXT, // BGRA_8888
GL_ALPHA, // ALPHA_8
GL_LUMINANCE, // LUMINANCE_8 GL_LUMINANCE, // LUMINANCE_8
GL_RGB, // RGB_565 GL_RGB, // RGB_565
GL_ETC1_RGB8_OES // ETC1 GL_ETC1_RGB8_OES // ETC1
......
...@@ -217,6 +217,15 @@ TEST(TextureUploaderTest, UploadContentsTest) { ...@@ -217,6 +217,15 @@ TEST(TextureUploaderTest, UploadContentsTest) {
} }
UploadTexture(uploader.get(), RGBA_8888, gfx::Size(41, 43), buffer); UploadTexture(uploader.get(), RGBA_8888, gfx::Size(41, 43), buffer);
// Upload a tightly packed 41x86 ALPHA texture.
memset(buffer, 0, sizeof(buffer));
for (int i = 0; i < 86; ++i) {
// Mark the beginning and end of each row, for the test.
buffer[i * 1 * 41] = 0x1;
buffer[(i + 1) * 41 - 1] = 0x2;
}
UploadTexture(uploader.get(), ALPHA_8, gfx::Size(41, 86), buffer);
// Upload a tightly packed 82x86 LUMINANCE texture. // Upload a tightly packed 82x86 LUMINANCE texture.
memset(buffer, 0, sizeof(buffer)); memset(buffer, 0, sizeof(buffer));
for (int i = 0; i < 86; ++i) { for (int i = 0; i < 86; ++i) {
......
...@@ -11,6 +11,26 @@ ...@@ -11,6 +11,26 @@
#include "third_party/skia/include/core/SkPixelRef.h" #include "third_party/skia/include/core/SkPixelRef.h"
namespace cc { namespace cc {
namespace {
UIResourceBitmap::UIResourceFormat SkColorTypeToUIResourceFormat(
SkColorType sk_type) {
UIResourceBitmap::UIResourceFormat format = UIResourceBitmap::RGBA8;
switch (sk_type) {
case kN32_SkColorType:
format = UIResourceBitmap::RGBA8;
break;
case kAlpha_8_SkColorType:
format = UIResourceBitmap::ALPHA_8;
break;
default:
NOTREACHED() << "Invalid SkColorType for UIResourceBitmap: " << sk_type;
break;
}
return format;
}
} // namespace
void UIResourceBitmap::Create(const skia::RefPtr<SkPixelRef>& pixel_ref, void UIResourceBitmap::Create(const skia::RefPtr<SkPixelRef>& pixel_ref,
const gfx::Size& size, const gfx::Size& size,
...@@ -29,14 +49,14 @@ void UIResourceBitmap::Create(const skia::RefPtr<SkPixelRef>& pixel_ref, ...@@ -29,14 +49,14 @@ void UIResourceBitmap::Create(const skia::RefPtr<SkPixelRef>& pixel_ref,
} }
UIResourceBitmap::UIResourceBitmap(const SkBitmap& skbitmap) { UIResourceBitmap::UIResourceBitmap(const SkBitmap& skbitmap) {
DCHECK_EQ(skbitmap.colorType(), kN32_SkColorType);
DCHECK_EQ(skbitmap.width(), skbitmap.rowBytesAsPixels()); DCHECK_EQ(skbitmap.width(), skbitmap.rowBytesAsPixels());
DCHECK(skbitmap.isImmutable()); DCHECK(skbitmap.isImmutable());
skia::RefPtr<SkPixelRef> pixel_ref = skia::SharePtr(skbitmap.pixelRef()); skia::RefPtr<SkPixelRef> pixel_ref = skia::SharePtr(skbitmap.pixelRef());
const SkImageInfo& info = pixel_ref->info(); const SkImageInfo& info = pixel_ref->info();
Create( Create(pixel_ref,
pixel_ref, gfx::Size(info.fWidth, info.fHeight), UIResourceBitmap::RGBA8); gfx::Size(info.fWidth, info.fHeight),
SkColorTypeToUIResourceFormat(skbitmap.colorType()));
SetOpaque(skbitmap.isOpaque()); SetOpaque(skbitmap.isOpaque());
} }
......
...@@ -27,6 +27,7 @@ class CC_EXPORT UIResourceBitmap { ...@@ -27,6 +27,7 @@ class CC_EXPORT UIResourceBitmap {
public: public:
enum UIResourceFormat { enum UIResourceFormat {
RGBA8, RGBA8,
ALPHA_8,
ETC1 ETC1
}; };
enum UIResourceWrapMode { enum UIResourceWrapMode {
...@@ -42,7 +43,7 @@ class CC_EXPORT UIResourceBitmap { ...@@ -42,7 +43,7 @@ class CC_EXPORT UIResourceBitmap {
void SetOpaque(bool opaque) { opaque_ = opaque; } void SetOpaque(bool opaque) { opaque_ = opaque; }
// User must ensure that |skbitmap| is immutable. The SkBitmap Format should // User must ensure that |skbitmap| is immutable. The SkBitmap Format should
// be 32-bit RGBA. // be 32-bit RGBA or 8-bit ALPHA.
explicit UIResourceBitmap(const SkBitmap& skbitmap); explicit UIResourceBitmap(const SkBitmap& skbitmap);
UIResourceBitmap(const gfx::Size& size, bool is_opaque); UIResourceBitmap(const gfx::Size& size, bool is_opaque);
UIResourceBitmap(const skia::RefPtr<SkPixelRef>& pixel_ref, UIResourceBitmap(const skia::RefPtr<SkPixelRef>& pixel_ref,
......
...@@ -3284,8 +3284,16 @@ void LayerTreeHostImpl::CreateUIResource(UIResourceId uid, ...@@ -3284,8 +3284,16 @@ void LayerTreeHostImpl::CreateUIResource(UIResourceId uid,
DeleteUIResource(uid); DeleteUIResource(uid);
ResourceFormat format = resource_provider_->best_texture_format(); ResourceFormat format = resource_provider_->best_texture_format();
if (bitmap.GetFormat() == UIResourceBitmap::ETC1) switch (bitmap.GetFormat()) {
format = ETC1; case UIResourceBitmap::RGBA8:
break;
case UIResourceBitmap::ALPHA_8:
format = ALPHA_8;
break;
case UIResourceBitmap::ETC1:
format = ETC1;
break;
};
id = resource_provider_->CreateResource( id = resource_provider_->CreateResource(
bitmap.GetSize(), bitmap.GetSize(),
wrap_mode, wrap_mode,
......
...@@ -15,6 +15,7 @@ static ui::SurfaceFactoryOzone::BufferFormat GetOzoneFormat( ...@@ -15,6 +15,7 @@ static ui::SurfaceFactoryOzone::BufferFormat GetOzoneFormat(
return ui::SurfaceFactoryOzone::RGBA_8888; return ui::SurfaceFactoryOzone::RGBA_8888;
case cc::RGBA_4444: case cc::RGBA_4444:
case cc::BGRA_8888: case cc::BGRA_8888:
case cc::ALPHA_8:
case cc::LUMINANCE_8: case cc::LUMINANCE_8:
case cc::RGB_565: case cc::RGB_565:
case cc::ETC1: case cc::ETC1:
......
...@@ -13,6 +13,7 @@ enum ResourceFormat { ...@@ -13,6 +13,7 @@ enum ResourceFormat {
RGBA_8888, RGBA_8888,
RGBA_4444, RGBA_4444,
BGRA_8888, BGRA_8888,
ALPHA_8,
LUMINANCE_8, LUMINANCE_8,
RGB_565, RGB_565,
ETC1, ETC1,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment