summaryrefslogtreecommitdiffstats
path: root/cc
diff options
context:
space:
mode:
Diffstat (limited to 'cc')
-rw-r--r--cc/base/switches.cc3
-rw-r--r--cc/base/switches.h1
-rw-r--r--cc/cc.gyp2
-rw-r--r--cc/layers/content_layer.cc5
-rw-r--r--cc/layers/heads_up_display_layer_impl.cc5
-rw-r--r--cc/layers/image_layer.cc5
-rw-r--r--cc/layers/nine_patch_layer.cc5
-rw-r--r--cc/layers/nine_patch_layer_unittest.cc3
-rw-r--r--cc/layers/picture_layer_impl.cc12
-rw-r--r--cc/layers/texture_layer_impl.cc4
-rw-r--r--cc/layers/tiled_layer.cc2
-rw-r--r--cc/layers/tiled_layer.h5
-rw-r--r--cc/layers/tiled_layer_unittest.cc3
-rw-r--r--cc/output/direct_renderer.cc12
-rw-r--r--cc/output/direct_renderer.h2
-rw-r--r--cc/output/gl_renderer.cc56
-rw-r--r--cc/output/gl_renderer.h2
-rw-r--r--cc/output/gl_renderer_unittest.cc33
-rw-r--r--cc/output/renderer_pixeltest.cc45
-rw-r--r--cc/output/software_renderer_unittest.cc24
-rw-r--r--cc/quads/draw_quad_unittest.cc14
-rw-r--r--cc/quads/picture_draw_quad.cc31
-rw-r--r--cc/quads/picture_draw_quad.h5
-rw-r--r--cc/resources/image_raster_worker_pool.cc17
-rw-r--r--cc/resources/image_raster_worker_pool.h2
-rw-r--r--cc/resources/picture_layer_tiling_set_unittest.cc2
-rw-r--r--cc/resources/pixel_buffer_raster_worker_pool.cc15
-rw-r--r--cc/resources/pixel_buffer_raster_worker_pool.h3
-rw-r--r--cc/resources/platform_color.h17
-rw-r--r--cc/resources/prioritized_resource.cc13
-rw-r--r--cc/resources/prioritized_resource.h20
-rw-r--r--cc/resources/prioritized_resource_manager.cc7
-rw-r--r--cc/resources/prioritized_resource_manager.h6
-rw-r--r--cc/resources/prioritized_resource_unittest.cc7
-rw-r--r--cc/resources/prioritized_tile_set_unittest.cc4
-rw-r--r--cc/resources/raster_worker_pool.cc71
-rw-r--r--cc/resources/raster_worker_pool.h17
-rw-r--r--cc/resources/raster_worker_pool_perftest.cc4
-rw-r--r--cc/resources/raster_worker_pool_unittest.cc19
-rw-r--r--cc/resources/resource.cc23
-rw-r--r--cc/resources/resource.h12
-rw-r--r--cc/resources/resource_format.cc24
-rw-r--r--cc/resources/resource_format.h25
-rw-r--r--cc/resources/resource_pool.cc8
-rw-r--r--cc/resources/resource_pool.h8
-rw-r--r--cc/resources/resource_provider.cc247
-rw-r--r--cc/resources/resource_provider.h41
-rw-r--r--cc/resources/resource_provider_unittest.cc147
-rw-r--r--cc/resources/resource_update_controller_unittest.cc6
-rw-r--r--cc/resources/scoped_resource.cc6
-rw-r--r--cc/resources/scoped_resource.h4
-rw-r--r--cc/resources/scoped_resource_unittest.cc31
-rw-r--r--cc/resources/tile_manager_perftest.cc3
-rw-r--r--cc/resources/tile_manager_unittest.cc3
-rw-r--r--cc/resources/transferable_resource.cc2
-rw-r--r--cc/resources/transferable_resource.h3
-rw-r--r--cc/resources/video_resource_updater.cc19
-rw-r--r--cc/resources/video_resource_updater.h7
-rw-r--r--cc/resources/video_resource_updater_unittest.cc2
-rw-r--r--cc/scheduler/texture_uploader.cc24
-rw-r--r--cc/scheduler/texture_uploader.h8
-rw-r--r--cc/scheduler/texture_uploader_unittest.cc26
-rw-r--r--cc/test/fake_tile_manager.cc4
-rw-r--r--cc/test/pixel_test.cc6
-rw-r--r--cc/test/render_pass_test_common.cc32
-rw-r--r--cc/test/tiled_layer_test_common.cc2
-rw-r--r--cc/trees/layer_tree_host.cc8
-rw-r--r--cc/trees/layer_tree_host.h3
-rw-r--r--cc/trees/layer_tree_host_impl.cc8
-rw-r--r--cc/trees/layer_tree_host_impl_unittest.cc10
-rw-r--r--cc/trees/layer_tree_host_unittest.cc2
-rw-r--r--cc/trees/layer_tree_host_unittest_context.cc4
-rw-r--r--cc/trees/layer_tree_settings.cc3
-rw-r--r--cc/trees/layer_tree_settings.h1
74 files changed, 775 insertions, 490 deletions
diff --git a/cc/base/switches.cc b/cc/base/switches.cc
index e604145..87e10ce 100644
--- a/cc/base/switches.cc
+++ b/cc/base/switches.cc
@@ -141,6 +141,9 @@ const char kDisableMapImage[] = "disable-map-image";
// Prevents the layer tree unit tests from timing out.
const char kCCLayerTreeTestNoTimeout[] = "cc-layer-tree-test-no-timeout";
+// Disable textures using RGBA_4444 layout.
+const char kDisable4444Textures[] = "disable-4444-textures";
+
bool IsLCDTextEnabled() {
const CommandLine* command_line = CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(cc::switches::kDisableLCDText))
diff --git a/cc/base/switches.h b/cc/base/switches.h
index b8585e2..97fe833 100644
--- a/cc/base/switches.h
+++ b/cc/base/switches.h
@@ -41,6 +41,7 @@ CC_EXPORT extern const char kEnablePartialSwap[];
CC_EXPORT extern const char kStrictLayerPropertyChangeChecking[];
CC_EXPORT extern const char kEnableMapImage[];
CC_EXPORT extern const char kDisableMapImage[];
+CC_EXPORT extern const char kDisable4444Textures[];
// Switches for both the renderer and ui compositors.
CC_EXPORT extern const char kUIDisablePartialSwap[];
diff --git a/cc/cc.gyp b/cc/cc.gyp
index 00a0b8b..ffc8615 100644
--- a/cc/cc.gyp
+++ b/cc/cc.gyp
@@ -317,6 +317,8 @@
'resources/release_callback.h',
'resources/resource.cc',
'resources/resource.h',
+ 'resources/resource_format.h',
+ 'resources/resource_format.cc',
'resources/resource_pool.cc',
'resources/resource_pool.h',
'resources/resource_provider.cc',
diff --git a/cc/layers/content_layer.cc b/cc/layers/content_layer.cc
index 01a8922..3d611ee 100644
--- a/cc/layers/content_layer.cc
+++ b/cc/layers/content_layer.cc
@@ -127,9 +127,8 @@ void ContentLayer::CreateUpdaterIfNeeded() {
}
updater_->SetOpaque(contents_opaque());
- unsigned texture_format =
- layer_tree_host()->GetRendererCapabilities().best_texture_format;
- SetTextureFormat(texture_format);
+ SetTextureFormat(
+ layer_tree_host()->GetRendererCapabilities().best_texture_format);
}
void ContentLayer::SetContentsOpaque(bool opaque) {
diff --git a/cc/layers/heads_up_display_layer_impl.cc b/cc/layers/heads_up_display_layer_impl.cc
index 8728d70..c1fa9f3 100644
--- a/cc/layers/heads_up_display_layer_impl.cc
+++ b/cc/layers/heads_up_display_layer_impl.cc
@@ -94,8 +94,9 @@ bool HeadsUpDisplayLayerImpl::WillDraw(DrawMode draw_mode,
hud_resource_->Free();
if (!hud_resource_->id()) {
- hud_resource_->Allocate(
- content_bounds(), GL_RGBA, ResourceProvider::TextureUsageAny);
+ hud_resource_->Allocate(content_bounds(),
+ ResourceProvider::TextureUsageAny,
+ RGBA_8888);
}
return LayerImpl::WillDraw(draw_mode, resource_provider);
diff --git a/cc/layers/image_layer.cc b/cc/layers/image_layer.cc
index 8ba1908..bbf1aa8 100644
--- a/cc/layers/image_layer.cc
+++ b/cc/layers/image_layer.cc
@@ -56,9 +56,8 @@ void ImageLayer::CreateUpdaterIfNeeded() {
return;
updater_ = ImageLayerUpdater::Create();
- GLenum texture_format =
- layer_tree_host()->GetRendererCapabilities().best_texture_format;
- SetTextureFormat(texture_format);
+ SetTextureFormat(
+ layer_tree_host()->GetRendererCapabilities().best_texture_format);
}
LayerUpdater* ImageLayer::Updater() const {
diff --git a/cc/layers/nine_patch_layer.cc b/cc/layers/nine_patch_layer.cc
index 517b49b..b500798 100644
--- a/cc/layers/nine_patch_layer.cc
+++ b/cc/layers/nine_patch_layer.cc
@@ -40,10 +40,9 @@ void NinePatchLayer::SetTexturePriorities(
if (resource_) {
resource_->texture()->set_request_priority(
PriorityCalculator::UIPriority(true));
- GLenum texture_format =
- layer_tree_host()->GetRendererCapabilities().best_texture_format;
resource_->texture()->SetDimensions(
- gfx::Size(bitmap_.width(), bitmap_.height()), texture_format);
+ gfx::Size(bitmap_.width(), bitmap_.height()),
+ layer_tree_host()->GetRendererCapabilities().best_texture_format);
}
}
diff --git a/cc/layers/nine_patch_layer_unittest.cc b/cc/layers/nine_patch_layer_unittest.cc
index f918efb..2e18808 100644
--- a/cc/layers/nine_patch_layer_unittest.cc
+++ b/cc/layers/nine_patch_layer_unittest.cc
@@ -104,7 +104,8 @@ TEST_F(NinePatchLayerTest, TriggerFullUploadOnceWhenChangingBitmap) {
DebugScopedSetMainThreadBlocked main_thread_blocked(Proxy());
output_surface = FakeOutputSurface::Create3d();
CHECK(output_surface->BindToClient(&output_surface_client));
- resource_provider = ResourceProvider::Create(output_surface.get(), 0);
+ resource_provider =
+ ResourceProvider::Create(output_surface.get(), 0, false);
params.texture->AcquireBackingTexture(resource_provider.get());
ASSERT_TRUE(params.texture->have_backing_texture());
}
diff --git a/cc/layers/picture_layer_impl.cc b/cc/layers/picture_layer_impl.cc
index 9c7f355..46a0c0e 100644
--- a/cc/layers/picture_layer_impl.cc
+++ b/cc/layers/picture_layer_impl.cc
@@ -136,7 +136,7 @@ void PictureLayerImpl::AppendQuads(QuadSink* quad_sink,
opaque_rect,
texture_rect,
texture_size,
- false,
+ RGBA_8888,
quad_content_rect,
contents_scale,
draw_direct_to_backbuffer,
@@ -248,17 +248,17 @@ void PictureLayerImpl::AppendQuads(QuadSink* quad_sink,
gfx::Rect opaque_rect = iter->opaque_rect();
opaque_rect.Intersect(content_rect);
+ ResourceProvider* resource_provider =
+ layer_tree_impl()->resource_provider();
+ ResourceFormat format =
+ resource_provider->memory_efficient_texture_format();
scoped_ptr<PictureDrawQuad> quad = PictureDrawQuad::Create();
quad->SetNew(shared_quad_state,
geometry_rect,
opaque_rect,
texture_rect,
iter.texture_size(),
- // TODO(reveman): This assumes the renderer will use
- // GL_RGBA as format of temporary resource. The need
- // to swizzle should instead be determined by the
- // renderer.
- !PlatformColor::SameComponentOrder(GL_RGBA),
+ format,
iter->content_rect(),
iter->contents_scale(),
draw_direct_to_backbuffer,
diff --git a/cc/layers/texture_layer_impl.cc b/cc/layers/texture_layer_impl.cc
index 413708d..e16fd3c 100644
--- a/cc/layers/texture_layer_impl.cc
+++ b/cc/layers/texture_layer_impl.cc
@@ -111,8 +111,8 @@ bool TextureLayerImpl::WillDraw(DrawMode draw_mode,
if (!texture_copy_->id()) {
texture_copy_->Allocate(texture_mailbox_.shared_memory_size(),
- resource_provider->best_texture_format(),
- ResourceProvider::TextureUsageAny);
+ ResourceProvider::TextureUsageAny,
+ resource_provider->best_texture_format());
}
if (texture_copy_->id()) {
diff --git a/cc/layers/tiled_layer.cc b/cc/layers/tiled_layer.cc
index 2d812e8..8bbf227 100644
--- a/cc/layers/tiled_layer.cc
+++ b/cc/layers/tiled_layer.cc
@@ -86,7 +86,7 @@ class UpdatableTile : public LayerTilingData::Tile {
TiledLayer::TiledLayer()
: ContentsScalingLayer(),
- texture_format_(GL_INVALID_ENUM),
+ texture_format_(RGBA_8888),
skips_draw_(false),
failed_update_(false),
tiling_option_(AUTO_TILE) {
diff --git a/cc/layers/tiled_layer.h b/cc/layers/tiled_layer.h
index 51afed2..3870d69 100644
--- a/cc/layers/tiled_layer.h
+++ b/cc/layers/tiled_layer.h
@@ -8,6 +8,7 @@
#include "cc/base/cc_export.h"
#include "cc/layers/contents_scaling_layer.h"
#include "cc/resources/layer_tiling_data.h"
+#include "cc/resources/resource_format.h"
namespace cc {
class LayerUpdater;
@@ -45,7 +46,7 @@ class CC_EXPORT TiledLayer : public ContentsScalingLayer {
// Exposed to subclasses for testing.
void SetTileSize(gfx::Size size);
- void SetTextureFormat(unsigned texture_format) {
+ void SetTextureFormat(ResourceFormat texture_format) {
texture_format_ = texture_format;
}
void SetBorderTexelOption(LayerTilingData::BorderTexelOption option);
@@ -120,7 +121,7 @@ class CC_EXPORT TiledLayer : public ContentsScalingLayer {
bool IsSmallAnimatedLayer() const;
- unsigned texture_format_;
+ ResourceFormat texture_format_;
bool skips_draw_;
bool failed_update_;
diff --git a/cc/layers/tiled_layer_unittest.cc b/cc/layers/tiled_layer_unittest.cc
index daae39b..50d1865 100644
--- a/cc/layers/tiled_layer_unittest.cc
+++ b/cc/layers/tiled_layer_unittest.cc
@@ -69,7 +69,8 @@ class TiledLayerTest : public testing::Test {
DebugScopedSetImplThreadAndMainThreadBlocked
impl_thread_and_main_thread_blocked(proxy_);
- resource_provider_ = ResourceProvider::Create(output_surface_.get(), 0);
+ resource_provider_ =
+ ResourceProvider::Create(output_surface_.get(), 0, false);
host_impl_ = make_scoped_ptr(new FakeLayerTreeHostImpl(proxy_));
}
diff --git a/cc/output/direct_renderer.cc b/cc/output/direct_renderer.cc
index c3a4d39..51ac56a 100644
--- a/cc/output/direct_renderer.cc
+++ b/cc/output/direct_renderer.cc
@@ -168,7 +168,8 @@ void DirectRenderer::DecideRenderPassAllocationsForFrame(
const RenderPass* render_pass_in_frame = it->second;
gfx::Size required_size = RenderPassTextureSize(render_pass_in_frame);
- GLenum required_format = RenderPassTextureFormat(render_pass_in_frame);
+ ResourceFormat required_format =
+ RenderPassTextureFormat(render_pass_in_frame);
CachedResource* texture = pass_iter->second;
DCHECK(texture);
@@ -398,8 +399,8 @@ bool DirectRenderer::UseRenderPass(DrawingFrame* frame,
enlarge_pass_texture_amount_.y());
if (!texture->id() &&
!texture->Allocate(size,
- RenderPassTextureFormat(render_pass),
- ResourceProvider::TextureUsageFramebuffer))
+ ResourceProvider::TextureUsageFramebuffer,
+ RenderPassTextureFormat(render_pass)))
return false;
return BindFramebufferToTexture(frame, texture, render_pass->output_rect);
@@ -420,8 +421,9 @@ gfx::Size DirectRenderer::RenderPassTextureSize(const RenderPass* render_pass) {
}
// static
-GLenum DirectRenderer::RenderPassTextureFormat(const RenderPass* render_pass) {
- return GL_RGBA;
+ResourceFormat DirectRenderer::RenderPassTextureFormat(
+ const RenderPass* render_pass) {
+ return RGBA_8888;
}
} // namespace cc
diff --git a/cc/output/direct_renderer.h b/cc/output/direct_renderer.h
index 94ec9cc..efa34cf 100644
--- a/cc/output/direct_renderer.h
+++ b/cc/output/direct_renderer.h
@@ -105,7 +105,7 @@ class CC_EXPORT DirectRenderer : public Renderer {
gfx::RectF draw_space_rect);
static gfx::Size RenderPassTextureSize(const RenderPass* render_pass);
- static GLenum RenderPassTextureFormat(const RenderPass* render_pass);
+ static ResourceFormat RenderPassTextureFormat(const RenderPass* render_pass);
void DrawRenderPass(DrawingFrame* frame,
const RenderPass* render_pass,
diff --git a/cc/output/gl_renderer.cc b/cc/output/gl_renderer.cc
index 89fe9de..f365e36 100644
--- a/cc/output/gl_renderer.cc
+++ b/cc/output/gl_renderer.cc
@@ -653,8 +653,8 @@ scoped_ptr<ScopedResource> GLRenderer::DrawBackgroundFilters(
scoped_ptr<ScopedResource> device_background_texture =
ScopedResource::create(resource_provider_);
if (!device_background_texture->Allocate(window_rect.size(),
- GL_RGB,
- ResourceProvider::TextureUsageAny)) {
+ ResourceProvider::TextureUsageAny,
+ RGBA_8888)) {
return scoped_ptr<ScopedResource>();
} else {
ResourceProvider::ScopedWriteLockGL lock(resource_provider_,
@@ -679,8 +679,8 @@ scoped_ptr<ScopedResource> GLRenderer::DrawBackgroundFilters(
scoped_ptr<ScopedResource> background_texture =
ScopedResource::create(resource_provider_);
if (!background_texture->Allocate(quad->rect.size(),
- GL_RGBA,
- ResourceProvider::TextureUsageFramebuffer))
+ ResourceProvider::TextureUsageFramebuffer,
+ RGBA_8888))
return scoped_ptr<ScopedResource>();
const RenderPass* target_render_pass = frame->current_render_pass;
@@ -1702,10 +1702,10 @@ void GLRenderer::DrawPictureQuad(const DrawingFrame* frame,
on_demand_tile_raster_resource_id_ = resource_provider_->CreateGLTexture(
quad->texture_size,
- GL_RGBA,
GL_TEXTURE_POOL_UNMANAGED_CHROMIUM,
GL_CLAMP_TO_EDGE,
- ResourceProvider::TextureUsageAny);
+ ResourceProvider::TextureUsageAny,
+ quad->texture_format);
}
SkBitmapDevice device(on_demand_tile_raster_bitmap_);
@@ -1714,9 +1714,25 @@ void GLRenderer::DrawPictureQuad(const DrawingFrame* frame,
quad->picture_pile->RasterToBitmap(&canvas, quad->content_rect,
quad->contents_scale, NULL);
+ uint8_t* bitmap_pixels = NULL;
+ SkBitmap on_demand_tile_raster_bitmap_dest;
+ SkBitmap::Config config = SkBitmapConfigFromFormat(quad->texture_format);
+ if (on_demand_tile_raster_bitmap_.getConfig() != config) {
+ on_demand_tile_raster_bitmap_.copyTo(&on_demand_tile_raster_bitmap_dest,
+ config);
+ // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the
+ // bitmap data. This check will be removed once crbug.com/293728 is fixed.
+ CHECK_EQ(0u, on_demand_tile_raster_bitmap_dest.rowBytes() % 4);
+ bitmap_pixels = reinterpret_cast<uint8_t*>(
+ on_demand_tile_raster_bitmap_dest.getPixels());
+ } else {
+ bitmap_pixels = reinterpret_cast<uint8_t*>(
+ on_demand_tile_raster_bitmap_.getPixels());
+ }
+
resource_provider_->SetPixels(
on_demand_tile_raster_resource_id_,
- reinterpret_cast<uint8_t*>(on_demand_tile_raster_bitmap_.getPixels()),
+ bitmap_pixels,
gfx::Rect(quad->texture_size),
gfx::Rect(quad->texture_size),
gfx::Vector2d());
@@ -2198,7 +2214,7 @@ void GLRenderer::GetFramebufferPixelsAsync(
GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
GLC(context_, context_->texParameteri(
GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
- GetFramebufferTexture(texture_id, GL_RGBA, window_rect);
+ GetFramebufferTexture(texture_id, RGBA_8888, window_rect);
gpu::Mailbox mailbox;
unsigned sync_point = 0;
@@ -2290,7 +2306,7 @@ void GLRenderer::DoGetFramebufferPixels(
// Copy the contents of the current (IOSurface-backed) framebuffer into a
// temporary texture.
GetFramebufferTexture(temporary_texture,
- GL_RGBA,
+ RGBA_8888,
gfx::Rect(current_surface_size_));
temporary_fbo = context_->createFramebuffer();
// Attach this texture to an FBO, and perform the readback from that FBO.
@@ -2440,9 +2456,8 @@ void GLRenderer::PassOnSkBitmap(
request->SendBitmapResult(bitmap.Pass());
}
-void GLRenderer::GetFramebufferTexture(unsigned texture_id,
- unsigned texture_format,
- gfx::Rect window_rect) {
+void GLRenderer::GetFramebufferTexture(
+ unsigned texture_id, ResourceFormat texture_format, gfx::Rect window_rect) {
DCHECK(texture_id);
DCHECK_GE(window_rect.x(), 0);
DCHECK_GE(window_rect.y(), 0);
@@ -2451,14 +2466,15 @@ void GLRenderer::GetFramebufferTexture(unsigned texture_id,
GLC(context_, context_->bindTexture(GL_TEXTURE_2D, texture_id));
GLC(context_,
- context_->copyTexImage2D(GL_TEXTURE_2D,
- 0,
- texture_format,
- window_rect.x(),
- window_rect.y(),
- window_rect.width(),
- window_rect.height(),
- 0));
+ context_->copyTexImage2D(
+ GL_TEXTURE_2D,
+ 0,
+ ResourceProvider::GetGLDataFormat(texture_format),
+ window_rect.x(),
+ window_rect.y(),
+ window_rect.width(),
+ window_rect.height(),
+ 0));
GLC(context_, context_->bindTexture(GL_TEXTURE_2D, 0));
}
diff --git a/cc/output/gl_renderer.h b/cc/output/gl_renderer.h
index 61262a66..13f65f2 100644
--- a/cc/output/gl_renderer.h
+++ b/cc/output/gl_renderer.h
@@ -102,7 +102,7 @@ class CC_EXPORT GLRenderer : public DirectRenderer {
void GetFramebufferPixelsAsync(gfx::Rect rect,
scoped_ptr<CopyOutputRequest> request);
void GetFramebufferTexture(unsigned texture_id,
- unsigned texture_format,
+ ResourceFormat texture_format,
gfx::Rect device_rect);
void ReleaseRenderPassTextures();
diff --git a/cc/output/gl_renderer_unittest.cc b/cc/output/gl_renderer_unittest.cc
index dfb8e99..18d77e4445 100644
--- a/cc/output/gl_renderer_unittest.cc
+++ b/cc/output/gl_renderer_unittest.cc
@@ -221,7 +221,7 @@ class GLRendererTest : public testing::Test {
CHECK(output_surface_->BindToClient(&output_surface_client_));
resource_provider_ =
- ResourceProvider::Create(output_surface_.get(), 0).Pass();
+ ResourceProvider::Create(output_surface_.get(), 0, false).Pass();
renderer_ = make_scoped_ptr(new FakeRendererGL(&renderer_client_,
&settings_,
output_surface_.get(),
@@ -312,8 +312,8 @@ class GLRendererShaderTest : public testing::Test {
new ShaderCreatorMockGraphicsContext())).Pass();
CHECK(output_surface_->BindToClient(&output_surface_client_));
- resource_provider_ = ResourceProvider::Create(output_surface_.get(),
- 0).Pass();
+ resource_provider_ = ResourceProvider::Create(
+ output_surface_.get(), 0, false).Pass();
renderer_.reset(new FakeRendererGL(&renderer_client_,
&settings_,
output_surface_.get(),
@@ -634,7 +634,7 @@ TEST(GLRendererTest2, InitializationDoesNotMakeSynchronousCalls) {
CHECK(output_surface->BindToClient(&output_surface_client));
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
LayerTreeSettings settings;
FakeRendererClient renderer_client;
@@ -679,7 +679,7 @@ TEST(GLRendererTest2, InitializationWithQuicklyLostContextDoesNotAssert) {
CHECK(output_surface->BindToClient(&output_surface_client));
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
LayerTreeSettings settings;
FakeRendererClient renderer_client;
@@ -714,7 +714,7 @@ TEST(GLRendererTest2, OpaqueBackground) {
CHECK(output_surface->BindToClient(&output_surface_client));
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
LayerTreeSettings settings;
FakeRendererClient renderer_client;
@@ -752,7 +752,7 @@ TEST(GLRendererTest2, TransparentBackground) {
CHECK(output_surface->BindToClient(&output_surface_client));
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
LayerTreeSettings settings;
FakeRendererClient renderer_client;
@@ -784,7 +784,7 @@ TEST(GLRendererTest2, OffscreenOutputSurface) {
CHECK(output_surface->BindToClient(&output_surface_client));
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
LayerTreeSettings settings;
FakeRendererClient renderer_client;
@@ -860,7 +860,7 @@ TEST(GLRendererTest2, VisibilityChangeIsLastCall) {
CHECK(output_surface->BindToClient(&output_surface_client));
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
LayerTreeSettings settings;
FakeRendererClient renderer_client;
@@ -920,7 +920,7 @@ TEST(GLRendererTest2, ActiveTextureState) {
CHECK(output_surface->BindToClient(&output_surface_client));
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
LayerTreeSettings settings;
FakeRendererClient renderer_client;
@@ -1007,7 +1007,7 @@ TEST(GLRendererTest2, ShouldClearRootRenderPass) {
CHECK(output_surface->BindToClient(&output_surface_client));
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
LayerTreeSettings settings;
settings.should_clear_root_render_pass = false;
@@ -1095,7 +1095,7 @@ TEST(GLRendererTest2, ScissorTestWhenClearing) {
CHECK(output_surface->BindToClient(&output_surface_client));
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
LayerTreeSettings settings;
FakeRendererClient renderer_client;
@@ -1198,7 +1198,7 @@ TEST(GLRendererTest2, ScissorAndViewportWithinNonreshapableSurface) {
CHECK(output_surface->BindToClient(&output_surface_client));
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
LayerTreeSettings settings;
OffsetViewportRendererClient renderer_client;
@@ -1240,9 +1240,9 @@ TEST_F(GLRendererShaderTest, DrawRenderPassQuadShaderPermutations) {
cc::ResourceProvider::ResourceId mask =
resource_provider_->CreateResource(gfx::Size(20, 12),
- resource_provider_->best_texture_format(),
GL_CLAMP_TO_EDGE,
- ResourceProvider::TextureUsageAny);
+ ResourceProvider::TextureUsageAny,
+ resource_provider_->best_texture_format());
resource_provider_->AllocateForTesting(mask);
SkScalar matrix[20];
@@ -1547,7 +1547,8 @@ class MockOutputSurfaceTest : public testing::Test, public FakeRendererClient {
FakeOutputSurfaceClient output_surface_client_;
CHECK(output_surface_.BindToClient(&output_surface_client_));
- resource_provider_ = ResourceProvider::Create(&output_surface_, 0).Pass();
+ resource_provider_ =
+ ResourceProvider::Create(&output_surface_, 0, false).Pass();
renderer_.reset(new FakeRendererGL(
this, &settings_, &output_surface_, resource_provider_.get()));
diff --git a/cc/output/renderer_pixeltest.cc b/cc/output/renderer_pixeltest.cc
index daa5039..f0187aa 100644
--- a/cc/output/renderer_pixeltest.cc
+++ b/cc/output/renderer_pixeltest.cc
@@ -8,7 +8,6 @@
#include "cc/quads/draw_quad.h"
#include "cc/quads/picture_draw_quad.h"
#include "cc/quads/texture_draw_quad.h"
-#include "cc/resources/platform_color.h"
#include "cc/resources/sync_point_helper.h"
#include "cc/test/fake_picture_pile_impl.h"
#include "cc/test/pixel_test.h"
@@ -111,9 +110,11 @@ scoped_ptr<TextureDrawQuad> CreateTestTextureDrawQuad(
SkColorGetB(texel_color));
std::vector<uint32_t> pixels(rect.size().GetArea(), pixel_color);
- ResourceProvider::ResourceId resource = resource_provider->CreateResource(
- rect.size(), GL_RGBA, GL_CLAMP_TO_EDGE,
- ResourceProvider::TextureUsageAny);
+ ResourceProvider::ResourceId resource =
+ resource_provider->CreateResource(rect.size(),
+ GL_CLAMP_TO_EDGE,
+ ResourceProvider::TextureUsageAny,
+ RGBA_8888);
resource_provider->SetPixels(
resource,
reinterpret_cast<uint8_t*>(&pixels.front()),
@@ -409,28 +410,28 @@ class VideoGLRendererPixelTest : public GLRendererPixelTest {
ResourceProvider::ResourceId y_resource =
resource_provider_->CreateResource(
this->device_viewport_size_,
- GL_LUMINANCE,
GL_CLAMP_TO_EDGE,
- ResourceProvider::TextureUsageAny);
+ ResourceProvider::TextureUsageAny,
+ LUMINANCE_8);
ResourceProvider::ResourceId u_resource =
resource_provider_->CreateResource(
this->device_viewport_size_,
- GL_LUMINANCE,
GL_CLAMP_TO_EDGE,
- ResourceProvider::TextureUsageAny);
+ ResourceProvider::TextureUsageAny,
+ LUMINANCE_8);
ResourceProvider::ResourceId v_resource =
resource_provider_->CreateResource(
this->device_viewport_size_,
- GL_LUMINANCE,
GL_CLAMP_TO_EDGE,
- ResourceProvider::TextureUsageAny);
+ ResourceProvider::TextureUsageAny,
+ LUMINANCE_8);
ResourceProvider::ResourceId a_resource = 0;
if (with_alpha) {
a_resource = resource_provider_->CreateResource(
this->device_viewport_size_,
- GL_LUMINANCE,
GL_CLAMP_TO_EDGE,
- ResourceProvider::TextureUsageAny);
+ ResourceProvider::TextureUsageAny,
+ LUMINANCE_8);
}
int w = this->device_viewport_size_.width();
@@ -1366,7 +1367,7 @@ TYPED_TEST(RendererPixelTestWithSkiaGPUBackend, PictureDrawQuadIdentityScale) {
gfx::Rect viewport(this->device_viewport_size_);
bool use_skia_gpu_backend = this->UseSkiaGPUBackend();
// TODO(enne): the renderer should figure this out on its own.
- bool contents_swizzled = !PlatformColor::SameComponentOrder(GL_RGBA);
+ ResourceFormat texture_format = RGBA_8888;
RenderPass::Id id(1, 1);
gfx::Transform transform_to_root;
@@ -1404,7 +1405,7 @@ TYPED_TEST(RendererPixelTestWithSkiaGPUBackend, PictureDrawQuadIdentityScale) {
gfx::Rect(),
viewport,
viewport.size(),
- contents_swizzled,
+ texture_format,
viewport,
1.f,
use_skia_gpu_backend,
@@ -1429,7 +1430,7 @@ TYPED_TEST(RendererPixelTestWithSkiaGPUBackend, PictureDrawQuadIdentityScale) {
gfx::Rect(),
gfx::RectF(0.f, 0.f, 1.f, 1.f),
viewport.size(),
- contents_swizzled,
+ texture_format,
viewport,
1.f,
use_skia_gpu_backend,
@@ -1451,7 +1452,7 @@ TYPED_TEST(RendererPixelTest, PictureDrawQuadOpacity) {
gfx::Size pile_tile_size(1000, 1000);
gfx::Rect viewport(this->device_viewport_size_);
bool use_skia_gpu_backend = this->UseSkiaGPUBackend();
- bool contents_swizzled = !PlatformColor::SameComponentOrder(GL_RGBA);
+ ResourceFormat texture_format = RGBA_8888;
RenderPass::Id id(1, 1);
gfx::Transform transform_to_root;
@@ -1477,7 +1478,7 @@ TYPED_TEST(RendererPixelTest, PictureDrawQuadOpacity) {
gfx::Rect(),
gfx::RectF(0, 0, 1, 1),
viewport.size(),
- contents_swizzled,
+ texture_format,
viewport,
1.f,
use_skia_gpu_backend,
@@ -1502,7 +1503,7 @@ TYPED_TEST(RendererPixelTest, PictureDrawQuadOpacity) {
gfx::Rect(),
gfx::RectF(0, 0, 1, 1),
viewport.size(),
- contents_swizzled,
+ texture_format,
viewport,
1.f,
use_skia_gpu_backend,
@@ -1525,7 +1526,7 @@ TYPED_TEST(RendererPixelTestWithSkiaGPUBackend,
gfx::Rect viewport(this->device_viewport_size_);
bool use_skia_gpu_backend = this->UseSkiaGPUBackend();
// TODO(enne): the renderer should figure this out on its own.
- bool contents_swizzled = !PlatformColor::SameComponentOrder(GL_RGBA);
+ ResourceFormat texture_format = RGBA_8888;
RenderPass::Id id(1, 1);
gfx::Transform transform_to_root;
@@ -1559,7 +1560,7 @@ TYPED_TEST(RendererPixelTestWithSkiaGPUBackend,
gfx::Rect(),
gfx::RectF(green_rect1.size()),
green_rect1.size(),
- contents_swizzled,
+ texture_format,
green_rect1,
1.f,
use_skia_gpu_backend,
@@ -1572,7 +1573,7 @@ TYPED_TEST(RendererPixelTestWithSkiaGPUBackend,
gfx::Rect(),
gfx::RectF(green_rect2.size()),
green_rect2.size(),
- contents_swizzled,
+ texture_format,
green_rect2,
1.f,
use_skia_gpu_backend,
@@ -1644,7 +1645,7 @@ TYPED_TEST(RendererPixelTestWithSkiaGPUBackend,
gfx::Rect(),
quad_content_rect,
content_union_rect.size(),
- contents_swizzled,
+ texture_format,
content_union_rect,
contents_scale,
use_skia_gpu_backend,
diff --git a/cc/output/software_renderer_unittest.cc b/cc/output/software_renderer_unittest.cc
index 6f61525..03f1635 100644
--- a/cc/output/software_renderer_unittest.cc
+++ b/cc/output/software_renderer_unittest.cc
@@ -33,7 +33,8 @@ class SoftwareRendererTest : public testing::Test, public RendererClient {
software_output_device.Pass());
CHECK(output_surface_->BindToClient(&output_surface_client_));
- resource_provider_ = ResourceProvider::Create(output_surface_.get(), 0);
+ resource_provider_ =
+ ResourceProvider::Create(output_surface_.get(), 0, false);
renderer_ = SoftwareRenderer::Create(
this, &settings_, output_surface_.get(), resource_provider());
}
@@ -124,13 +125,15 @@ TEST_F(SoftwareRendererTest, TileQuad) {
InitializeRenderer(make_scoped_ptr(new SoftwareOutputDevice));
ResourceProvider::ResourceId resource_yellow =
- resource_provider()->CreateResource(
- outer_size, GL_RGBA, GL_CLAMP_TO_EDGE,
- ResourceProvider::TextureUsageAny);
+ resource_provider()->CreateResource(outer_size,
+ GL_CLAMP_TO_EDGE,
+ ResourceProvider::TextureUsageAny,
+ RGBA_8888);
ResourceProvider::ResourceId resource_cyan =
- resource_provider()->CreateResource(
- inner_size, GL_RGBA, GL_CLAMP_TO_EDGE,
- ResourceProvider::TextureUsageAny);
+ resource_provider()->CreateResource(inner_size,
+ GL_CLAMP_TO_EDGE,
+ ResourceProvider::TextureUsageAny,
+ RGBA_8888);
SkBitmap yellow_tile;
yellow_tile.setConfig(
@@ -214,9 +217,10 @@ TEST_F(SoftwareRendererTest, TileQuadVisibleRect) {
InitializeRenderer(make_scoped_ptr(new SoftwareOutputDevice));
ResourceProvider::ResourceId resource_cyan =
- resource_provider()->CreateResource(
- tile_size, GL_RGBA, GL_CLAMP_TO_EDGE,
- ResourceProvider::TextureUsageAny);
+ resource_provider()->CreateResource(tile_size,
+ GL_CLAMP_TO_EDGE,
+ ResourceProvider::TextureUsageAny,
+ RGBA_8888);
SkBitmap cyan_tile; // The lowest five rows are yellow.
cyan_tile.setConfig(
diff --git a/cc/quads/draw_quad_unittest.cc b/cc/quads/draw_quad_unittest.cc
index 0ab0513..5705ce7 100644
--- a/cc/quads/draw_quad_unittest.cc
+++ b/cc/quads/draw_quad_unittest.cc
@@ -665,7 +665,7 @@ TEST(DrawQuadTest, CopyPictureDrawQuad) {
gfx::Rect opaque_rect(33, 44, 22, 33);
gfx::RectF tex_coord_rect(31.f, 12.f, 54.f, 20.f);
gfx::Size texture_size(85, 32);
- bool swizzle_contents = true;
+ ResourceFormat texture_format = RGBA_8888;
gfx::Rect content_rect(30, 40, 20, 30);
float contents_scale = 3.141592f;
bool can_draw_direct_to_backbuffer = true;
@@ -676,7 +676,7 @@ TEST(DrawQuadTest, CopyPictureDrawQuad) {
opaque_rect,
tex_coord_rect,
texture_size,
- swizzle_contents,
+ texture_format,
content_rect,
contents_scale,
can_draw_direct_to_backbuffer,
@@ -685,7 +685,7 @@ TEST(DrawQuadTest, CopyPictureDrawQuad) {
EXPECT_RECT_EQ(opaque_rect, copy_quad->opaque_rect);
EXPECT_EQ(tex_coord_rect, copy_quad->tex_coord_rect);
EXPECT_EQ(texture_size, copy_quad->texture_size);
- EXPECT_EQ(swizzle_contents, copy_quad->swizzle_contents);
+ EXPECT_EQ(texture_format, copy_quad->texture_format);
EXPECT_RECT_EQ(content_rect, copy_quad->content_rect);
EXPECT_EQ(contents_scale, copy_quad->contents_scale);
EXPECT_EQ(can_draw_direct_to_backbuffer,
@@ -695,7 +695,7 @@ TEST(DrawQuadTest, CopyPictureDrawQuad) {
CREATE_QUAD_7_ALL(PictureDrawQuad,
tex_coord_rect,
texture_size,
- swizzle_contents,
+ texture_format,
content_rect,
contents_scale,
can_draw_direct_to_backbuffer,
@@ -703,7 +703,7 @@ TEST(DrawQuadTest, CopyPictureDrawQuad) {
EXPECT_EQ(DrawQuad::PICTURE_CONTENT, copy_quad->material);
EXPECT_EQ(tex_coord_rect, copy_quad->tex_coord_rect);
EXPECT_EQ(texture_size, copy_quad->texture_size);
- EXPECT_EQ(swizzle_contents, copy_quad->swizzle_contents);
+ EXPECT_EQ(texture_format, copy_quad->texture_format);
EXPECT_RECT_EQ(content_rect, copy_quad->content_rect);
EXPECT_EQ(contents_scale, copy_quad->contents_scale);
EXPECT_EQ(can_draw_direct_to_backbuffer,
@@ -893,7 +893,7 @@ TEST_F(DrawQuadIteratorTest, DISABLED_PictureDrawQuad) {
gfx::Rect opaque_rect(33, 44, 22, 33);
gfx::RectF tex_coord_rect(31.f, 12.f, 54.f, 20.f);
gfx::Size texture_size(85, 32);
- bool swizzle_contents = true;
+ ResourceFormat texture_format = RGBA_8888;
gfx::Rect content_rect(30, 40, 20, 30);
float contents_scale = 3.141592f;
bool can_draw_direct_to_backbuffer = true;
@@ -904,7 +904,7 @@ TEST_F(DrawQuadIteratorTest, DISABLED_PictureDrawQuad) {
opaque_rect,
tex_coord_rect,
texture_size,
- swizzle_contents,
+ texture_format,
content_rect,
contents_scale,
can_draw_direct_to_backbuffer,
diff --git a/cc/quads/picture_draw_quad.cc b/cc/quads/picture_draw_quad.cc
index 0494764..e566b24 100644
--- a/cc/quads/picture_draw_quad.cc
+++ b/cc/quads/picture_draw_quad.cc
@@ -6,6 +6,7 @@
#include "base/values.h"
#include "cc/base/math_util.h"
+#include "cc/resources/platform_color.h"
namespace cc {
@@ -24,18 +25,24 @@ void PictureDrawQuad::SetNew(const SharedQuadState* shared_quad_state,
gfx::Rect opaque_rect,
const gfx::RectF& tex_coord_rect,
gfx::Size texture_size,
- bool swizzle_contents,
+ ResourceFormat texture_format,
gfx::Rect content_rect,
float contents_scale,
bool can_draw_direct_to_backbuffer,
scoped_refptr<PicturePileImpl> picture_pile) {
- ContentDrawQuadBase::SetNew(shared_quad_state, DrawQuad::PICTURE_CONTENT,
- rect, opaque_rect, tex_coord_rect, texture_size,
- swizzle_contents);
+ ContentDrawQuadBase::SetNew(shared_quad_state,
+ DrawQuad::PICTURE_CONTENT,
+ rect,
+ opaque_rect,
+ tex_coord_rect,
+ texture_size,
+ !PlatformColor::SameComponentOrder(
+ texture_format));
this->content_rect = content_rect;
this->contents_scale = contents_scale;
this->can_draw_direct_to_backbuffer = can_draw_direct_to_backbuffer;
this->picture_pile = picture_pile;
+ this->texture_format = texture_format;
}
void PictureDrawQuad::SetAll(const SharedQuadState* shared_quad_state,
@@ -45,19 +52,26 @@ void PictureDrawQuad::SetAll(const SharedQuadState* shared_quad_state,
bool needs_blending,
const gfx::RectF& tex_coord_rect,
gfx::Size texture_size,
- bool swizzle_contents,
+ ResourceFormat texture_format,
gfx::Rect content_rect,
float contents_scale,
bool can_draw_direct_to_backbuffer,
scoped_refptr<PicturePileImpl> picture_pile) {
ContentDrawQuadBase::SetAll(shared_quad_state,
- DrawQuad::PICTURE_CONTENT, rect, opaque_rect,
- visible_rect, needs_blending, tex_coord_rect,
- texture_size, swizzle_contents);
+ DrawQuad::PICTURE_CONTENT,
+ rect,
+ opaque_rect,
+ visible_rect,
+ needs_blending,
+ tex_coord_rect,
+ texture_size,
+ !PlatformColor::SameComponentOrder(
+ texture_format));
this->content_rect = content_rect;
this->contents_scale = contents_scale;
this->can_draw_direct_to_backbuffer = can_draw_direct_to_backbuffer;
this->picture_pile = picture_pile;
+ this->texture_format = texture_format;
}
void PictureDrawQuad::IterateResources(
@@ -77,6 +91,7 @@ void PictureDrawQuad::ExtendValue(base::DictionaryValue* value) const {
value->SetDouble("contents_scale", contents_scale);
value->SetBoolean("can_draw_direct_to_backbuffer",
can_draw_direct_to_backbuffer);
+ value->SetInteger("texture_format", texture_format);
// TODO(piman): picture_pile?
}
diff --git a/cc/quads/picture_draw_quad.h b/cc/quads/picture_draw_quad.h
index beec88c..756482a 100644
--- a/cc/quads/picture_draw_quad.h
+++ b/cc/quads/picture_draw_quad.h
@@ -27,7 +27,7 @@ class CC_EXPORT PictureDrawQuad : public ContentDrawQuadBase {
gfx::Rect opaque_rect,
const gfx::RectF& tex_coord_rect,
gfx::Size texture_size,
- bool swizzle_contents,
+ ResourceFormat texture_format,
gfx::Rect content_rect,
float contents_scale,
bool can_draw_direct_to_backbuffer,
@@ -40,7 +40,7 @@ class CC_EXPORT PictureDrawQuad : public ContentDrawQuadBase {
bool needs_blending,
const gfx::RectF& tex_coord_rect,
gfx::Size texture_size,
- bool swizzle_contents,
+ ResourceFormat texture_format,
gfx::Rect content_rect,
float contents_scale,
bool can_draw_direct_to_backbuffer,
@@ -50,6 +50,7 @@ class CC_EXPORT PictureDrawQuad : public ContentDrawQuadBase {
float contents_scale;
bool can_draw_direct_to_backbuffer;
scoped_refptr<PicturePileImpl> picture_pile;
+ ResourceFormat texture_format;
virtual void IterateResources(const ResourceIteratorCallback& callback)
OVERRIDE;
diff --git a/cc/resources/image_raster_worker_pool.cc b/cc/resources/image_raster_worker_pool.cc
index 9862484..2dfc090 100644
--- a/cc/resources/image_raster_worker_pool.cc
+++ b/cc/resources/image_raster_worker_pool.cc
@@ -34,14 +34,10 @@ class ImageWorkerPoolTaskImpl : public internal::WorkerPoolTask {
if (!buffer_)
return;
- SkBitmap bitmap;
- bitmap.setConfig(SkBitmap::kARGB_8888_Config,
- task_->resource()->size().width(),
- task_->resource()->size().height(),
- stride_);
- bitmap.setPixels(buffer_);
- SkBitmapDevice device(bitmap);
- task_->RunOnWorkerThread(&device, thread_index);
+ task_->RunOnWorkerThread(thread_index,
+ buffer_,
+ task_->resource()->size(),
+ stride_);
}
virtual void CompleteOnOriginThread() OVERRIDE {
reply_.Run(!HasFinishedRunning());
@@ -156,8 +152,9 @@ void ImageRasterWorkerPool::ScheduleTasks(RasterTask::Queue* queue) {
"state", TracedValue::FromValue(StateAsValue().release()));
}
-GLenum ImageRasterWorkerPool::GetResourceFormat() const {
- return GL_RGBA; // Only format supported by CHROMIUM_map_image
+ResourceFormat ImageRasterWorkerPool::GetResourceFormat() const {
+ // Only format supported by CHROMIUM_map_image
+ return RGBA_8888;
}
void ImageRasterWorkerPool::OnRasterTasksFinished() {
diff --git a/cc/resources/image_raster_worker_pool.h b/cc/resources/image_raster_worker_pool.h
index 1816b27..63526493 100644
--- a/cc/resources/image_raster_worker_pool.h
+++ b/cc/resources/image_raster_worker_pool.h
@@ -21,7 +21,7 @@ class CC_EXPORT ImageRasterWorkerPool : public RasterWorkerPool {
// Overridden from RasterWorkerPool:
virtual void ScheduleTasks(RasterTask::Queue* queue) OVERRIDE;
- virtual GLenum GetResourceFormat() const OVERRIDE;
+ virtual ResourceFormat GetResourceFormat() const OVERRIDE;
virtual void OnRasterTasksFinished() OVERRIDE;
virtual void OnRasterTasksRequiredForActivationFinished() OVERRIDE;
diff --git a/cc/resources/picture_layer_tiling_set_unittest.cc b/cc/resources/picture_layer_tiling_set_unittest.cc
index db72ade..231e378 100644
--- a/cc/resources/picture_layer_tiling_set_unittest.cc
+++ b/cc/resources/picture_layer_tiling_set_unittest.cc
@@ -66,7 +66,7 @@ class PictureLayerTilingSetTestWithResources : public testing::Test {
CHECK(output_surface->BindToClient(&output_surface_client));
scoped_ptr<ResourceProvider> resource_provider =
- ResourceProvider::Create(output_surface.get(), 0);
+ ResourceProvider::Create(output_surface.get(), 0, false);
FakePictureLayerTilingClient client;
client.SetTileSize(gfx::Size(256, 256));
diff --git a/cc/resources/pixel_buffer_raster_worker_pool.cc b/cc/resources/pixel_buffer_raster_worker_pool.cc
index a7d9b31..e831b3a 100644
--- a/cc/resources/pixel_buffer_raster_worker_pool.cc
+++ b/cc/resources/pixel_buffer_raster_worker_pool.cc
@@ -41,13 +41,10 @@ class PixelBufferWorkerPoolTaskImpl : public internal::WorkerPoolTask {
needs_upload_ = true;
return;
}
- SkBitmap bitmap;
- bitmap.setConfig(SkBitmap::kARGB_8888_Config,
- task_->resource()->size().width(),
- task_->resource()->size().height());
- bitmap.setPixels(buffer_);
- SkBitmapDevice device(bitmap);
- needs_upload_ = task_->RunOnWorkerThread(&device, thread_index);
+ needs_upload_ = task_->RunOnWorkerThread(thread_index,
+ buffer_,
+ task_->resource()->size(),
+ 0);
}
virtual void CompleteOnOriginThread() OVERRIDE {
// |needs_upload_| must be be false if task didn't run.
@@ -219,8 +216,8 @@ void PixelBufferRasterWorkerPool::ScheduleTasks(RasterTask::Queue* queue) {
"state", TracedValue::FromValue(StateAsValue().release()));
}
-GLenum PixelBufferRasterWorkerPool::GetResourceFormat() const {
- return resource_provider()->best_texture_format();
+ResourceFormat PixelBufferRasterWorkerPool::GetResourceFormat() const {
+ return resource_provider()->memory_efficient_texture_format();
}
void PixelBufferRasterWorkerPool::CheckForCompletedTasks() {
diff --git a/cc/resources/pixel_buffer_raster_worker_pool.h b/cc/resources/pixel_buffer_raster_worker_pool.h
index 980fe54..a856d8a 100644
--- a/cc/resources/pixel_buffer_raster_worker_pool.h
+++ b/cc/resources/pixel_buffer_raster_worker_pool.h
@@ -34,7 +34,7 @@ class CC_EXPORT PixelBufferRasterWorkerPool : public RasterWorkerPool {
// Overridden from RasterWorkerPool:
virtual void ScheduleTasks(RasterTask::Queue* queue) OVERRIDE;
- virtual GLenum GetResourceFormat() const OVERRIDE;
+ virtual ResourceFormat GetResourceFormat() const OVERRIDE;
virtual void OnRasterTasksFinished() OVERRIDE;
virtual void OnRasterTasksRequiredForActivationFinished() OVERRIDE;
@@ -81,6 +81,7 @@ class CC_EXPORT PixelBufferRasterWorkerPool : public RasterWorkerPool {
bool should_notify_client_if_no_tasks_are_pending_;
bool should_notify_client_if_no_tasks_required_for_activation_are_pending_;
+ ResourceFormat format_;
DISALLOW_COPY_AND_ASSIGN(PixelBufferRasterWorkerPool);
};
diff --git a/cc/resources/platform_color.h b/cc/resources/platform_color.h
index bd27d82..ecdf7c1 100644
--- a/cc/resources/platform_color.h
+++ b/cc/resources/platform_color.h
@@ -7,6 +7,7 @@
#include "base/basictypes.h"
#include "base/logging.h"
+#include "cc/resources/resource_format.h"
#include "third_party/khronos/GLES2/gl2.h"
#include "third_party/khronos/GLES2/gl2ext.h"
#include "third_party/skia/include/core/SkTypes.h"
@@ -25,27 +26,25 @@ class PlatformColor {
}
// Returns the most efficient texture format for this platform.
- static GLenum BestTextureFormat(bool supports_bgra8888) {
+ static ResourceFormat BestTextureFormat(bool supports_bgra8888) {
switch (Format()) {
case SOURCE_FORMAT_BGRA8:
- if (supports_bgra8888)
- return GL_BGRA_EXT;
- return GL_RGBA;
+ return (supports_bgra8888) ? BGRA_8888 : RGBA_8888;
case SOURCE_FORMAT_RGBA8:
- return GL_RGBA;
+ return RGBA_8888;
}
NOTREACHED();
- return GL_RGBA;
+ return RGBA_8888;
}
// Return true if the given texture format has the same component order
// as the color on this platform.
- static bool SameComponentOrder(GLenum texture_format) {
+ static bool SameComponentOrder(ResourceFormat format) {
switch (Format()) {
case SOURCE_FORMAT_RGBA8:
- return texture_format == GL_RGBA;
+ return format == RGBA_8888 || format == RGBA_4444;
case SOURCE_FORMAT_BGRA8:
- return texture_format == GL_BGRA_EXT;
+ return format == BGRA_8888;
}
NOTREACHED();
return false;
diff --git a/cc/resources/prioritized_resource.cc b/cc/resources/prioritized_resource.cc
index 78fd900..313b275 100644
--- a/cc/resources/prioritized_resource.cc
+++ b/cc/resources/prioritized_resource.cc
@@ -15,7 +15,7 @@ namespace cc {
PrioritizedResource::PrioritizedResource(PrioritizedResourceManager* manager,
gfx::Size size,
- GLenum format)
+ ResourceFormat format)
: size_(size),
format_(format),
bytes_(0),
@@ -25,10 +25,7 @@ PrioritizedResource::PrioritizedResource(PrioritizedResourceManager* manager,
is_self_managed_(false),
backing_(NULL),
manager_(NULL) {
- // manager_ is set in RegisterTexture() so validity can be checked.
- DCHECK(format || size.IsEmpty());
- if (format)
- bytes_ = Resource::MemorySizeBytes(size, format);
+ bytes_ = Resource::MemorySizeBytes(size, format);
if (manager)
manager->RegisterTexture(this);
}
@@ -48,7 +45,7 @@ void PrioritizedResource::SetTextureManager(
manager->RegisterTexture(this);
}
-void PrioritizedResource::SetDimensions(gfx::Size size, GLenum format) {
+void PrioritizedResource::SetDimensions(gfx::Size size, ResourceFormat format) {
if (format_ != format || size_ != size) {
is_above_priority_cutoff_ = false;
format_ = format;
@@ -113,7 +110,7 @@ void PrioritizedResource::Unlink() {
}
void PrioritizedResource::SetToSelfManagedMemoryPlaceholder(size_t bytes) {
- SetDimensions(gfx::Size(), GL_RGBA);
+ SetDimensions(gfx::Size(), RGBA_8888);
set_is_self_managed(true);
bytes_ = bytes;
}
@@ -121,7 +118,7 @@ void PrioritizedResource::SetToSelfManagedMemoryPlaceholder(size_t bytes) {
PrioritizedResource::Backing::Backing(unsigned id,
ResourceProvider* resource_provider,
gfx::Size size,
- GLenum format)
+ ResourceFormat format)
: Resource(id, size, format),
owner_(NULL),
priority_at_last_priority_update_(PriorityCalculator::LowestPriority()),
diff --git a/cc/resources/prioritized_resource.h b/cc/resources/prioritized_resource.h
index 07e0787..a3d5d89 100644
--- a/cc/resources/prioritized_resource.h
+++ b/cc/resources/prioritized_resource.h
@@ -12,7 +12,6 @@
#include "cc/resources/priority_calculator.h"
#include "cc/resources/resource.h"
#include "cc/resources/resource_provider.h"
-#include "third_party/khronos/GLES2/gl2.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
#include "ui/gfx/vector2d.h"
@@ -24,13 +23,16 @@ class Proxy;
class CC_EXPORT PrioritizedResource {
public:
- static scoped_ptr<PrioritizedResource>
- Create(PrioritizedResourceManager* manager, gfx::Size size, GLenum format) {
+ static scoped_ptr<PrioritizedResource> Create(
+ PrioritizedResourceManager* manager,
+ gfx::Size size,
+ ResourceFormat format) {
return make_scoped_ptr(new PrioritizedResource(manager, size, format));
}
static scoped_ptr<PrioritizedResource> Create(
PrioritizedResourceManager* manager) {
- return make_scoped_ptr(new PrioritizedResource(manager, gfx::Size(), 0));
+ return make_scoped_ptr(
+ new PrioritizedResource(manager, gfx::Size(), RGBA_8888));
}
~PrioritizedResource();
@@ -38,8 +40,8 @@ class CC_EXPORT PrioritizedResource {
// Setting these to the same value is a no-op.
void SetTextureManager(PrioritizedResourceManager* manager);
PrioritizedResourceManager* resource_manager() { return manager_; }
- void SetDimensions(gfx::Size size, GLenum format);
- GLenum format() const { return format_; }
+ void SetDimensions(gfx::Size size, ResourceFormat format);
+ ResourceFormat format() const { return format_; }
gfx::Size size() const { return size_; }
size_t bytes() const { return bytes_; }
bool contents_swizzled() const { return contents_swizzled_; }
@@ -106,7 +108,7 @@ class CC_EXPORT PrioritizedResource {
Backing(unsigned id,
ResourceProvider* resource_provider,
gfx::Size size,
- GLenum format);
+ ResourceFormat format);
~Backing();
void UpdatePriority();
void UpdateInDrawingImplTree();
@@ -146,7 +148,7 @@ class CC_EXPORT PrioritizedResource {
PrioritizedResource(PrioritizedResourceManager* resource_manager,
gfx::Size size,
- GLenum format);
+ ResourceFormat format);
bool is_above_priority_cutoff() { return is_above_priority_cutoff_; }
void set_above_priority_cutoff(bool is_above_priority_cutoff) {
@@ -161,7 +163,7 @@ class CC_EXPORT PrioritizedResource {
void Unlink();
gfx::Size size_;
- GLenum format_;
+ ResourceFormat format_;
size_t bytes_;
bool contents_swizzled_;
diff --git a/cc/resources/prioritized_resource_manager.cc b/cc/resources/prioritized_resource_manager.cc
index e0b5dca..1a6e545 100644
--- a/cc/resources/prioritized_resource_manager.cc
+++ b/cc/resources/prioritized_resource_manager.cc
@@ -449,13 +449,16 @@ void PrioritizedResourceManager::ReturnBackingTexture(
PrioritizedResource::Backing* PrioritizedResourceManager::CreateBacking(
gfx::Size size,
- GLenum format,
+ ResourceFormat format,
ResourceProvider* resource_provider) {
DCHECK(proxy_->IsImplThread() && proxy_->IsMainThreadBlocked());
DCHECK(resource_provider);
ResourceProvider::ResourceId resource_id =
resource_provider->CreateManagedResource(
- size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
+ size,
+ GL_CLAMP_TO_EDGE,
+ ResourceProvider::TextureUsageAny,
+ format);
PrioritizedResource::Backing* backing = new PrioritizedResource::Backing(
resource_id, resource_provider, size, format);
memory_use_bytes_ += backing->bytes();
diff --git a/cc/resources/prioritized_resource_manager.h b/cc/resources/prioritized_resource_manager.h
index 7396772..2374a1e 100644
--- a/cc/resources/prioritized_resource_manager.h
+++ b/cc/resources/prioritized_resource_manager.h
@@ -17,7 +17,6 @@
#include "cc/resources/priority_calculator.h"
#include "cc/resources/resource.h"
#include "cc/trees/proxy.h"
-#include "third_party/khronos/GLES2/gl2.h"
#include "ui/gfx/size.h"
#if defined(COMPILER_GCC)
@@ -40,7 +39,8 @@ class CC_EXPORT PrioritizedResourceManager {
static scoped_ptr<PrioritizedResourceManager> Create(const Proxy* proxy) {
return make_scoped_ptr(new PrioritizedResourceManager(proxy));
}
- scoped_ptr<PrioritizedResource> CreateTexture(gfx::Size size, GLenum format) {
+ scoped_ptr<PrioritizedResource> CreateTexture(
+ gfx::Size size, ResourceFormat format) {
return make_scoped_ptr(new PrioritizedResource(this, size, format));
}
~PrioritizedResourceManager();
@@ -184,7 +184,7 @@ class CC_EXPORT PrioritizedResourceManager {
ResourceProvider* resource_provider);
PrioritizedResource::Backing* CreateBacking(
gfx::Size size,
- GLenum format,
+ ResourceFormat format,
ResourceProvider* resource_provider);
void EvictFirstBackingResource(ResourceProvider* resource_provider);
void SortBackings();
diff --git a/cc/resources/prioritized_resource_unittest.cc b/cc/resources/prioritized_resource_unittest.cc
index 91b1c2e..181498c 100644
--- a/cc/resources/prioritized_resource_unittest.cc
+++ b/cc/resources/prioritized_resource_unittest.cc
@@ -19,11 +19,12 @@ class PrioritizedResourceTest : public testing::Test {
public:
PrioritizedResourceTest()
: texture_size_(256, 256),
- texture_format_(GL_RGBA),
+ texture_format_(RGBA_8888),
output_surface_(FakeOutputSurface::Create3d()) {
DebugScopedSetImplThread impl_thread(&proxy_);
CHECK(output_surface_->BindToClient(&output_surface_client_));
- resource_provider_ = cc::ResourceProvider::Create(output_surface_.get(), 0);
+ resource_provider_ =
+ cc::ResourceProvider::Create(output_surface_.get(), 0, false);
}
virtual ~PrioritizedResourceTest() {
@@ -93,7 +94,7 @@ class PrioritizedResourceTest : public testing::Test {
protected:
FakeProxy proxy_;
const gfx::Size texture_size_;
- const GLenum texture_format_;
+ const ResourceFormat texture_format_;
FakeOutputSurfaceClient output_surface_client_;
scoped_ptr<OutputSurface> output_surface_;
scoped_ptr<cc::ResourceProvider> resource_provider_;
diff --git a/cc/resources/prioritized_tile_set_unittest.cc b/cc/resources/prioritized_tile_set_unittest.cc
index 45c714f..7de1032 100644
--- a/cc/resources/prioritized_tile_set_unittest.cc
+++ b/cc/resources/prioritized_tile_set_unittest.cc
@@ -56,8 +56,8 @@ class PrioritizedTileSetTest : public testing::Test {
output_surface_ = FakeOutputSurface::Create3d().Pass();
CHECK(output_surface_->BindToClient(&output_surface_client_));
- resource_provider_ = ResourceProvider::Create(output_surface_.get(),
- 0).Pass();
+ resource_provider_ =
+ ResourceProvider::Create(output_surface_.get(), 0, false).Pass();
tile_manager_.reset(new FakeTileManager(&tile_manager_client_,
resource_provider_.get()));
picture_pile_ = FakePicturePileImpl::CreatePile();
diff --git a/cc/resources/raster_worker_pool.cc b/cc/resources/raster_worker_pool.cc
index 15b8aa4..6f80cc3 100644
--- a/cc/resources/raster_worker_pool.cc
+++ b/cc/resources/raster_worker_pool.cc
@@ -13,11 +13,25 @@
#include "cc/resources/picture_pile_impl.h"
#include "skia/ext/lazy_pixel_ref.h"
#include "skia/ext/paint_simplifier.h"
+#include "third_party/skia/include/core/SkBitmap.h"
namespace cc {
namespace {
+// Subclass of Allocator that takes a suitably allocated pointer and uses
+// it as the pixel memory for the bitmap.
+class IdentityAllocator : public SkBitmap::Allocator {
+ public:
+ explicit IdentityAllocator(void* buffer) : buffer_(buffer) {}
+ virtual bool allocPixelRef(SkBitmap* dst, SkColorTable*) OVERRIDE {
+ dst->setPixels(buffer_);
+ return true;
+ }
+ private:
+ void* buffer_;
+};
+
// Flag to indicate whether we should try and detect that
// a tile is of solid color.
const bool kUseColorEstimator = true;
@@ -89,7 +103,10 @@ class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask {
analysis_.is_solid_color &= kUseColorEstimator;
}
- bool RunRasterOnThread(SkBaseDevice* device, unsigned thread_index) {
+ bool RunRasterOnThread(unsigned thread_index,
+ void* buffer,
+ gfx::Size size,
+ int stride) {
TRACE_EVENT2(
benchmark_instrumentation::kCategory,
benchmark_instrumentation::kRunRasterOnThread,
@@ -102,7 +119,7 @@ class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask {
devtools_instrumentation::kRasterTask, layer_id_);
DCHECK(picture_pile_.get());
- DCHECK(device);
+ DCHECK(buffer);
if (analysis_.is_solid_color)
return false;
@@ -110,8 +127,31 @@ class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask {
PicturePileImpl* picture_clone =
picture_pile_->GetCloneForDrawingOnThread(thread_index);
- SkCanvas canvas(device);
+ SkBitmap bitmap;
+ switch (resource()->format()) {
+ case RGBA_4444:
+ // Use the default stride if we will eventually convert this
+ // bitmap to 4444.
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config,
+ size.width(),
+ size.height());
+ bitmap.allocPixels();
+ break;
+ case RGBA_8888:
+ case BGRA_8888:
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config,
+ size.width(),
+ size.height(),
+ stride);
+ bitmap.setPixels(buffer);
+ break;
+ case LUMINANCE_8:
+ NOTREACHED();
+ break;
+ }
+ SkBitmapDevice device(bitmap);
+ SkCanvas canvas(&device);
skia::RefPtr<SkDrawFilter> draw_filter;
switch (raster_mode_) {
case LOW_QUALITY_RASTER_MODE:
@@ -149,14 +189,20 @@ class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask {
picture_clone->RasterToBitmap(
&canvas, content_rect_, contents_scale_, NULL);
}
+
+ ChangeBitmapConfigIfNeeded(bitmap, buffer);
+
return true;
}
// Overridden from internal::RasterWorkerPoolTask:
- virtual bool RunOnWorkerThread(SkBaseDevice* device, unsigned thread_index)
+ virtual bool RunOnWorkerThread(unsigned thread_index,
+ void* buffer,
+ gfx::Size size,
+ int stride)
OVERRIDE {
RunAnalysisOnThread(thread_index);
- return RunRasterOnThread(device, thread_index);
+ return RunRasterOnThread(thread_index, buffer, size, stride);
}
virtual void CompleteOnOriginThread() OVERRIDE {
reply_.Run(analysis_, !HasFinishedRunning() || WasCanceled());
@@ -177,6 +223,21 @@ class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask {
return res.PassAs<base::Value>();
}
+ void ChangeBitmapConfigIfNeeded(const SkBitmap& bitmap,
+ void* buffer) {
+ TRACE_EVENT0("cc", "RasterWorkerPoolTaskImpl::ChangeBitmapConfigIfNeeded");
+ SkBitmap::Config config = SkBitmapConfigFromFormat(
+ resource()->format());
+ if (bitmap.getConfig() != config) {
+ SkBitmap bitmap_dest;
+ IdentityAllocator allocator(buffer);
+ bitmap.copyTo(&bitmap_dest, config, &allocator);
+ // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the
+ // bitmap data. This check will be removed once crbug.com/293728 is fixed.
+ CHECK_EQ(0u, bitmap_dest.rowBytes() % 4);
+ }
+ }
+
PicturePileImpl::Analysis analysis_;
scoped_refptr<PicturePileImpl> picture_pile_;
gfx::Rect content_rect_;
diff --git a/cc/resources/raster_worker_pool.h b/cc/resources/raster_worker_pool.h
index a53e52f..b12a1b4 100644
--- a/cc/resources/raster_worker_pool.h
+++ b/cc/resources/raster_worker_pool.h
@@ -11,11 +11,11 @@
#include "cc/debug/rendering_stats_instrumentation.h"
#include "cc/resources/picture_pile_impl.h"
#include "cc/resources/raster_mode.h"
+#include "cc/resources/resource.h"
+#include "cc/resources/resource_provider.h"
#include "cc/resources/tile_priority.h"
#include "cc/resources/worker_pool.h"
#include "third_party/khronos/GLES2/gl2.h"
-// TODO(robertphillips): change this to "class SkBaseDevice;"
-#include "third_party/skia/include/core/SkDevice.h"
namespace skia {
class LazyPixelRef;
@@ -24,7 +24,6 @@ class LazyPixelRef;
namespace cc {
class PicturePileImpl;
class PixelBufferRasterWorkerPool;
-class Resource;
class ResourceProvider;
namespace internal {
@@ -34,11 +33,13 @@ class CC_EXPORT RasterWorkerPoolTask
public:
typedef std::vector<scoped_refptr<WorkerPoolTask> > TaskVector;
- // Returns true if |device| was written to. False indicate that
- // the content of |device| is undefined and the resource doesn't
+ // Returns true if |buffer| was written to. False indicate that
+ // the content of |buffer| is undefined and the resource doesn't
// need to be initialized.
- virtual bool RunOnWorkerThread(SkBaseDevice* device,
- unsigned thread_index) = 0;
+ virtual bool RunOnWorkerThread(unsigned thread_index,
+ void* buffer,
+ gfx::Size size,
+ int stride) = 0;
virtual void CompleteOnOriginThread() = 0;
void DidRun(bool was_canceled);
@@ -186,7 +187,7 @@ class CC_EXPORT RasterWorkerPool : public WorkerPool {
virtual void ScheduleTasks(RasterTask::Queue* queue) = 0;
// Returns the format that needs to be used for raster task resources.
- virtual GLenum GetResourceFormat() const = 0;
+ virtual ResourceFormat GetResourceFormat() const = 0;
// TODO(vmpstr): Figure out an elegant way to not pass this many parameters.
static RasterTask CreateRasterTask(
diff --git a/cc/resources/raster_worker_pool_perftest.cc b/cc/resources/raster_worker_pool_perftest.cc
index fbcdb24..cec9c48 100644
--- a/cc/resources/raster_worker_pool_perftest.cc
+++ b/cc/resources/raster_worker_pool_perftest.cc
@@ -40,9 +40,9 @@ class PerfRasterWorkerPool : public RasterWorkerPool {
virtual void ScheduleTasks(RasterTask::Queue* queue) OVERRIDE {
NOTREACHED();
}
- virtual GLenum GetResourceFormat() const OVERRIDE {
+ virtual ResourceFormat GetResourceFormat() const OVERRIDE {
NOTREACHED();
- return GL_RGBA;
+ return RGBA_8888;
}
virtual void OnRasterTasksFinished() OVERRIDE {
NOTREACHED();
diff --git a/cc/resources/raster_worker_pool_unittest.cc b/cc/resources/raster_worker_pool_unittest.cc
index ab55bf3..61cb324 100644
--- a/cc/resources/raster_worker_pool_unittest.cc
+++ b/cc/resources/raster_worker_pool_unittest.cc
@@ -35,8 +35,10 @@ class TestRasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask {
did_raster_(false) {}
// Overridden from internal::WorkerPoolTask:
- virtual bool RunOnWorkerThread(SkBaseDevice* device, unsigned thread_index)
- OVERRIDE {
+ virtual bool RunOnWorkerThread(unsigned thread_index,
+ void* buffer,
+ gfx::Size size,
+ int stride) OVERRIDE {
did_raster_ = true;
return true;
}
@@ -65,8 +67,8 @@ class RasterWorkerPoolTest : public testing::Test,
output_surface_ = FakeOutputSurface::Create3d(context_provider_).Pass();
CHECK(output_surface_->BindToClient(&output_surface_client_));
- resource_provider_ = ResourceProvider::Create(output_surface_.get(),
- 0).Pass();
+ resource_provider_ =
+ ResourceProvider::Create(output_surface_.get(), 0, false).Pass();
}
virtual ~RasterWorkerPoolTest() {
resource_provider_.reset();
@@ -104,8 +106,11 @@ class RasterWorkerPoolTest : public testing::Test,
raster_worker_pool_ = ImageRasterWorkerPool::Create(
resource_provider(), 1);
} else {
- raster_worker_pool_ = PixelBufferRasterWorkerPool::Create(
- resource_provider(), 1, std::numeric_limits<size_t>::max());
+ raster_worker_pool_ =
+ PixelBufferRasterWorkerPool::Create(
+ resource_provider(),
+ 1,
+ std::numeric_limits<size_t>::max());
}
raster_worker_pool_->SetClient(this);
@@ -155,7 +160,7 @@ class RasterWorkerPoolTest : public testing::Test,
scoped_ptr<ScopedResource> resource(
ScopedResource::create(resource_provider()));
- resource->Allocate(size, GL_RGBA, ResourceProvider::TextureUsageAny);
+ resource->Allocate(size, ResourceProvider::TextureUsageAny, RGBA_8888);
const Resource* const_resource = resource.get();
RasterWorkerPool::Task::Set empty;
diff --git a/cc/resources/resource.cc b/cc/resources/resource.cc
index 192eaeb..c97db7f 100644
--- a/cc/resources/resource.cc
+++ b/cc/resources/resource.cc
@@ -3,7 +3,6 @@
// found in the LICENSE file.
#include "cc/resources/resource.h"
-#include "third_party/khronos/GLES2/gl2ext.h"
namespace cc {
@@ -14,26 +13,8 @@ size_t Resource::bytes() const {
return MemorySizeBytes(size_, format_);
}
-size_t Resource::BytesPerPixel(GLenum format) {
- size_t components_per_pixel = 0;
- size_t bytes_per_component = 1;
- switch (format) {
- case GL_RGBA:
- case GL_BGRA_EXT:
- components_per_pixel = 4;
- break;
- case GL_LUMINANCE:
- components_per_pixel = 1;
- break;
- default:
- NOTREACHED();
- }
- return components_per_pixel * bytes_per_component;
+size_t Resource::MemorySizeBytes(gfx::Size size, ResourceFormat format) {
+ return ResourceProvider::BytesPerPixel(format) * size.width() * size.height();
}
-size_t Resource::MemorySizeBytes(gfx::Size size, GLenum format) {
- return BytesPerPixel(format) * size.width() * size.height();
-}
-
-
} // namespace cc
diff --git a/cc/resources/resource.h b/cc/resources/resource.h
index 1c65822..d2d104c 100644
--- a/cc/resources/resource.h
+++ b/cc/resources/resource.h
@@ -15,23 +15,21 @@ namespace cc {
class CC_EXPORT Resource {
public:
Resource() : id_(0) {}
- Resource(unsigned id, gfx::Size size, GLenum format)
+ Resource(unsigned id, gfx::Size size, ResourceFormat format)
: id_(id),
size_(size),
format_(format) {}
ResourceProvider::ResourceId id() const { return id_; }
gfx::Size size() const { return size_; }
- GLenum format() const { return format_; }
-
+ ResourceFormat format() const { return format_; }
size_t bytes() const;
- static size_t BytesPerPixel(GLenum format);
- static size_t MemorySizeBytes(gfx::Size size, GLenum format);
+ static size_t MemorySizeBytes(gfx::Size size, ResourceFormat format);
protected:
void set_id(ResourceProvider::ResourceId id) { id_ = id; }
- void set_dimensions(gfx::Size size, GLenum format) {
+ void set_dimensions(gfx::Size size, ResourceFormat format) {
size_ = size;
format_ = format;
}
@@ -39,7 +37,7 @@ class CC_EXPORT Resource {
private:
ResourceProvider::ResourceId id_;
gfx::Size size_;
- GLenum format_;
+ ResourceFormat format_;
DISALLOW_COPY_AND_ASSIGN(Resource);
};
diff --git a/cc/resources/resource_format.cc b/cc/resources/resource_format.cc
new file mode 100644
index 0000000..28bb1e4
--- /dev/null
+++ b/cc/resources/resource_format.cc
@@ -0,0 +1,24 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/resources/resource_format.h"
+
+namespace cc {
+
+SkBitmap::Config SkBitmapConfigFromFormat(ResourceFormat format) {
+ switch (format) {
+ case RGBA_4444:
+ return SkBitmap::kARGB_4444_Config;
+ case RGBA_8888:
+ case BGRA_8888:
+ return SkBitmap::kARGB_8888_Config;
+ case LUMINANCE_8:
+ NOTREACHED();
+ break;
+ }
+ NOTREACHED();
+ return SkBitmap::kARGB_8888_Config;
+}
+
+} // namespace cc
diff --git a/cc/resources/resource_format.h b/cc/resources/resource_format.h
new file mode 100644
index 0000000..4b12d92
--- /dev/null
+++ b/cc/resources/resource_format.h
@@ -0,0 +1,25 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CC_RESOURCES_RESOURCE_FORMAT_H_
+#define CC_RESOURCES_RESOURCE_FORMAT_H_
+
+#include "base/logging.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+
+namespace cc {
+
+enum ResourceFormat {
+ RGBA_8888,
+ RGBA_4444,
+ BGRA_8888,
+ LUMINANCE_8,
+ RESOURCE_FORMAT_MAX = LUMINANCE_8,
+};
+
+SkBitmap::Config SkBitmapConfigFromFormat(ResourceFormat format);
+
+} // namespace cc
+
+#endif // CC_RESOURCES_RESOURCE_FORMAT_H_
diff --git a/cc/resources/resource_pool.cc b/cc/resources/resource_pool.cc
index 75f7d1e..cef86de 100644
--- a/cc/resources/resource_pool.cc
+++ b/cc/resources/resource_pool.cc
@@ -10,12 +10,12 @@ namespace cc {
ResourcePool::Resource::Resource(cc::ResourceProvider* resource_provider,
gfx::Size size,
- GLenum format)
+ ResourceFormat format)
: cc::Resource(resource_provider->CreateManagedResource(
size,
- format,
GL_CLAMP_TO_EDGE,
- ResourceProvider::TextureUsageAny),
+ ResourceProvider::TextureUsageAny,
+ format),
size,
format),
resource_provider_(resource_provider) {
@@ -43,7 +43,7 @@ ResourcePool::~ResourcePool() {
}
scoped_ptr<ResourcePool::Resource> ResourcePool::AcquireResource(
- gfx::Size size, GLenum format) {
+ gfx::Size size, ResourceFormat format) {
for (ResourceList::iterator it = unused_resources_.begin();
it != unused_resources_.end(); ++it) {
Resource* resource = *it;
diff --git a/cc/resources/resource_pool.h b/cc/resources/resource_pool.h
index 771650e..21bbb0a 100644
--- a/cc/resources/resource_pool.h
+++ b/cc/resources/resource_pool.h
@@ -11,9 +11,9 @@
#include "cc/base/cc_export.h"
#include "cc/output/renderer.h"
#include "cc/resources/resource.h"
+#include "cc/resources/resource_format.h"
namespace cc {
-class ResourceProvider;
class CC_EXPORT ResourcePool {
public:
@@ -21,7 +21,7 @@ class CC_EXPORT ResourcePool {
public:
Resource(ResourceProvider* resource_provider,
gfx::Size size,
- GLenum format);
+ ResourceFormat format);
~Resource();
private:
@@ -36,8 +36,8 @@ class CC_EXPORT ResourcePool {
virtual ~ResourcePool();
- scoped_ptr<ResourcePool::Resource> AcquireResource(gfx::Size size,
- GLenum format);
+ scoped_ptr<ResourcePool::Resource> AcquireResource(
+ gfx::Size size, ResourceFormat format);
void ReleaseResource(scoped_ptr<ResourcePool::Resource>);
void SetResourceUsageLimits(size_t max_memory_usage_bytes,
diff --git a/cc/resources/resource_provider.cc b/cc/resources/resource_provider.cc
index 017c2e9..e1cbba5 100644
--- a/cc/resources/resource_provider.cc
+++ b/cc/resources/resource_provider.cc
@@ -12,6 +12,7 @@
#include "base/stl_util.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
+#include "cc/base/util.h"
#include "cc/output/gl_renderer.h" // For the GLC() macro.
#include "cc/resources/platform_color.h"
#include "cc/resources/returned_resource.h"
@@ -34,24 +35,31 @@ namespace {
const double kSoftwareUploadTickRate = 0.000250;
const double kTextureUploadTickRate = 0.004;
-GLenum TextureToStorageFormat(GLenum texture_format) {
+GLenum TextureToStorageFormat(ResourceFormat format) {
GLenum storage_format = GL_RGBA8_OES;
- switch (texture_format) {
- case GL_RGBA:
+ switch (format) {
+ case RGBA_8888:
+ case RGBA_4444:
+ case LUMINANCE_8:
break;
- case GL_BGRA_EXT:
+ case BGRA_8888:
storage_format = GL_BGRA8_EXT;
break;
- default:
- NOTREACHED();
- break;
}
return storage_format;
}
-bool IsTextureFormatSupportedForStorage(GLenum format) {
- return (format == GL_RGBA || format == GL_BGRA_EXT);
+bool IsFormatSupportedForStorage(ResourceFormat format) {
+ switch (format) {
+ case RGBA_8888:
+ case BGRA_8888:
+ return true;
+ case RGBA_4444:
+ case LUMINANCE_8:
+ return false;
+ }
+ return false;
}
class ScopedSetActiveTexture {
@@ -95,7 +103,6 @@ ResourceProvider::Resource::Resource()
enable_read_lock_fences(false),
read_lock_fence(NULL),
size(),
- format(0),
original_filter(0),
filter(0),
target(0),
@@ -103,18 +110,19 @@ ResourceProvider::Resource::Resource()
texture_pool(0),
wrap_mode(0),
hint(TextureUsageAny),
- type(static_cast<ResourceType>(0)) {}
+ type(static_cast<ResourceType>(0)),
+ format(RGBA_8888) {}
ResourceProvider::Resource::~Resource() {}
ResourceProvider::Resource::Resource(
unsigned texture_id,
gfx::Size size,
- GLenum format,
GLenum filter,
GLenum texture_pool,
GLint wrap_mode,
- TextureUsageHint hint)
+ TextureUsageHint hint,
+ ResourceFormat format)
: gl_id(texture_id),
gl_pixel_buffer_id(0),
gl_upload_query_id(0),
@@ -132,7 +140,6 @@ ResourceProvider::Resource::Resource(
enable_read_lock_fences(false),
read_lock_fence(NULL),
size(size),
- format(format),
original_filter(filter),
filter(filter),
target(0),
@@ -140,14 +147,14 @@ ResourceProvider::Resource::Resource(
texture_pool(texture_pool),
wrap_mode(wrap_mode),
hint(hint),
- type(GLTexture) {
+ type(GLTexture),
+ format(format) {
DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT);
}
ResourceProvider::Resource::Resource(
uint8_t* pixels,
gfx::Size size,
- GLenum format,
GLenum filter,
GLint wrap_mode)
: gl_id(0),
@@ -167,7 +174,6 @@ ResourceProvider::Resource::Resource(
enable_read_lock_fences(false),
read_lock_fence(NULL),
size(size),
- format(format),
original_filter(filter),
filter(filter),
target(0),
@@ -175,7 +181,8 @@ ResourceProvider::Resource::Resource(
texture_pool(0),
wrap_mode(wrap_mode),
hint(TextureUsageAny),
- type(Bitmap) {
+ type(Bitmap),
+ format(RGBA_8888) {
DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT);
}
@@ -185,9 +192,12 @@ ResourceProvider::Child::~Child() {}
scoped_ptr<ResourceProvider> ResourceProvider::Create(
OutputSurface* output_surface,
- int highp_threshold_min) {
+ int highp_threshold_min,
+ bool use_rgba_4444_texture_format) {
scoped_ptr<ResourceProvider> resource_provider(
- new ResourceProvider(output_surface, highp_threshold_min));
+ new ResourceProvider(output_surface,
+ highp_threshold_min,
+ use_rgba_4444_texture_format));
bool success = false;
if (resource_provider->Context3d()) {
@@ -217,17 +227,20 @@ bool ResourceProvider::InUseByConsumer(ResourceId id) {
}
ResourceProvider::ResourceId ResourceProvider::CreateResource(
- gfx::Size size, GLenum format, GLint wrap_mode, TextureUsageHint hint) {
+ gfx::Size size,
+ GLint wrap_mode,
+ TextureUsageHint hint,
+ ResourceFormat format) {
DCHECK(!size.IsEmpty());
switch (default_resource_type_) {
case GLTexture:
- return CreateGLTexture(size, format, GL_TEXTURE_POOL_UNMANAGED_CHROMIUM,
- wrap_mode, hint);
+ return CreateGLTexture(size,
+ GL_TEXTURE_POOL_UNMANAGED_CHROMIUM,
+ wrap_mode,
+ hint,
+ format);
case Bitmap:
- // The only wrap_mode currently implemented in software mode is
- // GL_CLAMP_TO_EDGE.
- // http://crbug.com/284796
- DCHECK(format == GL_RGBA);
+ DCHECK_EQ(RGBA_8888, format);
return CreateBitmap(size);
case InvalidType:
break;
@@ -238,14 +251,20 @@ ResourceProvider::ResourceId ResourceProvider::CreateResource(
}
ResourceProvider::ResourceId ResourceProvider::CreateManagedResource(
- gfx::Size size, GLenum format, GLint wrap_mode, TextureUsageHint hint) {
+ gfx::Size size,
+ GLint wrap_mode,
+ TextureUsageHint hint,
+ ResourceFormat format) {
DCHECK(!size.IsEmpty());
switch (default_resource_type_) {
case GLTexture:
- return CreateGLTexture(size, format, GL_TEXTURE_POOL_MANAGED_CHROMIUM,
- wrap_mode, hint);
+ return CreateGLTexture(size,
+ GL_TEXTURE_POOL_MANAGED_CHROMIUM,
+ wrap_mode,
+ hint,
+ format);
case Bitmap:
- DCHECK(format == GL_RGBA);
+ DCHECK_EQ(RGBA_8888, format);
return CreateBitmap(size);
case InvalidType:
break;
@@ -257,16 +276,16 @@ ResourceProvider::ResourceId ResourceProvider::CreateManagedResource(
ResourceProvider::ResourceId ResourceProvider::CreateGLTexture(
gfx::Size size,
- GLenum format,
GLenum texture_pool,
GLint wrap_mode,
- TextureUsageHint hint) {
+ TextureUsageHint hint,
+ ResourceFormat format) {
DCHECK_LE(size.width(), max_texture_size_);
DCHECK_LE(size.height(), max_texture_size_);
DCHECK(thread_checker_.CalledOnValidThread());
ResourceId id = next_id_++;
- Resource resource(0, size, format, GL_LINEAR, texture_pool, wrap_mode, hint);
+ Resource resource(0, size, GL_LINEAR, texture_pool, wrap_mode, hint, format);
resource.allocated = false;
resources_[id] = resource;
return id;
@@ -278,7 +297,7 @@ ResourceProvider::ResourceId ResourceProvider::CreateBitmap(gfx::Size size) {
uint8_t* pixels = new uint8_t[4 * size.GetArea()];
ResourceId id = next_id_++;
- Resource resource(pixels, size, GL_RGBA, GL_LINEAR, GL_CLAMP_TO_EDGE);
+ Resource resource(pixels, size, GL_LINEAR, GL_CLAMP_TO_EDGE);
resource.allocated = true;
resources_[id] = resource;
return id;
@@ -303,8 +322,13 @@ ResourceProvider::CreateResourceFromExternalTexture(
texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
ResourceId id = next_id_++;
- Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE,
- TextureUsageAny);
+ Resource resource(texture_id,
+ gfx::Size(),
+ GL_LINEAR,
+ 0,
+ GL_CLAMP_TO_EDGE,
+ TextureUsageAny,
+ RGBA_8888);
resource.external = true;
resource.allocated = true;
resources_[id] = resource;
@@ -320,15 +344,20 @@ ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox(
DCHECK(mailbox.IsValid());
Resource& resource = resources_[id];
if (mailbox.IsTexture()) {
- resource = Resource(0, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE,
- TextureUsageAny);
+ resource = Resource(0,
+ gfx::Size(),
+ GL_LINEAR,
+ 0,
+ GL_CLAMP_TO_EDGE,
+ TextureUsageAny,
+ RGBA_8888);
} else {
DCHECK(mailbox.IsSharedMemory());
base::SharedMemory* shared_memory = mailbox.shared_memory();
DCHECK(shared_memory->memory());
uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory());
- resource = Resource(pixels, mailbox.shared_memory_size(),
- GL_RGBA, GL_LINEAR, GL_CLAMP_TO_EDGE);
+ resource = Resource(
+ pixels, mailbox.shared_memory_size(), GL_LINEAR, GL_CLAMP_TO_EDGE);
}
resource.external = true;
resource.allocated = true;
@@ -448,7 +477,7 @@ void ResourceProvider::SetPixels(ResourceId id,
if (resource->pixels) {
DCHECK(resource->allocated);
- DCHECK(resource->format == GL_RGBA);
+ DCHECK_EQ(RGBA_8888, resource->format);
SkBitmap src_full;
src_full.setConfig(
SkBitmap::kARGB_8888_Config, image_rect.width(), image_rect.height());
@@ -672,7 +701,7 @@ ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() {
void ResourceProvider::PopulateSkBitmapWithResource(
SkBitmap* sk_bitmap, const Resource* resource) {
DCHECK(resource->pixels);
- DCHECK(resource->format == GL_RGBA);
+ DCHECK_EQ(RGBA_8888, resource->format);
sk_bitmap->setConfig(SkBitmap::kARGB_8888_Config,
resource->size.width(),
resource->size.height());
@@ -707,7 +736,8 @@ ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() {
}
ResourceProvider::ResourceProvider(OutputSurface* output_surface,
- int highp_threshold_min)
+ int highp_threshold_min,
+ bool use_rgba_4444_texture_format)
: output_surface_(output_surface),
lost_output_surface_(false),
highp_threshold_min_(highp_threshold_min),
@@ -718,7 +748,8 @@ ResourceProvider::ResourceProvider(OutputSurface* output_surface,
use_texture_usage_hint_(false),
use_shallow_flush_(false),
max_texture_size_(0),
- best_texture_format_(0) {
+ best_texture_format_(RGBA_8888),
+ use_rgba_4444_texture_format_(use_rgba_4444_texture_format) {
DCHECK(output_surface_->HasClient());
}
@@ -730,7 +761,7 @@ void ResourceProvider::InitializeSoftware() {
default_resource_type_ = Bitmap;
max_texture_size_ = INT_MAX / 2;
- best_texture_format_ = GL_RGBA;
+ best_texture_format_ = RGBA_8888;
}
bool ResourceProvider::InitializeGL() {
@@ -931,10 +962,16 @@ void ResourceProvider::ReceiveFromChild(
GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, texture_id));
GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D,
it->mailbox.name));
+
ResourceId id = next_id_++;
Resource resource(
- texture_id, it->size, it->format, it->filter, 0, GL_CLAMP_TO_EDGE,
- TextureUsageAny);
+ texture_id,
+ it->size,
+ it->filter,
+ 0,
+ GL_CLAMP_TO_EDGE,
+ TextureUsageAny,
+ it->format);
resource.mailbox.SetName(it->mailbox);
// Don't allocate a texture for a child.
resource.allocated = true;
@@ -1023,9 +1060,11 @@ void ResourceProvider::AcquirePixelBuffer(ResourceId id) {
context3d->bindBuffer(
GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
resource->gl_pixel_buffer_id);
+ unsigned bytes_per_pixel = BytesPerPixel(resource->format);
context3d->bufferData(
GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
- 4 * resource->size.GetArea(),
+ resource->size.height() * RoundUp(bytes_per_pixel
+ * resource->size.width(), 4u),
NULL,
GL_DYNAMIC_DRAW);
context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
@@ -1201,25 +1240,27 @@ void ResourceProvider::BeginSetPixels(ResourceId id) {
GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM,
resource->gl_upload_query_id);
if (allocate) {
- context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D,
- 0, /* level */
- resource->format,
- resource->size.width(),
- resource->size.height(),
- 0, /* border */
- resource->format,
- GL_UNSIGNED_BYTE,
- NULL);
+ context3d->asyncTexImage2DCHROMIUM(
+ GL_TEXTURE_2D,
+ 0, /* level */
+ GetGLInternalFormat(resource->format),
+ resource->size.width(),
+ resource->size.height(),
+ 0, /* border */
+ GetGLDataFormat(resource->format),
+ GetGLDataType(resource->format),
+ NULL);
} else {
- context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D,
- 0, /* level */
- 0, /* x */
- 0, /* y */
- resource->size.width(),
- resource->size.height(),
- resource->format,
- GL_UNSIGNED_BYTE,
- NULL);
+ context3d->asyncTexSubImage2DCHROMIUM(
+ GL_TEXTURE_2D,
+ 0, /* level */
+ 0, /* x */
+ 0, /* y */
+ resource->size.width(),
+ resource->size.height(),
+ GetGLDataFormat(resource->format),
+ GetGLDataType(resource->format),
+ NULL);
}
context3d->endQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM);
context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
@@ -1228,7 +1269,7 @@ void ResourceProvider::BeginSetPixels(ResourceId id) {
if (resource->pixels) {
DCHECK(!resource->mailbox.IsValid());
DCHECK(resource->pixel_buffer);
- DCHECK(resource->format == GL_RGBA);
+ DCHECK_EQ(RGBA_8888, resource->format);
std::swap(resource->pixels, resource->pixel_buffer);
delete[] resource->pixel_buffer;
@@ -1334,9 +1375,9 @@ void ResourceProvider::LazyAllocate(Resource* resource) {
resource->allocated = true;
WebGraphicsContext3D* context3d = Context3d();
gfx::Size& size = resource->size;
- GLenum format = resource->format;
+ ResourceFormat format = resource->format;
GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id));
- if (use_texture_storage_ext_ && IsTextureFormatSupportedForStorage(format)) {
+ if (use_texture_storage_ext_ && IsFormatSupportedForStorage(format)) {
GLenum storage_format = TextureToStorageFormat(format);
GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D,
1,
@@ -1346,12 +1387,12 @@ void ResourceProvider::LazyAllocate(Resource* resource) {
} else {
GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D,
0,
- format,
+ GetGLInternalFormat(format),
size.width(),
size.height(),
0,
- format,
- GL_UNSIGNED_BYTE,
+ GetGLDataFormat(format),
+ GetGLDataType(format),
NULL));
}
}
@@ -1376,7 +1417,7 @@ void ResourceProvider::AcquireImage(ResourceId id) {
resource->allocated = true;
WebGraphicsContext3D* context3d = Context3d();
DCHECK(context3d);
- DCHECK_EQ(static_cast<GLenum>(GL_RGBA), resource->format);
+ DCHECK_EQ(RGBA_8888, resource->format);
resource->image_id = context3d->createImageCHROMIUM(
resource->size.width(), resource->size.height(), GL_RGBA8_OES);
DCHECK(resource->image_id);
@@ -1456,4 +1497,62 @@ WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const {
return context_provider ? context_provider->Context3d() : NULL;
}
+size_t ResourceProvider::BytesPerPixel(ResourceFormat format) {
+ size_t components_per_pixel = 0;
+ switch (format) {
+ case RGBA_8888:
+ case RGBA_4444:
+ case BGRA_8888:
+ components_per_pixel = 4;
+ break;
+ case LUMINANCE_8:
+ components_per_pixel = 1;
+ break;
+ }
+ size_t bits_per_component = 0;
+ switch (format) {
+ case RGBA_8888:
+ case BGRA_8888:
+ case LUMINANCE_8:
+ bits_per_component = 8;
+ break;
+ case RGBA_4444:
+ bits_per_component = 4;
+ break;
+ }
+ const size_t kBitsPerByte = 8;
+ return (components_per_pixel * bits_per_component) / kBitsPerByte;
+}
+
+GLenum ResourceProvider::GetGLDataType(ResourceFormat format) {
+ switch (format) {
+ case RGBA_4444:
+ return GL_UNSIGNED_SHORT_4_4_4_4;
+ case RGBA_8888:
+ case BGRA_8888:
+ case LUMINANCE_8:
+ return GL_UNSIGNED_BYTE;
+ }
+ NOTREACHED();
+ return GL_UNSIGNED_BYTE;
+}
+
+GLenum ResourceProvider::GetGLDataFormat(ResourceFormat format) {
+ switch (format) {
+ case RGBA_8888:
+ case RGBA_4444:
+ return GL_RGBA;
+ case BGRA_8888:
+ return GL_BGRA_EXT;
+ case LUMINANCE_8:
+ return GL_LUMINANCE;
+ }
+ NOTREACHED();
+ return GL_RGBA;
+}
+
+GLenum ResourceProvider::GetGLInternalFormat(ResourceFormat format) {
+ return GetGLDataFormat(format);
+}
+
} // namespace cc
diff --git a/cc/resources/resource_provider.h b/cc/resources/resource_provider.h
index 88ff274..e73ea15 100644
--- a/cc/resources/resource_provider.h
+++ b/cc/resources/resource_provider.h
@@ -19,6 +19,7 @@
#include "cc/output/context_provider.h"
#include "cc/output/output_surface.h"
#include "cc/resources/release_callback.h"
+#include "cc/resources/resource_format.h"
#include "cc/resources/single_release_callback.h"
#include "cc/resources/texture_mailbox.h"
#include "cc/resources/transferable_resource.h"
@@ -56,8 +57,8 @@ class CC_EXPORT ResourceProvider {
};
static scoped_ptr<ResourceProvider> Create(OutputSurface* output_surface,
- int highp_threshold_min);
-
+ int highp_threshold_min,
+ bool use_rgba_4444_texture_format);
virtual ~ResourceProvider();
void InitializeSoftware();
@@ -66,7 +67,10 @@ class CC_EXPORT ResourceProvider {
void DidLoseOutputSurface() { lost_output_surface_ = true; }
int max_texture_size() const { return max_texture_size_; }
- GLenum best_texture_format() const { return best_texture_format_; }
+ ResourceFormat memory_efficient_texture_format() const {
+ return use_rgba_4444_texture_format_ ? RGBA_4444 : best_texture_format_;
+ }
+ ResourceFormat best_texture_format() const { return best_texture_format_; }
size_t num_resources() const { return resources_.size(); }
// Checks whether a resource is in use by a consumer.
@@ -80,23 +84,23 @@ class CC_EXPORT ResourceProvider {
// Creates a resource of the default resource type.
ResourceId CreateResource(gfx::Size size,
- GLenum format,
GLint wrap_mode,
- TextureUsageHint hint);
+ TextureUsageHint hint,
+ ResourceFormat format);
// Creates a resource which is tagged as being managed for GPU memory
// accounting purposes.
ResourceId CreateManagedResource(gfx::Size size,
- GLenum format,
GLint wrap_mode,
- TextureUsageHint hint);
+ TextureUsageHint hint,
+ ResourceFormat format);
// You can also explicitly create a specific resource type.
ResourceId CreateGLTexture(gfx::Size size,
- GLenum format,
GLenum texture_pool,
GLint wrap_mode,
- TextureUsageHint hint);
+ TextureUsageHint hint,
+ ResourceFormat format);
ResourceId CreateBitmap(gfx::Size size);
// Wraps an external texture into a GL resource.
@@ -334,6 +338,10 @@ class CC_EXPORT ResourceProvider {
bool CanLockForWrite(ResourceId id);
static GLint GetActiveTextureUnit(WebKit::WebGraphicsContext3D* context);
+ static size_t BytesPerPixel(ResourceFormat format);
+ static GLenum GetGLDataType(ResourceFormat format);
+ static GLenum GetGLDataFormat(ResourceFormat format);
+ static GLenum GetGLInternalFormat(ResourceFormat format);
private:
struct Resource {
@@ -341,14 +349,13 @@ class CC_EXPORT ResourceProvider {
~Resource();
Resource(unsigned texture_id,
gfx::Size size,
- GLenum format,
GLenum filter,
GLenum texture_pool,
GLint wrap_mode,
- TextureUsageHint hint);
+ TextureUsageHint hint,
+ ResourceFormat format);
Resource(uint8_t* pixels,
gfx::Size size,
- GLenum format,
GLenum filter,
GLint wrap_mode);
@@ -373,7 +380,6 @@ class CC_EXPORT ResourceProvider {
bool enable_read_lock_fences;
scoped_refptr<Fence> read_lock_fence;
gfx::Size size;
- GLenum format;
// TODO(skyostil): Use a separate sampler object for filter state.
GLenum original_filter;
GLenum filter;
@@ -383,6 +389,7 @@ class CC_EXPORT ResourceProvider {
GLint wrap_mode;
TextureUsageHint hint;
ResourceType type;
+ ResourceFormat format;
};
typedef base::hash_map<ResourceId, Resource> ResourceMap;
struct Child {
@@ -399,8 +406,9 @@ class CC_EXPORT ResourceProvider {
resource->read_lock_fence->HasPassed();
}
- explicit ResourceProvider(OutputSurface* output_surface,
- int highp_threshold_min);
+ ResourceProvider(OutputSurface* output_surface,
+ int highp_threshold_min,
+ bool use_rgba_4444_texture_format);
void CleanUpGLIfNeeded();
@@ -451,11 +459,12 @@ class CC_EXPORT ResourceProvider {
bool use_shallow_flush_;
scoped_ptr<TextureUploader> texture_uploader_;
int max_texture_size_;
- GLenum best_texture_format_;
+ ResourceFormat best_texture_format_;
base::ThreadChecker thread_checker_;
scoped_refptr<Fence> current_read_lock_fence_;
+ bool use_rgba_4444_texture_format_;
DISALLOW_COPY_AND_ASSIGN(ResourceProvider);
};
diff --git a/cc/resources/resource_provider_unittest.cc b/cc/resources/resource_provider_unittest.cc
index abdd78e..7df9412 100644
--- a/cc/resources/resource_provider_unittest.cc
+++ b/cc/resources/resource_provider_unittest.cc
@@ -41,7 +41,7 @@ using WebKit::WebGLId;
namespace cc {
namespace {
-size_t TextureSize(gfx::Size size, WGC3Denum format) {
+size_t TextureSize(gfx::Size size, ResourceFormat format) {
unsigned int components_per_pixel = 4;
unsigned int bytes_per_component = 1;
return size.width() * size.height() * components_per_pixel *
@@ -65,16 +65,17 @@ class TextureStateTrackingContext : public TestWebGraphicsContext3D {
};
struct Texture : public base::RefCounted<Texture> {
- Texture() : format(0), filter(GL_NEAREST_MIPMAP_LINEAR) {}
+ Texture() : format(RGBA_8888),
+ filter(GL_NEAREST_MIPMAP_LINEAR) {}
- void Reallocate(gfx::Size size, WGC3Denum format) {
+ void Reallocate(gfx::Size size, ResourceFormat format) {
this->size = size;
this->format = format;
this->data.reset(new uint8_t[TextureSize(size, format)]);
}
gfx::Size size;
- WGC3Denum format;
+ ResourceFormat format;
WGC3Denum filter;
scoped_ptr<uint8_t[]> data;
@@ -237,7 +238,9 @@ class ResourceProviderContext : public TestWebGraphicsContext3D {
ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target);
ASSERT_FALSE(level);
ASSERT_TRUE(textures_[current_texture_].get());
- ASSERT_EQ(textures_[current_texture_]->format, format);
+ ASSERT_EQ(
+ ResourceProvider::GetGLDataFormat(textures_[current_texture_]->format),
+ format);
ASSERT_EQ(static_cast<unsigned>(GL_UNSIGNED_BYTE), type);
ASSERT_TRUE(pixels);
SetPixels(xoffset, yoffset, width, height, pixels);
@@ -280,7 +283,7 @@ class ResourceProviderContext : public TestWebGraphicsContext3D {
mailbox, last_waited_sync_point_);
}
- void GetPixels(gfx::Size size, WGC3Denum format, uint8_t* pixels) {
+ void GetPixels(gfx::Size size, ResourceFormat format, uint8_t* pixels) {
ASSERT_TRUE(current_texture_);
scoped_refptr<Texture> texture = textures_[current_texture_];
ASSERT_TRUE(texture.get());
@@ -311,7 +314,16 @@ class ResourceProviderContext : public TestWebGraphicsContext3D {
ASSERT_TRUE(current_texture_);
scoped_refptr<Texture> texture = textures_[current_texture_];
ASSERT_TRUE(texture.get());
- texture->Reallocate(size, format);
+ ResourceFormat texture_format = RGBA_8888;
+ switch (format) {
+ case GL_RGBA:
+ texture_format = RGBA_8888;
+ break;
+ case GL_BGRA_EXT:
+ texture_format = BGRA_8888;
+ break;
+ }
+ texture->Reallocate(size, texture_format);
}
void SetPixels(int xoffset,
@@ -356,7 +368,7 @@ void GetResourcePixels(ResourceProvider* resource_provider,
ResourceProviderContext* context,
ResourceProvider::ResourceId id,
gfx::Size size,
- WGC3Denum format,
+ ResourceFormat format,
uint8_t* pixels) {
switch (resource_provider->default_resource_type()) {
case ResourceProvider::GLTexture: {
@@ -408,7 +420,8 @@ class ResourceProviderTest
break;
}
CHECK(output_surface_->BindToClient(&output_surface_client_));
- resource_provider_ = ResourceProvider::Create(output_surface_.get(), 0);
+ resource_provider_ = ResourceProvider::Create(
+ output_surface_.get(), 0, false);
}
static void SetResourceFilter(ResourceProvider* resource_provider,
@@ -434,12 +447,12 @@ void CheckCreateResource(ResourceProvider::ResourceType expected_default_type,
DCHECK_EQ(expected_default_type, resource_provider->default_resource_type());
gfx::Size size(1, 1);
- WGC3Denum format = GL_RGBA;
+ ResourceFormat format = RGBA_8888;
size_t pixel_size = TextureSize(size, format);
ASSERT_EQ(4U, pixel_size);
ResourceProvider::ResourceId id = resource_provider->CreateResource(
- size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
+ size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
EXPECT_EQ(1, static_cast<int>(resource_provider->num_resources()));
if (expected_default_type == ResourceProvider::GLTexture)
EXPECT_EQ(0, context->texture_count());
@@ -466,12 +479,12 @@ TEST_P(ResourceProviderTest, Basic) {
TEST_P(ResourceProviderTest, Upload) {
gfx::Size size(2, 2);
- WGC3Denum format = GL_RGBA;
+ ResourceFormat format = RGBA_8888;
size_t pixel_size = TextureSize(size, format);
ASSERT_EQ(16U, pixel_size);
ResourceProvider::ResourceId id = resource_provider_->CreateResource(
- size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
+ size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
uint8_t image[16] = { 0 };
gfx::Rect image_rect(size);
@@ -547,21 +560,21 @@ TEST_P(ResourceProviderTest, TransferResources) {
CHECK(child_output_surface->BindToClient(&child_output_surface_client));
scoped_ptr<ResourceProvider> child_resource_provider(
- ResourceProvider::Create(child_output_surface.get(), 0));
+ ResourceProvider::Create(child_output_surface.get(), 0, false));
gfx::Size size(1, 1);
- WGC3Denum format = GL_RGBA;
+ ResourceFormat format = RGBA_8888;
size_t pixel_size = TextureSize(size, format);
ASSERT_EQ(4U, pixel_size);
ResourceProvider::ResourceId id1 = child_resource_provider->CreateResource(
- size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
+ size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
uint8_t data1[4] = { 1, 2, 3, 4 };
gfx::Rect rect(size);
child_resource_provider->SetPixels(id1, data1, rect, rect, gfx::Vector2d());
ResourceProvider::ResourceId id2 = child_resource_provider->CreateResource(
- size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
+ size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
uint8_t data2[4] = { 5, 5, 5, 5 };
child_resource_provider->SetPixels(id2, data2, rect, rect, gfx::Vector2d());
@@ -683,15 +696,15 @@ TEST_P(ResourceProviderTest, DeleteTransferredResources) {
CHECK(child_output_surface->BindToClient(&child_output_surface_client));
scoped_ptr<ResourceProvider> child_resource_provider(
- ResourceProvider::Create(child_output_surface.get(), 0));
+ ResourceProvider::Create(child_output_surface.get(), 0, false));
gfx::Size size(1, 1);
- WGC3Denum format = GL_RGBA;
+ ResourceFormat format = RGBA_8888;
size_t pixel_size = TextureSize(size, format);
ASSERT_EQ(4U, pixel_size);
ResourceProvider::ResourceId id = child_resource_provider->CreateResource(
- size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
+ size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
uint8_t data[4] = { 1, 2, 3, 4 };
gfx::Rect rect(size);
child_resource_provider->SetPixels(id, data, rect, rect, gfx::Vector2d());
@@ -744,7 +757,7 @@ class ResourceProviderTestTextureFilters : public ResourceProviderTest {
CHECK(child_output_surface->BindToClient(&child_output_surface_client));
scoped_ptr<ResourceProvider> child_resource_provider(
- ResourceProvider::Create(child_output_surface.get(), 0));
+ ResourceProvider::Create(child_output_surface.get(), 0, false));
scoped_ptr<TextureStateTrackingContext> parent_context_owned(
new TextureStateTrackingContext);
@@ -756,17 +769,17 @@ class ResourceProviderTestTextureFilters : public ResourceProviderTest {
CHECK(parent_output_surface->BindToClient(&parent_output_surface_client));
scoped_ptr<ResourceProvider> parent_resource_provider(
- ResourceProvider::Create(parent_output_surface.get(), 0));
+ ResourceProvider::Create(parent_output_surface.get(), 0, false));
gfx::Size size(1, 1);
- WGC3Denum format = GL_RGBA;
+ ResourceFormat format = RGBA_8888;
int texture_id = 1;
size_t pixel_size = TextureSize(size, format);
ASSERT_EQ(4U, pixel_size);
ResourceProvider::ResourceId id = child_resource_provider->CreateResource(
- size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
+ size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
// The new texture is created with GL_LINEAR.
EXPECT_CALL(*child_context, bindTexture(GL_TEXTURE_2D, texture_id))
@@ -944,7 +957,8 @@ TEST_P(ResourceProviderTest, TransferMailboxResources) {
context()->bindTexture(GL_TEXTURE_2D, other_texture);
context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
uint8_t test_data[4] = { 0 };
- context()->GetPixels(gfx::Size(1, 1), GL_RGBA, test_data);
+ context()->GetPixels(
+ gfx::Size(1, 1), RGBA_8888, test_data);
EXPECT_EQ(0, memcmp(data, test_data, sizeof(data)));
context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
context()->deleteTexture(other_texture);
@@ -991,7 +1005,8 @@ TEST_P(ResourceProviderTest, TransferMailboxResources) {
context()->bindTexture(GL_TEXTURE_2D, other_texture);
context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
uint8_t test_data[4] = { 0 };
- context()->GetPixels(gfx::Size(1, 1), GL_RGBA, test_data);
+ context()->GetPixels(
+ gfx::Size(1, 1), RGBA_8888, test_data);
EXPECT_EQ(0, memcmp(data, test_data, sizeof(data)));
context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
context()->deleteTexture(other_texture);
@@ -1168,14 +1183,14 @@ TEST_P(ResourceProviderTest, ScopedSampler) {
CHECK(output_surface->BindToClient(&output_surface_client));
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
gfx::Size size(1, 1);
- WGC3Denum format = GL_RGBA;
+ ResourceFormat format = RGBA_8888;
int texture_id = 1;
ResourceProvider::ResourceId id = resource_provider->CreateResource(
- size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
+ size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
// Check that the texture gets created with the right sampler settings.
EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id))
@@ -1194,6 +1209,7 @@ TEST_P(ResourceProviderTest, ScopedSampler) {
texParameteri(GL_TEXTURE_2D,
GL_TEXTURE_POOL_CHROMIUM,
GL_TEXTURE_POOL_UNMANAGED_CHROMIUM));
+
resource_provider->AllocateForTesting(id);
Mock::VerifyAndClearExpectations(context);
@@ -1248,15 +1264,15 @@ TEST_P(ResourceProviderTest, ManagedResource) {
CHECK(output_surface->BindToClient(&output_surface_client));
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
gfx::Size size(1, 1);
- WGC3Denum format = GL_RGBA;
+ ResourceFormat format = RGBA_8888;
int texture_id = 1;
// Check that the texture gets created with the right sampler settings.
ResourceProvider::ResourceId id = resource_provider->CreateManagedResource(
- size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
+ size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id));
EXPECT_CALL(*context,
texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
@@ -1293,19 +1309,22 @@ TEST_P(ResourceProviderTest, TextureWrapMode) {
CHECK(output_surface->BindToClient(&output_surface_client));
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
gfx::Size size(1, 1);
- WGC3Denum format = GL_RGBA;
+ ResourceFormat format = RGBA_8888;
int texture_id = 1;
GLenum texture_pool = GL_TEXTURE_POOL_UNMANAGED_CHROMIUM;
for (int i = 0; i < 2; ++i) {
GLint wrap_mode = i ? GL_CLAMP_TO_EDGE : GL_REPEAT;
// Check that the texture gets created with the right sampler settings.
- ResourceProvider::ResourceId id = resource_provider->CreateGLTexture(
- size, format, texture_pool, wrap_mode,
- ResourceProvider::TextureUsageAny);
+ ResourceProvider::ResourceId id =
+ resource_provider->CreateGLTexture(size,
+ texture_pool,
+ wrap_mode,
+ ResourceProvider::TextureUsageAny,
+ format);
EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id));
EXPECT_CALL(*context,
texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
@@ -1346,7 +1365,7 @@ TEST_P(ResourceProviderTest, TextureMailbox_SharedMemory) {
CHECK(output_surface->BindToClient(&output_surface_client));
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create(
base::Bind(&EmptyReleaseCallback));
@@ -1381,7 +1400,7 @@ TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D) {
CHECK(output_surface->BindToClient(&output_surface_client));
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
unsigned texture_id = 1;
unsigned sync_point = 30;
@@ -1445,7 +1464,7 @@ TEST_P(ResourceProviderTest, TextureMailbox_GLTextureExternalOES) {
CHECK(output_surface->BindToClient(&output_surface_client));
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
unsigned texture_id = 1;
unsigned sync_point = 30;
@@ -1565,19 +1584,19 @@ TEST_P(ResourceProviderTest, TextureAllocation) {
CHECK(output_surface->BindToClient(&output_surface_client));
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
gfx::Size size(2, 2);
gfx::Vector2d offset(0, 0);
gfx::Rect rect(0, 0, 2, 2);
- WGC3Denum format = GL_RGBA;
+ ResourceFormat format = RGBA_8888;
ResourceProvider::ResourceId id = 0;
uint8_t pixels[16] = { 0 };
int texture_id = 123;
// Lazy allocation. Don't allocate when creating the resource.
id = resource_provider->CreateResource(
- size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
+ size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id));
EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1);
@@ -1590,7 +1609,7 @@ TEST_P(ResourceProviderTest, TextureAllocation) {
// Do allocate when we set the pixels.
id = resource_provider->CreateResource(
- size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
+ size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id));
EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3);
@@ -1605,7 +1624,7 @@ TEST_P(ResourceProviderTest, TextureAllocation) {
// Same for async version.
id = resource_provider->CreateResource(
- size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
+ size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
resource_provider->AcquirePixelBuffer(id);
EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id));
@@ -1636,15 +1655,15 @@ TEST_P(ResourceProviderTest, PixelBuffer_GLTexture) {
CHECK(output_surface->BindToClient(&output_surface_client));
gfx::Size size(2, 2);
- WGC3Denum format = GL_RGBA;
+ ResourceFormat format = RGBA_8888;
ResourceProvider::ResourceId id = 0;
int texture_id = 123;
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
id = resource_provider->CreateResource(
- size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
+ size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
resource_provider->AcquirePixelBuffer(id);
EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id));
@@ -1673,15 +1692,15 @@ TEST_P(ResourceProviderTest, PixelBuffer_Bitmap) {
CHECK(output_surface->BindToClient(&output_surface_client));
gfx::Size size(1, 1);
- WGC3Denum format = GL_RGBA;
+ ResourceFormat format = RGBA_8888;
ResourceProvider::ResourceId id = 0;
const uint32_t kBadBeef = 0xbadbeef;
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
id = resource_provider->CreateResource(
- size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
+ size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
resource_provider->AcquirePixelBuffer(id);
void* data = resource_provider->MapPixelBuffer(id);
@@ -1719,15 +1738,15 @@ TEST_P(ResourceProviderTest, ForcingAsyncUploadToComplete) {
CHECK(output_surface->BindToClient(&output_surface_client));
gfx::Size size(2, 2);
- WGC3Denum format = GL_RGBA;
+ ResourceFormat format = RGBA_8888;
ResourceProvider::ResourceId id = 0;
int texture_id = 123;
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
id = resource_provider->CreateResource(
- size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
+ size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
resource_provider->AcquirePixelBuffer(id);
EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id));
@@ -1760,17 +1779,17 @@ TEST_P(ResourceProviderTest, PixelBufferLostContext) {
CHECK(output_surface->BindToClient(&output_surface_client));
gfx::Size size(2, 2);
- WGC3Denum format = GL_RGBA;
+ ResourceFormat format = RGBA_8888;
ResourceProvider::ResourceId id = 0;
int texture_id = 123;
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
EXPECT_CALL(*context, createTexture()).WillRepeatedly(Return(texture_id));
id = resource_provider->CreateResource(
- size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
+ size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
GL_INNOCENT_CONTEXT_RESET_ARB);
resource_provider->AcquirePixelBuffer(id);
@@ -1797,16 +1816,16 @@ TEST_P(ResourceProviderTest, Image_GLTexture) {
const int kWidth = 2;
const int kHeight = 2;
gfx::Size size(kWidth, kHeight);
- WGC3Denum format = GL_RGBA;
+ ResourceFormat format = RGBA_8888;
ResourceProvider::ResourceId id = 0;
const unsigned kTextureId = 123u;
const unsigned kImageId = 234u;
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
id = resource_provider->CreateResource(
- size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
+ size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
EXPECT_CALL(*context, createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES))
.WillOnce(Return(kImageId))
.RetiresOnSaturation();
@@ -1869,15 +1888,15 @@ TEST_P(ResourceProviderTest, Image_Bitmap) {
CHECK(output_surface->BindToClient(&output_surface_client));
gfx::Size size(1, 1);
- WGC3Denum format = GL_RGBA;
+ ResourceFormat format = RGBA_8888;
ResourceProvider::ResourceId id = 0;
const uint32_t kBadBeef = 0xbadbeef;
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
id = resource_provider->CreateResource(
- size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
+ size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
resource_provider->AcquireImage(id);
const int kStride = 0;
@@ -1925,7 +1944,7 @@ TEST(ResourceProviderTest, BasicInitializeGLSoftware) {
scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice)));
EXPECT_TRUE(output_surface->BindToClient(&client));
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
CheckCreateResource(ResourceProvider::Bitmap, resource_provider.get(), NULL);
diff --git a/cc/resources/resource_update_controller_unittest.cc b/cc/resources/resource_update_controller_unittest.cc
index ccbfadd..31b5d71 100644
--- a/cc/resources/resource_update_controller_unittest.cc
+++ b/cc/resources/resource_update_controller_unittest.cc
@@ -124,7 +124,8 @@ class ResourceUpdateControllerTest : public Test {
for (int i = 0; i < 4; i++) {
textures_[i] = PrioritizedResource::Create(resource_manager_.get(),
- gfx::Size(300, 150), GL_RGBA);
+ gfx::Size(300, 150),
+ RGBA_8888);
textures_[i]->
set_request_priority(PriorityCalculator::VisiblePriority(true));
}
@@ -135,7 +136,8 @@ class ResourceUpdateControllerTest : public Test {
new WebGraphicsContext3DForUploadTest(this)));
CHECK(output_surface_->BindToClient(&output_surface_client_));
- resource_provider_ = ResourceProvider::Create(output_surface_.get(), 0);
+ resource_provider_ =
+ ResourceProvider::Create(output_surface_.get(), 0, false);
}
void AppendFullUploadsOfIndexedTextureToUpdateQueue(int count,
diff --git a/cc/resources/scoped_resource.cc b/cc/resources/scoped_resource.cc
index 525fb73..5fcaaca 100644
--- a/cc/resources/scoped_resource.cc
+++ b/cc/resources/scoped_resource.cc
@@ -16,14 +16,14 @@ ScopedResource::~ScopedResource() {
}
bool ScopedResource::Allocate(gfx::Size size,
- GLenum format,
- ResourceProvider::TextureUsageHint hint) {
+ ResourceProvider::TextureUsageHint hint,
+ ResourceFormat format) {
DCHECK(!id());
DCHECK(!size.IsEmpty());
set_dimensions(size, format);
set_id(resource_provider_->CreateResource(
- size, format, GL_CLAMP_TO_EDGE, hint));
+ size, GL_CLAMP_TO_EDGE, hint, format));
#ifndef NDEBUG
allocate_thread_id_ = base::PlatformThread::CurrentId();
diff --git a/cc/resources/scoped_resource.h b/cc/resources/scoped_resource.h
index 6a2c8f1..8e316eb 100644
--- a/cc/resources/scoped_resource.h
+++ b/cc/resources/scoped_resource.h
@@ -26,8 +26,8 @@ class CC_EXPORT ScopedResource : public Resource {
virtual ~ScopedResource();
bool Allocate(gfx::Size size,
- GLenum format,
- ResourceProvider::TextureUsageHint hint);
+ ResourceProvider::TextureUsageHint hint,
+ ResourceFormat texture_format);
void Free();
void Leak();
diff --git a/cc/resources/scoped_resource_unittest.cc b/cc/resources/scoped_resource_unittest.cc
index 9c66180..8b59995 100644
--- a/cc/resources/scoped_resource_unittest.cc
+++ b/cc/resources/scoped_resource_unittest.cc
@@ -9,7 +9,6 @@
#include "cc/test/fake_output_surface_client.h"
#include "cc/test/tiled_layer_test_common.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/khronos/GLES2/gl2.h"
namespace cc {
namespace {
@@ -20,7 +19,7 @@ TEST(ScopedResourceTest, NewScopedResource) {
CHECK(output_surface->BindToClient(&output_surface_client));
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
scoped_ptr<ScopedResource> texture =
ScopedResource::create(resource_provider.get());
@@ -38,18 +37,19 @@ TEST(ScopedResourceTest, CreateScopedResource) {
CHECK(output_surface->BindToClient(&output_surface_client));
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
scoped_ptr<ScopedResource> texture =
ScopedResource::create(resource_provider.get());
- texture->Allocate(
- gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny);
+ texture->Allocate(gfx::Size(30, 30),
+ ResourceProvider::TextureUsageAny,
+ RGBA_8888);
// The texture has an allocated byte-size now.
size_t expected_bytes = 30 * 30 * 4;
EXPECT_EQ(expected_bytes, texture->bytes());
EXPECT_LT(0u, texture->id());
- EXPECT_EQ(static_cast<unsigned>(GL_RGBA), texture->format());
+ EXPECT_EQ(static_cast<unsigned>(RGBA_8888), texture->format());
EXPECT_EQ(gfx::Size(30, 30), texture->size());
}
@@ -59,14 +59,15 @@ TEST(ScopedResourceTest, ScopedResourceIsDeleted) {
CHECK(output_surface->BindToClient(&output_surface_client));
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
{
scoped_ptr<ScopedResource> texture =
ScopedResource::create(resource_provider.get());
EXPECT_EQ(0u, resource_provider->num_resources());
- texture->Allocate(
- gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny);
+ texture->Allocate(gfx::Size(30, 30),
+ ResourceProvider::TextureUsageAny,
+ RGBA_8888);
EXPECT_LT(0u, texture->id());
EXPECT_EQ(1u, resource_provider->num_resources());
}
@@ -76,8 +77,9 @@ TEST(ScopedResourceTest, ScopedResourceIsDeleted) {
scoped_ptr<ScopedResource> texture =
ScopedResource::create(resource_provider.get());
EXPECT_EQ(0u, resource_provider->num_resources());
- texture->Allocate(
- gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny);
+ texture->Allocate(gfx::Size(30, 30),
+ ResourceProvider::TextureUsageAny,
+ RGBA_8888);
EXPECT_LT(0u, texture->id());
EXPECT_EQ(1u, resource_provider->num_resources());
texture->Free();
@@ -91,14 +93,15 @@ TEST(ScopedResourceTest, LeakScopedResource) {
CHECK(output_surface->BindToClient(&output_surface_client));
scoped_ptr<ResourceProvider> resource_provider(
- ResourceProvider::Create(output_surface.get(), 0));
+ ResourceProvider::Create(output_surface.get(), 0, false));
{
scoped_ptr<ScopedResource> texture =
ScopedResource::create(resource_provider.get());
EXPECT_EQ(0u, resource_provider->num_resources());
- texture->Allocate(
- gfx::Size(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny);
+ texture->Allocate(gfx::Size(30, 30),
+ ResourceProvider::TextureUsageAny,
+ RGBA_8888);
EXPECT_LT(0u, texture->id());
EXPECT_EQ(1u, resource_provider->num_resources());
diff --git a/cc/resources/tile_manager_perftest.cc b/cc/resources/tile_manager_perftest.cc
index e0d130b..99d16a1 100644
--- a/cc/resources/tile_manager_perftest.cc
+++ b/cc/resources/tile_manager_perftest.cc
@@ -39,7 +39,8 @@ class TileManagerPerfTest : public testing::Test {
output_surface_ = FakeOutputSurface::Create3d();
CHECK(output_surface_->BindToClient(&output_surface_client_));
- resource_provider_ = ResourceProvider::Create(output_surface_.get(), 0);
+ resource_provider_ =
+ ResourceProvider::Create(output_surface_.get(), 0, false);
tile_manager_ = make_scoped_ptr(
new FakeTileManager(&tile_manager_client_, resource_provider_.get()));
diff --git a/cc/resources/tile_manager_unittest.cc b/cc/resources/tile_manager_unittest.cc
index d3b9fac..0274914 100644
--- a/cc/resources/tile_manager_unittest.cc
+++ b/cc/resources/tile_manager_unittest.cc
@@ -25,7 +25,8 @@ class TileManagerTest : public testing::TestWithParam<bool> {
output_surface_ = FakeOutputSurface::Create3d();
CHECK(output_surface_->BindToClient(&output_surface_client_));
- resource_provider_ = ResourceProvider::Create(output_surface_.get(), 0);
+ resource_provider_ =
+ ResourceProvider::Create(output_surface_.get(), 0, false);
tile_manager_ = make_scoped_ptr(
new FakeTileManager(&tile_manager_client_, resource_provider_.get()));
diff --git a/cc/resources/transferable_resource.cc b/cc/resources/transferable_resource.cc
index 8a200c3..1b8930f 100644
--- a/cc/resources/transferable_resource.cc
+++ b/cc/resources/transferable_resource.cc
@@ -11,7 +11,7 @@ namespace cc {
TransferableResource::TransferableResource()
: id(0),
sync_point(0),
- format(0),
+ format(RGBA_8888),
filter(0) {
}
diff --git a/cc/resources/transferable_resource.h b/cc/resources/transferable_resource.h
index be6902c..0ea6243 100644
--- a/cc/resources/transferable_resource.h
+++ b/cc/resources/transferable_resource.h
@@ -9,6 +9,7 @@
#include "base/basictypes.h"
#include "cc/base/cc_export.h"
+#include "cc/resources/resource_format.h"
#include "gpu/command_buffer/common/mailbox.h"
#include "ui/gfx/size.h"
@@ -29,7 +30,7 @@ struct CC_EXPORT TransferableResource {
unsigned id;
unsigned sync_point;
- uint32 format;
+ ResourceFormat format;
uint32 filter;
gfx::Size size;
gpu::Mailbox mailbox;
diff --git a/cc/resources/video_resource_updater.cc b/cc/resources/video_resource_updater.cc
index d07ff35..34c7ab6 100644
--- a/cc/resources/video_resource_updater.cc
+++ b/cc/resources/video_resource_updater.cc
@@ -15,11 +15,11 @@
#include "third_party/khronos/GLES2/gl2ext.h"
#include "ui/gfx/size_conversions.h"
-const unsigned kYUVResourceFormat = GL_LUMINANCE;
-const unsigned kRGBResourceFormat = GL_RGBA;
-
namespace cc {
+const ResourceFormat kYUVResourceFormat = LUMINANCE_8;
+const ResourceFormat kRGBResourceFormat = RGBA_8888;
+
VideoFrameExternalResources::VideoFrameExternalResources() : type(NONE) {}
VideoFrameExternalResources::~VideoFrameExternalResources() {}
@@ -90,7 +90,7 @@ bool VideoResourceUpdater::VerifyFrame(
static gfx::Size SoftwarePlaneDimension(
media::VideoFrame::Format input_frame_format,
gfx::Size coded_size,
- GLenum output_resource_format,
+ ResourceFormat output_resource_format,
int plane_index) {
if (output_resource_format == kYUVResourceFormat) {
if (plane_index == media::VideoFrame::kYPlane ||
@@ -116,7 +116,7 @@ static gfx::Size SoftwarePlaneDimension(
}
}
- DCHECK_EQ(output_resource_format, static_cast<unsigned>(kRGBResourceFormat));
+ DCHECK_EQ(output_resource_format, kRGBResourceFormat);
return coded_size;
}
@@ -143,7 +143,7 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
bool software_compositor = context_provider_ == NULL;
- GLenum output_resource_format = kYUVResourceFormat;
+ ResourceFormat output_resource_format = kYUVResourceFormat;
size_t output_plane_count =
(input_frame_format == media::VideoFrame::YV12A) ? 4 : 3;
@@ -194,9 +194,9 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
// ResourceProvider and stop using ResourceProvider in this class.
resource_id =
resource_provider_->CreateResource(output_plane_resource_size,
- output_resource_format,
GL_CLAMP_TO_EDGE,
- ResourceProvider::TextureUsageAny);
+ ResourceProvider::TextureUsageAny,
+ output_resource_format);
DCHECK(mailbox.IsZero());
@@ -284,8 +284,7 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
for (size_t i = 0; i < plane_resources.size(); ++i) {
// Update each plane's resource id with its content.
- DCHECK_EQ(plane_resources[i].resource_format,
- static_cast<unsigned>(kYUVResourceFormat));
+ DCHECK_EQ(plane_resources[i].resource_format, kYUVResourceFormat);
const uint8_t* input_plane_pixels = video_frame->data(i);
diff --git a/cc/resources/video_resource_updater.h b/cc/resources/video_resource_updater.h
index d0e9f9c..e3476d4 100644
--- a/cc/resources/video_resource_updater.h
+++ b/cc/resources/video_resource_updater.h
@@ -13,6 +13,7 @@
#include "base/memory/weak_ptr.h"
#include "cc/base/cc_export.h"
#include "cc/resources/release_callback.h"
+#include "cc/resources/resource_format.h"
#include "cc/resources/texture_mailbox.h"
#include "ui/gfx/size.h"
@@ -75,12 +76,12 @@ class CC_EXPORT VideoResourceUpdater
struct PlaneResource {
unsigned resource_id;
gfx::Size resource_size;
- unsigned resource_format;
+ ResourceFormat resource_format;
gpu::Mailbox mailbox;
PlaneResource(unsigned resource_id,
gfx::Size resource_size,
- unsigned resource_format,
+ ResourceFormat resource_format,
gpu::Mailbox mailbox)
: resource_id(resource_id),
resource_size(resource_size),
@@ -98,7 +99,7 @@ class CC_EXPORT VideoResourceUpdater
struct RecycleResourceData {
unsigned resource_id;
gfx::Size resource_size;
- unsigned resource_format;
+ ResourceFormat resource_format;
gpu::Mailbox mailbox;
};
static void RecycleResource(base::WeakPtr<VideoResourceUpdater> updater,
diff --git a/cc/resources/video_resource_updater_unittest.cc b/cc/resources/video_resource_updater_unittest.cc
index 60673ed..c36689e 100644
--- a/cc/resources/video_resource_updater_unittest.cc
+++ b/cc/resources/video_resource_updater_unittest.cc
@@ -26,7 +26,7 @@ class VideoResourceUpdaterTest : public testing::Test {
FakeOutputSurface::Create3d(context3d.Pass());
CHECK(output_surface3d_->BindToClient(&client_));
resource_provider3d_ =
- ResourceProvider::Create(output_surface3d_.get(), 0);
+ ResourceProvider::Create(output_surface3d_.get(), 0, false);
}
scoped_refptr<media::VideoFrame> CreateTestYUVVideoFrame() {
diff --git a/cc/scheduler/texture_uploader.cc b/cc/scheduler/texture_uploader.cc
index 920c38e..207bae2 100644
--- a/cc/scheduler/texture_uploader.cc
+++ b/cc/scheduler/texture_uploader.cc
@@ -135,7 +135,7 @@ void TextureUploader::Upload(const uint8* image,
gfx::Rect image_rect,
gfx::Rect source_rect,
gfx::Vector2d dest_offset,
- GLenum format,
+ ResourceFormat format,
gfx::Size size) {
CHECK(image_rect.Contains(source_rect));
@@ -178,7 +178,7 @@ void TextureUploader::UploadWithTexSubImage(const uint8* image,
gfx::Rect image_rect,
gfx::Rect source_rect,
gfx::Vector2d dest_offset,
- GLenum format) {
+ ResourceFormat format) {
// Instrumentation to debug issue 156107
int source_rect_x = source_rect.x();
int source_rect_y = source_rect.y();
@@ -207,10 +207,10 @@ void TextureUploader::UploadWithTexSubImage(const uint8* image,
gfx::Vector2d offset(source_rect.origin() - image_rect.origin());
const uint8* pixel_source;
- unsigned int bytes_per_pixel = Resource::BytesPerPixel(format);
+ unsigned bytes_per_pixel = ResourceProvider::BytesPerPixel(format);
// Use 4-byte row alignment (OpenGL default) for upload performance.
// Assuming that GL_UNPACK_ALIGNMENT has not changed from default.
- unsigned int upload_image_stride =
+ unsigned upload_image_stride =
RoundUp(bytes_per_pixel * source_rect.width(), 4u);
if (upload_image_stride == image_rect.width() * bytes_per_pixel &&
@@ -239,8 +239,8 @@ void TextureUploader::UploadWithTexSubImage(const uint8* image,
dest_offset.y(),
source_rect.width(),
source_rect.height(),
- format,
- GL_UNSIGNED_BYTE,
+ ResourceProvider::GetGLDataFormat(format),
+ ResourceProvider::GetGLDataType(format),
pixel_source);
}
@@ -248,7 +248,7 @@ void TextureUploader::UploadWithMapTexSubImage(const uint8* image,
gfx::Rect image_rect,
gfx::Rect source_rect,
gfx::Vector2d dest_offset,
- GLenum format) {
+ ResourceFormat format) {
// Instrumentation to debug issue 156107
int source_rect_x = source_rect.x();
int source_rect_y = source_rect.y();
@@ -277,10 +277,10 @@ void TextureUploader::UploadWithMapTexSubImage(const uint8* image,
// Offset from image-rect to source-rect.
gfx::Vector2d offset(source_rect.origin() - image_rect.origin());
- unsigned int bytes_per_pixel = Resource::BytesPerPixel(format);
+ unsigned bytes_per_pixel = ResourceProvider::BytesPerPixel(format);
// Use 4-byte row alignment (OpenGL default) for upload performance.
// Assuming that GL_UNPACK_ALIGNMENT has not changed from default.
- unsigned int upload_image_stride =
+ unsigned upload_image_stride =
RoundUp(bytes_per_pixel * source_rect.width(), 4u);
// Upload tile data via a mapped transfer buffer
@@ -291,8 +291,10 @@ void TextureUploader::UploadWithMapTexSubImage(const uint8* image,
dest_offset.y(),
source_rect.width(),
source_rect.height(),
- format,
- GL_UNSIGNED_BYTE,
+ ResourceProvider::GetGLDataFormat(
+ format),
+ ResourceProvider::GetGLDataType(
+ format),
GL_WRITE_ONLY));
if (!pixel_dest) {
diff --git a/cc/scheduler/texture_uploader.h b/cc/scheduler/texture_uploader.h
index 1457bed..a131ba0 100644
--- a/cc/scheduler/texture_uploader.h
+++ b/cc/scheduler/texture_uploader.h
@@ -11,7 +11,7 @@
#include "base/memory/scoped_ptr.h"
#include "cc/base/cc_export.h"
#include "cc/base/scoped_ptr_deque.h"
-#include "third_party/khronos/GLES2/gl2.h"
+#include "cc/resources/resource_provider.h"
namespace WebKit { class WebGraphicsContext3D; }
@@ -46,7 +46,7 @@ class CC_EXPORT TextureUploader {
gfx::Rect content_rect,
gfx::Rect source_rect,
gfx::Vector2d dest_offset,
- GLenum format,
+ ResourceFormat format,
gfx::Size size);
void Flush();
@@ -97,12 +97,12 @@ class CC_EXPORT TextureUploader {
gfx::Rect image_rect,
gfx::Rect source_rect,
gfx::Vector2d dest_offset,
- GLenum format);
+ ResourceFormat format);
void UploadWithMapTexSubImage(const uint8* image,
gfx::Rect image_rect,
gfx::Rect source_rect,
gfx::Vector2d dest_offset,
- GLenum format);
+ ResourceFormat format);
WebKit::WebGraphicsContext3D* context_;
ScopedPtrDeque<Query> pending_queries_;
diff --git a/cc/scheduler/texture_uploader_unittest.cc b/cc/scheduler/texture_uploader_unittest.cc
index 0595917..68413df 100644
--- a/cc/scheduler/texture_uploader_unittest.cc
+++ b/cc/scheduler/texture_uploader_unittest.cc
@@ -151,7 +151,7 @@ class TestWebGraphicsContext3DTextureUpload : public TestWebGraphicsContext3D {
};
void UploadTexture(TextureUploader* uploader,
- WGC3Denum format,
+ ResourceFormat format,
gfx::Size size,
const uint8* data) {
uploader->Upload(data,
@@ -170,17 +170,17 @@ TEST(TextureUploaderTest, NumBlockingUploads) {
fake_context->SetResultAvailable(0);
EXPECT_EQ(0u, uploader->NumBlockingUploads());
- UploadTexture(uploader.get(), GL_RGBA, gfx::Size(), NULL);
+ UploadTexture(uploader.get(), RGBA_8888, gfx::Size(), NULL);
EXPECT_EQ(1u, uploader->NumBlockingUploads());
- UploadTexture(uploader.get(), GL_RGBA, gfx::Size(), NULL);
+ UploadTexture(uploader.get(), RGBA_8888, gfx::Size(), NULL);
EXPECT_EQ(2u, uploader->NumBlockingUploads());
fake_context->SetResultAvailable(1);
EXPECT_EQ(0u, uploader->NumBlockingUploads());
- UploadTexture(uploader.get(), GL_RGBA, gfx::Size(), NULL);
+ UploadTexture(uploader.get(), RGBA_8888, gfx::Size(), NULL);
EXPECT_EQ(0u, uploader->NumBlockingUploads());
- UploadTexture(uploader.get(), GL_RGBA, gfx::Size(), NULL);
- UploadTexture(uploader.get(), GL_RGBA, gfx::Size(), NULL);
+ UploadTexture(uploader.get(), RGBA_8888, gfx::Size(), NULL);
+ UploadTexture(uploader.get(), RGBA_8888, gfx::Size(), NULL);
EXPECT_EQ(0u, uploader->NumBlockingUploads());
}
@@ -192,18 +192,18 @@ TEST(TextureUploaderTest, MarkPendingUploadsAsNonBlocking) {
fake_context->SetResultAvailable(0);
EXPECT_EQ(0u, uploader->NumBlockingUploads());
- UploadTexture(uploader.get(), GL_RGBA, gfx::Size(), NULL);
- UploadTexture(uploader.get(), GL_RGBA, gfx::Size(), NULL);
+ UploadTexture(uploader.get(), RGBA_8888, gfx::Size(), NULL);
+ UploadTexture(uploader.get(), RGBA_8888, gfx::Size(), NULL);
EXPECT_EQ(2u, uploader->NumBlockingUploads());
uploader->MarkPendingUploadsAsNonBlocking();
EXPECT_EQ(0u, uploader->NumBlockingUploads());
- UploadTexture(uploader.get(), GL_RGBA, gfx::Size(), NULL);
+ UploadTexture(uploader.get(), RGBA_8888, gfx::Size(), NULL);
EXPECT_EQ(1u, uploader->NumBlockingUploads());
fake_context->SetResultAvailable(1);
EXPECT_EQ(0u, uploader->NumBlockingUploads());
- UploadTexture(uploader.get(), GL_RGBA, gfx::Size(), NULL);
+ UploadTexture(uploader.get(), RGBA_8888, gfx::Size(), NULL);
uploader->MarkPendingUploadsAsNonBlocking();
EXPECT_EQ(0u, uploader->NumBlockingUploads());
}
@@ -222,7 +222,7 @@ TEST(TextureUploaderTest, UploadContentsTest) {
buffer[i * 4 * 256] = 0x1;
buffer[(i + 1) * 4 * 256 - 1] = 0x2;
}
- UploadTexture(uploader.get(), GL_RGBA, gfx::Size(256, 256), buffer);
+ UploadTexture(uploader.get(), RGBA_8888, gfx::Size(256, 256), buffer);
// Upload a tightly packed 41x43 RGBA texture.
memset(buffer, 0, sizeof(buffer));
@@ -231,7 +231,7 @@ TEST(TextureUploaderTest, UploadContentsTest) {
buffer[i * 4 * 41] = 0x1;
buffer[(i + 1) * 4 * 41 - 1] = 0x2;
}
- UploadTexture(uploader.get(), GL_RGBA, gfx::Size(41, 43), buffer);
+ UploadTexture(uploader.get(), RGBA_8888, gfx::Size(41, 43), buffer);
// Upload a tightly packed 82x86 LUMINANCE texture.
memset(buffer, 0, sizeof(buffer));
@@ -240,7 +240,7 @@ TEST(TextureUploaderTest, UploadContentsTest) {
buffer[i * 1 * 82] = 0x1;
buffer[(i + 1) * 82 - 1] = 0x2;
}
- UploadTexture(uploader.get(), GL_LUMINANCE, gfx::Size(82, 86), buffer);
+ UploadTexture(uploader.get(), LUMINANCE_8, gfx::Size(82, 86), buffer);
}
} // namespace
diff --git a/cc/test/fake_tile_manager.cc b/cc/test/fake_tile_manager.cc
index 8b13c63..d8b53aa 100644
--- a/cc/test/fake_tile_manager.cc
+++ b/cc/test/fake_tile_manager.cc
@@ -32,7 +32,9 @@ class FakeRasterWorkerPool : public RasterWorkerPool {
completed_tasks_.pop_front();
}
}
- virtual GLenum GetResourceFormat() const OVERRIDE { return GL_RGBA; }
+ virtual ResourceFormat GetResourceFormat() const OVERRIDE {
+ return RGBA_8888;
+ }
virtual void OnRasterTasksFinished() OVERRIDE {}
virtual void OnRasterTasksRequiredForActivationFinished() OVERRIDE {}
diff --git a/cc/test/pixel_test.cc b/cc/test/pixel_test.cc
index 556a194..864af4e 100644
--- a/cc/test/pixel_test.cc
+++ b/cc/test/pixel_test.cc
@@ -162,7 +162,8 @@ void PixelTest::SetUpGLRenderer(bool use_skia_gpu_backend) {
ContextProviderInProcess::CreateOffscreen()));
output_surface_->BindToClient(fake_client_.get());
- resource_provider_ = ResourceProvider::Create(output_surface_.get(), 0);
+ resource_provider_ =
+ ResourceProvider::Create(output_surface_.get(), 0, false);
texture_mailbox_deleter_ = make_scoped_ptr(new TextureMailboxDeleter);
@@ -204,7 +205,8 @@ void PixelTest::SetUpSoftwareRenderer() {
scoped_ptr<SoftwareOutputDevice> device(new PixelTestSoftwareOutputDevice());
output_surface_.reset(new PixelTestOutputSurface(device.Pass()));
output_surface_->BindToClient(fake_client_.get());
- resource_provider_ = ResourceProvider::Create(output_surface_.get(), 0);
+ resource_provider_ =
+ ResourceProvider::Create(output_surface_.get(), 0, false);
renderer_ = SoftwareRenderer::Create(fake_client_.get(),
&settings_,
output_surface_.get(),
diff --git a/cc/test/render_pass_test_common.cc b/cc/test/render_pass_test_common.cc
index 13e5c54..b50d923 100644
--- a/cc/test/render_pass_test_common.cc
+++ b/cc/test/render_pass_test_common.cc
@@ -36,51 +36,51 @@ void TestRenderPass::AppendOneOfEveryQuadType(
cc::ResourceProvider::ResourceId resource1 =
resource_provider->CreateResource(
gfx::Size(45, 5),
- resource_provider->best_texture_format(),
GL_CLAMP_TO_EDGE,
- ResourceProvider::TextureUsageAny);
+ ResourceProvider::TextureUsageAny,
+ resource_provider->best_texture_format());
resource_provider->AllocateForTesting(resource1);
cc::ResourceProvider::ResourceId resource2 =
resource_provider->CreateResource(
gfx::Size(346, 61),
- resource_provider->best_texture_format(),
GL_CLAMP_TO_EDGE,
- ResourceProvider::TextureUsageAny);
+ ResourceProvider::TextureUsageAny,
+ resource_provider->best_texture_format());
resource_provider->AllocateForTesting(resource2);
cc::ResourceProvider::ResourceId resource3 =
resource_provider->CreateResource(
gfx::Size(12, 134),
- resource_provider->best_texture_format(),
GL_CLAMP_TO_EDGE,
- ResourceProvider::TextureUsageAny);
+ ResourceProvider::TextureUsageAny,
+ resource_provider->best_texture_format());
resource_provider->AllocateForTesting(resource3);
cc::ResourceProvider::ResourceId resource4 =
resource_provider->CreateResource(
gfx::Size(56, 12),
- resource_provider->best_texture_format(),
GL_CLAMP_TO_EDGE,
- ResourceProvider::TextureUsageAny);
+ ResourceProvider::TextureUsageAny,
+ resource_provider->best_texture_format());
resource_provider->AllocateForTesting(resource4);
cc::ResourceProvider::ResourceId resource5 =
resource_provider->CreateResource(
gfx::Size(73, 26),
- resource_provider->best_texture_format(),
GL_CLAMP_TO_EDGE,
- ResourceProvider::TextureUsageAny);
+ ResourceProvider::TextureUsageAny,
+ resource_provider->best_texture_format());
resource_provider->AllocateForTesting(resource5);
cc::ResourceProvider::ResourceId resource6 =
resource_provider->CreateResource(
gfx::Size(64, 92),
- resource_provider->best_texture_format(),
GL_CLAMP_TO_EDGE,
- ResourceProvider::TextureUsageAny);
+ ResourceProvider::TextureUsageAny,
+ resource_provider->best_texture_format());
resource_provider->AllocateForTesting(resource6);
cc::ResourceProvider::ResourceId resource7 =
resource_provider->CreateResource(
gfx::Size(9, 14),
- resource_provider->best_texture_format(),
GL_CLAMP_TO_EDGE,
- ResourceProvider::TextureUsageAny);
+ ResourceProvider::TextureUsageAny,
+ resource_provider->best_texture_format());
resource_provider->AllocateForTesting(resource7);
scoped_ptr<cc::SharedQuadState> shared_state = cc::SharedQuadState::Create();
@@ -220,9 +220,9 @@ void TestRenderPass::AppendOneOfEveryQuadType(
plane_resources[i] =
resource_provider->CreateResource(
gfx::Size(20, 12),
- resource_provider->best_texture_format(),
GL_CLAMP_TO_EDGE,
- ResourceProvider::TextureUsageAny);
+ ResourceProvider::TextureUsageAny,
+ resource_provider->best_texture_format());
resource_provider->AllocateForTesting(plane_resources[i]);
}
scoped_ptr<cc::YUVVideoDrawQuad> yuv_quad =
diff --git a/cc/test/tiled_layer_test_common.cc b/cc/test/tiled_layer_test_common.cc
index 79d658d..4db79e8 100644
--- a/cc/test/tiled_layer_test_common.cc
+++ b/cc/test/tiled_layer_test_common.cc
@@ -71,7 +71,7 @@ FakeTiledLayer::FakeTiledLayer(PrioritizedResourceManager* resource_manager)
fake_updater_(make_scoped_refptr(new FakeLayerUpdater)),
resource_manager_(resource_manager) {
SetTileSize(tile_size());
- SetTextureFormat(GL_RGBA);
+ SetTextureFormat(RGBA_8888);
SetBorderTexelOption(LayerTilingData::NO_BORDER_TEXELS);
// So that we don't get false positives if any of these
// tests expect to return false from DrawsContent() for other reasons.
diff --git a/cc/trees/layer_tree_host.cc b/cc/trees/layer_tree_host.cc
index dea5757..8afb592 100644
--- a/cc/trees/layer_tree_host.cc
+++ b/cc/trees/layer_tree_host.cc
@@ -47,7 +47,7 @@ static int s_num_layer_tree_instances;
namespace cc {
RendererCapabilities::RendererCapabilities()
- : best_texture_format(0),
+ : best_texture_format(RGBA_8888),
using_partial_swap(false),
using_set_visibility(false),
using_egl_image(false),
@@ -197,7 +197,7 @@ LayerTreeHost::OnCreateAndInitializeOutputSurfaceAttempted(bool success) {
contents_texture_manager_ =
PrioritizedResourceManager::Create(proxy_.get());
surface_memory_placeholder_ =
- contents_texture_manager_->CreateTexture(gfx::Size(), GL_RGBA);
+ contents_texture_manager_->CreateTexture(gfx::Size(), RGBA_8888);
}
client_->DidInitializeOutputSurface(true);
@@ -930,7 +930,7 @@ size_t LayerTreeHost::CalculateMemoryForRenderSurfaces(
size_t bytes =
Resource::MemorySizeBytes(render_surface->content_rect().size(),
- GL_RGBA);
+ RGBA_8888);
contents_texture_bytes += bytes;
if (render_surface_layer->background_filters().IsEmpty())
@@ -940,7 +940,7 @@ size_t LayerTreeHost::CalculateMemoryForRenderSurfaces(
max_background_texture_bytes = bytes;
if (!readback_bytes) {
readback_bytes = Resource::MemorySizeBytes(device_viewport_size_,
- GL_RGBA);
+ RGBA_8888);
}
}
return readback_bytes + max_background_texture_bytes + contents_texture_bytes;
diff --git a/cc/trees/layer_tree_host.h b/cc/trees/layer_tree_host.h
index ba91e11..fff226a 100644
--- a/cc/trees/layer_tree_host.h
+++ b/cc/trees/layer_tree_host.h
@@ -24,6 +24,7 @@
#include "cc/input/top_controls_state.h"
#include "cc/layers/layer_lists.h"
#include "cc/output/output_surface.h"
+#include "cc/resources/resource_format.h"
#include "cc/resources/scoped_ui_resource.h"
#include "cc/resources/ui_resource_bitmap.h"
#include "cc/resources/ui_resource_client.h"
@@ -73,7 +74,7 @@ struct CC_EXPORT RendererCapabilities {
RendererCapabilities();
~RendererCapabilities();
- unsigned best_texture_format;
+ ResourceFormat best_texture_format;
bool using_partial_swap;
bool using_set_visibility;
bool using_egl_image;
diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc
index 2f657e1..3a95b5b 100644
--- a/cc/trees/layer_tree_host_impl.cc
+++ b/cc/trees/layer_tree_host_impl.cc
@@ -1699,7 +1699,9 @@ bool LayerTreeHostImpl::InitializeRenderer(
return false;
scoped_ptr<ResourceProvider> resource_provider = ResourceProvider::Create(
- output_surface.get(), settings_.highp_threshold_min);
+ output_surface.get(),
+ settings_.highp_threshold_min,
+ settings_.use_rgba_4444_textures);
if (!resource_provider)
return false;
@@ -2650,9 +2652,9 @@ void LayerTreeHostImpl::CreateUIResource(
DeleteUIResource(uid);
id = resource_provider_->CreateResource(
bitmap->GetSize(),
- resource_provider_->best_texture_format(),
wrap_mode,
- ResourceProvider::TextureUsageAny);
+ ResourceProvider::TextureUsageAny,
+ resource_provider_->best_texture_format());
ui_resource_map_[uid] = id;
resource_provider_->SetPixels(id,
diff --git a/cc/trees/layer_tree_host_impl_unittest.cc b/cc/trees/layer_tree_host_impl_unittest.cc
index 3676745..d386795 100644
--- a/cc/trees/layer_tree_host_impl_unittest.cc
+++ b/cc/trees/layer_tree_host_impl_unittest.cc
@@ -1529,9 +1529,9 @@ class MissingTextureAnimatingLayer : public DidDrawCheckLayer {
if (!tile_missing) {
ResourceProvider::ResourceId resource =
resource_provider->CreateResource(gfx::Size(1, 1),
- GL_RGBA,
GL_CLAMP_TO_EDGE,
- ResourceProvider::TextureUsageAny);
+ ResourceProvider::TextureUsageAny,
+ RGBA_8888);
resource_provider->AllocateForTesting(resource);
PushTileProperties(0, 0, resource, gfx::Rect(), false);
}
@@ -2621,9 +2621,9 @@ class BlendStateCheckLayer : public LayerImpl {
quad_visible_rect_(5, 5, 5, 5),
resource_id_(resource_provider->CreateResource(
gfx::Size(1, 1),
- GL_RGBA,
GL_CLAMP_TO_EDGE,
- ResourceProvider::TextureUsageAny)) {
+ ResourceProvider::TextureUsageAny,
+ RGBA_8888)) {
resource_provider->AllocateForTesting(resource_id_);
SetAnchorPoint(gfx::PointF());
SetBounds(gfx::Size(10, 10));
@@ -5371,7 +5371,7 @@ TEST_F(LayerTreeHostImplTest, TestRemoveRenderPasses) {
ASSERT_TRUE(output_surface->context_provider());
scoped_ptr<ResourceProvider> resource_provider =
- ResourceProvider::Create(output_surface.get(), 0);
+ ResourceProvider::Create(output_surface.get(), 0, false);
scoped_ptr<TestRenderer> renderer = TestRenderer::Create(
&settings, resource_provider.get(), output_surface.get(), &proxy_);
diff --git a/cc/trees/layer_tree_host_unittest.cc b/cc/trees/layer_tree_host_unittest.cc
index 2849589..0cb69f5 100644
--- a/cc/trees/layer_tree_host_unittest.cc
+++ b/cc/trees/layer_tree_host_unittest.cc
@@ -1741,7 +1741,7 @@ class EvictionTestLayer : public Layer {
return;
texture_ = PrioritizedResource::Create(
layer_tree_host()->contents_texture_manager());
- texture_->SetDimensions(gfx::Size(10, 10), GL_RGBA);
+ texture_->SetDimensions(gfx::Size(10, 10), RGBA_8888);
bitmap_.setConfig(SkBitmap::kARGB_8888_Config, 10, 10);
}
diff --git a/cc/trees/layer_tree_host_unittest_context.cc b/cc/trees/layer_tree_host_unittest_context.cc
index 6615cfc..18683e8 100644
--- a/cc/trees/layer_tree_host_unittest_context.cc
+++ b/cc/trees/layer_tree_host_unittest_context.cc
@@ -1264,9 +1264,9 @@ class LayerTreeHostContextTestDontUseLostResources
ResourceProvider::ResourceId texture = resource_provider->CreateResource(
gfx::Size(4, 4),
- resource_provider->default_resource_type(),
GL_CLAMP_TO_EDGE,
- ResourceProvider::TextureUsageAny);
+ ResourceProvider::TextureUsageAny,
+ RGBA_8888);
ResourceProvider::ScopedWriteLockGL lock(resource_provider, texture);
gpu::Mailbox mailbox;
diff --git a/cc/trees/layer_tree_settings.cc b/cc/trees/layer_tree_settings.cc
index 1743532..3e9cb21 100644
--- a/cc/trees/layer_tree_settings.cc
+++ b/cc/trees/layer_tree_settings.cc
@@ -56,7 +56,8 @@ LayerTreeSettings::LayerTreeSettings()
force_direct_layer_drawing(false),
strict_layer_property_change_checking(false),
use_map_image(false),
- ignore_root_layer_flings(false) {
+ ignore_root_layer_flings(false),
+ use_rgba_4444_textures(false) {
// TODO(danakj): Renable surface caching when we can do it more realiably.
// crbug.com/170713
cache_render_pass_contents = false;
diff --git a/cc/trees/layer_tree_settings.h b/cc/trees/layer_tree_settings.h
index e66f229..53b97dc 100644
--- a/cc/trees/layer_tree_settings.h
+++ b/cc/trees/layer_tree_settings.h
@@ -67,6 +67,7 @@ class CC_EXPORT LayerTreeSettings {
bool strict_layer_property_change_checking;
bool use_map_image;
bool ignore_root_layer_flings;
+ bool use_rgba_4444_textures;
LayerTreeDebugState initial_debug_state;
};