diff options
author | kaanb@chromium.org <kaanb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-18 09:34:21 +0000 |
---|---|---|
committer | kaanb@chromium.org <kaanb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-18 09:34:21 +0000 |
commit | 8e6d15826280b9f11a28060b5b2d2bbef17d15bc (patch) | |
tree | 4e9d72e8a47235583089c67bfdc16da572370812 /cc/resources | |
parent | 2ec5b56e62d38f6a1947868f90f63633c3579b54 (diff) | |
download | chromium_src-8e6d15826280b9f11a28060b5b2d2bbef17d15bc.zip chromium_src-8e6d15826280b9f11a28060b5b2d2bbef17d15bc.tar.gz chromium_src-8e6d15826280b9f11a28060b5b2d2bbef17d15bc.tar.bz2 |
Adding support for RGBA_4444 tile textures
BUG=245774,272539
Review URL: https://chromiumcodereview.appspot.com/21159007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@223830 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/resources')
36 files changed, 536 insertions, 309 deletions
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() { |