diff options
author | auygun <auygun@opera.com> | 2016-02-22 03:09:35 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-22 11:10:56 +0000 |
commit | 2cb89894001edd7dd1c3a1c051de76d65b0d9ff8 (patch) | |
tree | b30a6cac13c996012423b706a9414c44975742c6 | |
parent | 14bbbf277bf50e0103891dd2ad80aa8d091fe6d5 (diff) | |
download | chromium_src-2cb89894001edd7dd1c3a1c051de76d65b0d9ff8.zip chromium_src-2cb89894001edd7dd1c3a1c051de76d65b0d9ff8.tar.gz chromium_src-2cb89894001edd7dd1c3a1c051de76d65b0d9ff8.tar.bz2 |
Reland Allow one-copy and zero-copy task tile worker pools to use compressed textures.
BUG=434699
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel
Review URL: https://codereview.chromium.org/1713503002
Cr-Commit-Position: refs/heads/master@{#376711}
27 files changed, 252 insertions, 113 deletions
diff --git a/blimp/client/feature/compositor/blimp_layer_tree_settings.cc b/blimp/client/feature/compositor/blimp_layer_tree_settings.cc index c78604c..2620b36 100644 --- a/blimp/client/feature/compositor/blimp_layer_tree_settings.cc +++ b/blimp/client/feature/compositor/blimp_layer_tree_settings.cc @@ -66,12 +66,13 @@ void PopulateCommonLayerTreeSettings(cc::LayerTreeSettings* settings) { settings->renderer_settings.highp_threshold_min = 2048; settings->ignore_root_layer_flings = false; bool use_low_memory_policy = base::SysInfo::IsLowEndDevice(); - settings->renderer_settings.use_rgba_4444_textures = use_low_memory_policy; if (use_low_memory_policy) { // On low-end we want to be very carefull about killing other // apps. So initially we use 50% more memory to avoid flickering // or raster-on-demand. settings->max_memory_for_prepaint_percentage = 67; + + settings->renderer_settings.preferred_tile_format = cc::RGBA_4444; } else { // On other devices we have increased memory excessively to avoid // raster-on-demand already, so now we reserve 50% _only_ to avoid diff --git a/cc/base/switches.cc b/cc/base/switches.cc index 4e02de1..25565b1 100644 --- a/cc/base/switches.cc +++ b/cc/base/switches.cc @@ -45,6 +45,9 @@ const char kSlowDownRasterScaleFactor[] = "slow-down-raster-scale-factor"; const char kStrictLayerPropertyChangeChecking[] = "strict-layer-property-change-checking"; +// Compress tile textures for GPUs supporting it. +const char kEnableTileCompression[] = "enable-tile-compression"; + // Use a BeginFrame signal from browser to renderer to schedule rendering. const char kEnableBeginFrameScheduling[] = "enable-begin-frame-scheduling"; diff --git a/cc/base/switches.h b/cc/base/switches.h index 63d806c..0713053 100644 --- a/cc/base/switches.h +++ b/cc/base/switches.h @@ -25,6 +25,7 @@ CC_EXPORT extern const char kTopControlsHideThreshold[]; CC_EXPORT extern const char kTopControlsShowThreshold[]; CC_EXPORT extern const char kSlowDownRasterScaleFactor[]; CC_EXPORT extern const char kStrictLayerPropertyChangeChecking[]; +CC_EXPORT extern const char kEnableTileCompression[]; // Switches for both the renderer and ui compositors. CC_EXPORT extern const char kEnableBeginFrameScheduling[]; diff --git a/cc/layers/picture_layer_impl.cc b/cc/layers/picture_layer_impl.cc index 93d9bf1..695f539 100644 --- a/cc/layers/picture_layer_impl.cc +++ b/cc/layers/picture_layer_impl.cc @@ -52,6 +52,10 @@ const int kMinHeightForGpuRasteredTile = 256; // of using the same tile size. const int kTileRoundUp = 64; +// For performance reasons and to support compressed tile textures, tile +// width and height should be an even multiple of 4 in size. +const int kTileMinimalAlignment = 4; + } // namespace namespace cc { @@ -781,6 +785,10 @@ gfx::Size PictureLayerImpl::CalculateTileSize( tile_height = std::min(tile_height, default_tile_height); } + // Ensure that tile width and height are properly aligned. + tile_width = MathUtil::UncheckedRoundUp(tile_width, kTileMinimalAlignment); + tile_height = MathUtil::UncheckedRoundUp(tile_height, kTileMinimalAlignment); + // Under no circumstance should we be larger than the max texture size. tile_width = std::min(tile_width, max_texture_size); tile_height = std::min(tile_height, max_texture_size); diff --git a/cc/layers/picture_layer_impl_unittest.cc b/cc/layers/picture_layer_impl_unittest.cc index 0f73ef1..04bac67 100644 --- a/cc/layers/picture_layer_impl_unittest.cc +++ b/cc/layers/picture_layer_impl_unittest.cc @@ -4890,8 +4890,10 @@ TEST_F(TileSizeTest, TileSizes) { layer->set_gpu_raster_max_texture_size(host_impl_.device_viewport_size()); result = layer->CalculateTileSize(gfx::Size(10000, 10000)); - EXPECT_EQ(result.width(), 2000 + 2 * PictureLayerTiling::kBorderTexels); - EXPECT_EQ(result.height(), 500 + 2); + EXPECT_EQ(result.width(), + MathUtil::UncheckedRoundUp( + 2000 + 2 * PictureLayerTiling::kBorderTexels, 4)); + EXPECT_EQ(result.height(), 504); // 500 + 2, 4-byte aligned. // Clamp and round-up, when smaller than viewport. // Tile-height doubles to 50% when width shrinks to <= 50%. @@ -4899,7 +4901,7 @@ TEST_F(TileSizeTest, TileSizes) { layer->set_gpu_raster_max_texture_size(host_impl_.device_viewport_size()); result = layer->CalculateTileSize(gfx::Size(447, 10000)); EXPECT_EQ(result.width(), 448); - EXPECT_EQ(result.height(), 500 + 2); + EXPECT_EQ(result.height(), 504); // 500 + 2, 4-byte aliged. // Largest layer is 50% of viewport width (rounded up), and // 50% of viewport in height. @@ -4908,7 +4910,7 @@ TEST_F(TileSizeTest, TileSizes) { EXPECT_EQ(result.height(), 448); result = layer->CalculateTileSize(gfx::Size(500, 499)); EXPECT_EQ(result.width(), 512); - EXPECT_EQ(result.height(), 500 + 2); + EXPECT_EQ(result.height(), 504); // 500 + 2, 4-byte aligned. } TEST_F(NoLowResPictureLayerImplTest, LowResWasHighResCollision) { diff --git a/cc/output/renderer_settings.cc b/cc/output/renderer_settings.cc index 133fb33..c0927cc 100644 --- a/cc/output/renderer_settings.cc +++ b/cc/output/renderer_settings.cc @@ -8,6 +8,7 @@ #include "base/logging.h" #include "cc/proto/renderer_settings.pb.h" +#include "cc/resources/platform_color.h" namespace cc { @@ -22,9 +23,9 @@ RendererSettings::RendererSettings() release_overlay_resources_on_swap_complete(false), refresh_rate(60.0), highp_threshold_min(0), - use_rgba_4444_textures(false), texture_id_allocation_chunk_size(64), - use_gpu_memory_buffer_resources(false) {} + use_gpu_memory_buffer_resources(false), + preferred_tile_format(PlatformColor::BestTextureFormat()) {} RendererSettings::~RendererSettings() { } @@ -41,9 +42,9 @@ void RendererSettings::ToProtobuf(proto::RendererSettings* proto) const { release_overlay_resources_on_swap_complete); proto->set_refresh_rate(refresh_rate); proto->set_highp_threshold_min(highp_threshold_min); - proto->set_use_rgba_4444_textures(use_rgba_4444_textures); proto->set_texture_id_allocation_chunk_size(texture_id_allocation_chunk_size); proto->set_use_gpu_memory_buffer_resources(use_gpu_memory_buffer_resources); + proto->set_preferred_tile_format(preferred_tile_format); } void RendererSettings::FromProtobuf(const proto::RendererSettings& proto) { @@ -58,9 +59,13 @@ void RendererSettings::FromProtobuf(const proto::RendererSettings& proto) { proto.release_overlay_resources_on_swap_complete(); refresh_rate = proto.refresh_rate(); highp_threshold_min = proto.highp_threshold_min(); - use_rgba_4444_textures = proto.use_rgba_4444_textures(); texture_id_allocation_chunk_size = proto.texture_id_allocation_chunk_size(); use_gpu_memory_buffer_resources = proto.use_gpu_memory_buffer_resources(); + + DCHECK_LE(proto.preferred_tile_format(), + static_cast<uint32_t>(RESOURCE_FORMAT_MAX)); + preferred_tile_format = + static_cast<ResourceFormat>(proto.preferred_tile_format()); } bool RendererSettings::operator==(const RendererSettings& other) const { @@ -75,11 +80,11 @@ bool RendererSettings::operator==(const RendererSettings& other) const { other.release_overlay_resources_on_swap_complete && refresh_rate == other.refresh_rate && highp_threshold_min == other.highp_threshold_min && - use_rgba_4444_textures == other.use_rgba_4444_textures && texture_id_allocation_chunk_size == other.texture_id_allocation_chunk_size && use_gpu_memory_buffer_resources == - other.use_gpu_memory_buffer_resources; + other.use_gpu_memory_buffer_resources && + preferred_tile_format == other.preferred_tile_format; } } // namespace cc diff --git a/cc/output/renderer_settings.h b/cc/output/renderer_settings.h index 657996e..5aeaee6 100644 --- a/cc/output/renderer_settings.h +++ b/cc/output/renderer_settings.h @@ -8,6 +8,7 @@ #include <stddef.h> #include "cc/base/cc_export.h" +#include "cc/resources/resource_format.h" namespace cc { @@ -30,9 +31,9 @@ class CC_EXPORT RendererSettings { bool release_overlay_resources_on_swap_complete; double refresh_rate; int highp_threshold_min; - bool use_rgba_4444_textures; size_t texture_id_allocation_chunk_size; bool use_gpu_memory_buffer_resources; + ResourceFormat preferred_tile_format; void ToProtobuf(proto::RendererSettings* proto) const; void FromProtobuf(const proto::RendererSettings& proto); diff --git a/cc/output/renderer_settings_unittest.cc b/cc/output/renderer_settings_unittest.cc index ca318ae..281c278 100644 --- a/cc/output/renderer_settings_unittest.cc +++ b/cc/output/renderer_settings_unittest.cc @@ -30,9 +30,9 @@ TEST(RendererSettingsTest, AllFieldsFlipped) { settings.release_overlay_resources_on_swap_complete = true; settings.refresh_rate = 6.0; settings.highp_threshold_min = 1; - settings.use_rgba_4444_textures = true; settings.texture_id_allocation_chunk_size = 46; settings.use_gpu_memory_buffer_resources = true; + settings.preferred_tile_format = RGBA_4444; VerifySerializeAndDeserializeProto(settings); } @@ -48,9 +48,9 @@ TEST(RendererSettingsTest, ArbitraryFieldValues) { settings.release_overlay_resources_on_swap_complete = true; settings.refresh_rate = 999.0; settings.highp_threshold_min = 1; - settings.use_rgba_4444_textures = true; settings.texture_id_allocation_chunk_size = 12; settings.use_gpu_memory_buffer_resources = true; + settings.preferred_tile_format = RGBA_4444; VerifySerializeAndDeserializeProto(settings); } diff --git a/cc/proto/renderer_settings.proto b/cc/proto/renderer_settings.proto index c439934..753de48 100644 --- a/cc/proto/renderer_settings.proto +++ b/cc/proto/renderer_settings.proto @@ -19,7 +19,7 @@ message RendererSettings { optional bool release_overlay_resources_on_swap_complete = 8; optional double refresh_rate = 9; optional uint32 highp_threshold_min = 10; - optional bool use_rgba_4444_textures = 11; - optional uint32 texture_id_allocation_chunk_size = 12; - optional bool use_gpu_memory_buffer_resources = 13; + optional uint32 texture_id_allocation_chunk_size = 11; + optional bool use_gpu_memory_buffer_resources = 12; + optional uint32 preferred_tile_format = 13; } diff --git a/cc/raster/one_copy_tile_task_worker_pool.cc b/cc/raster/one_copy_tile_task_worker_pool.cc index 1252205..38e3076 100644 --- a/cc/raster/one_copy_tile_task_worker_pool.cc +++ b/cc/raster/one_copy_tile_task_worker_pool.cc @@ -185,11 +185,11 @@ scoped_ptr<TileTaskWorkerPool> OneCopyTileTaskWorkerPool::Create( int max_copy_texture_chromium_size, bool use_partial_raster, int max_staging_buffer_usage_in_bytes, - bool use_rgba_4444_texture_format) { + ResourceFormat preferred_tile_format) { return make_scoped_ptr<TileTaskWorkerPool>(new OneCopyTileTaskWorkerPool( task_runner, task_graph_runner, resource_provider, max_copy_texture_chromium_size, use_partial_raster, - max_staging_buffer_usage_in_bytes, use_rgba_4444_texture_format)); + max_staging_buffer_usage_in_bytes, preferred_tile_format)); } OneCopyTileTaskWorkerPool::OneCopyTileTaskWorkerPool( @@ -199,7 +199,7 @@ OneCopyTileTaskWorkerPool::OneCopyTileTaskWorkerPool( int max_copy_texture_chromium_size, bool use_partial_raster, int max_staging_buffer_usage_in_bytes, - bool use_rgba_4444_texture_format) + ResourceFormat preferred_tile_format) : task_runner_(task_runner), task_graph_runner_(task_graph_runner), namespace_token_(task_graph_runner->GetNamespaceToken()), @@ -212,7 +212,7 @@ OneCopyTileTaskWorkerPool::OneCopyTileTaskWorkerPool( use_partial_raster_(use_partial_raster), bytes_scheduled_since_last_flush_(0), max_staging_buffer_usage_in_bytes_(max_staging_buffer_usage_in_bytes), - use_rgba_4444_texture_format_(use_rgba_4444_texture_format), + preferred_tile_format_(preferred_tile_format), staging_buffer_usage_in_bytes_(0), free_staging_buffer_usage_in_bytes_(0), staging_buffer_expiration_delay_( @@ -285,9 +285,13 @@ void OneCopyTileTaskWorkerPool::CheckForCompletedTasks() { ResourceFormat OneCopyTileTaskWorkerPool::GetResourceFormat( bool must_support_alpha) const { - return use_rgba_4444_texture_format_ - ? RGBA_4444 - : resource_provider_->best_texture_format(); + if (resource_provider_->IsResourceFormatSupported(preferred_tile_format_) && + (DoesResourceFormatSupportAlpha(preferred_tile_format_) || + !must_support_alpha)) { + return preferred_tile_format_; + } + + return resource_provider_->best_texture_format(); } bool OneCopyTileTaskWorkerPool::GetResourceRequiresSwizzle( @@ -427,31 +431,39 @@ void OneCopyTileTaskWorkerPool::PlaybackAndCopyOnWorkerThread( #endif } - int bytes_per_row = - (BitsPerPixel(resource->format()) * resource->size().width()) / 8; - int chunk_size_in_rows = - std::max(1, max_bytes_per_copy_operation_ / bytes_per_row); - // Align chunk size to 4. Required to support compressed texture formats. - chunk_size_in_rows = MathUtil::UncheckedRoundUp(chunk_size_in_rows, 4); - int y = 0; - int height = resource->size().height(); - while (y < height) { - // Copy at most |chunk_size_in_rows|. - int rows_to_copy = std::min(chunk_size_in_rows, height - y); - DCHECK_GT(rows_to_copy, 0); - - gl->CopySubTextureCHROMIUM( - staging_buffer->texture_id, resource_lock->texture_id(), 0, y, 0, y, - resource->size().width(), rows_to_copy, false, false, false); - y += rows_to_copy; - - // Increment |bytes_scheduled_since_last_flush_| by the amount of memory - // used for this copy operation. - bytes_scheduled_since_last_flush_ += rows_to_copy * bytes_per_row; - - if (bytes_scheduled_since_last_flush_ >= max_bytes_per_copy_operation_) { - gl->ShallowFlushCHROMIUM(); - bytes_scheduled_since_last_flush_ = 0; + // Since compressed texture's cannot be pre-allocated we might have an + // unallocated resource in which case we need to perform a full size copy. + if (IsResourceFormatCompressed(resource->format())) { + gl->CompressedCopyTextureCHROMIUM(staging_buffer->texture_id, + resource_lock->texture_id()); + } else { + int bytes_per_row = + (BitsPerPixel(resource->format()) * resource->size().width()) / 8; + int chunk_size_in_rows = + std::max(1, max_bytes_per_copy_operation_ / bytes_per_row); + // Align chunk size to 4. Required to support compressed texture formats. + chunk_size_in_rows = MathUtil::UncheckedRoundUp(chunk_size_in_rows, 4); + int y = 0; + int height = resource->size().height(); + while (y < height) { + // Copy at most |chunk_size_in_rows|. + int rows_to_copy = std::min(chunk_size_in_rows, height - y); + DCHECK_GT(rows_to_copy, 0); + + gl->CopySubTextureCHROMIUM( + staging_buffer->texture_id, resource_lock->texture_id(), 0, y, 0, y, + resource->size().width(), rows_to_copy, false, false, false); + y += rows_to_copy; + + // Increment |bytes_scheduled_since_last_flush_| by the amount of memory + // used for this copy operation. + bytes_scheduled_since_last_flush_ += rows_to_copy * bytes_per_row; + + if (bytes_scheduled_since_last_flush_ >= + max_bytes_per_copy_operation_) { + gl->ShallowFlushCHROMIUM(); + bytes_scheduled_since_last_flush_ = 0; + } } } diff --git a/cc/raster/one_copy_tile_task_worker_pool.h b/cc/raster/one_copy_tile_task_worker_pool.h index 581c57b..3a9187e 100644 --- a/cc/raster/one_copy_tile_task_worker_pool.h +++ b/cc/raster/one_copy_tile_task_worker_pool.h @@ -53,7 +53,7 @@ class CC_EXPORT OneCopyTileTaskWorkerPool int max_copy_texture_chromium_size, bool use_partial_raster, int max_staging_buffer_usage_in_bytes, - bool use_rgba_4444_texture_format); + ResourceFormat preferred_tile_format); // Overridden from TileTaskWorkerPool: TileTaskRunner* AsTileTaskRunner() override; @@ -95,7 +95,7 @@ class CC_EXPORT OneCopyTileTaskWorkerPool int max_copy_texture_chromium_size, bool use_partial_raster, int max_staging_buffer_usage_in_bytes, - bool use_rgba_4444_texture_format); + ResourceFormat preferred_tile_format); private: struct StagingBuffer { @@ -152,7 +152,7 @@ class CC_EXPORT OneCopyTileTaskWorkerPool StagingBufferDeque busy_buffers_; int bytes_scheduled_since_last_flush_; const int max_staging_buffer_usage_in_bytes_; - bool use_rgba_4444_texture_format_; + ResourceFormat preferred_tile_format_; int staging_buffer_usage_in_bytes_; int free_staging_buffer_usage_in_bytes_; const base::TimeDelta staging_buffer_expiration_delay_; diff --git a/cc/raster/tile_task_worker_pool.cc b/cc/raster/tile_task_worker_pool.cc index d4549c7..b746d22 100644 --- a/cc/raster/tile_task_worker_pool.cc +++ b/cc/raster/tile_task_worker_pool.cc @@ -8,6 +8,7 @@ #include "base/trace_event/trace_event.h" #include "cc/playback/display_list_raster_source.h" +#include "cc/raster/texture_compressor.h" #include "skia/ext/refptr.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkSurface.h" @@ -44,11 +45,11 @@ bool IsSupportedPlaybackToMemoryFormat(ResourceFormat format) { case RGBA_4444: case RGBA_8888: case BGRA_8888: + case ETC1: return true; case ALPHA_8: case LUMINANCE_8: case RGB_565: - case ETC1: case RED_8: case LUMINANCE_F16: return false; @@ -116,8 +117,6 @@ void TileTaskWorkerPool::PlaybackToMemory( // Uses kPremul_SkAlphaType since the result is not known to be opaque. SkImageInfo info = SkImageInfo::MakeN32(size.width(), size.height(), kPremul_SkAlphaType); - SkColorType buffer_color_type = ResourceFormatToSkColorType(format); - bool needs_copy = buffer_color_type != info.colorType(); // Use unknown pixel geometry to disable LCD text. SkSurfaceProps surface_props(0, kUnknown_SkPixelGeometry); @@ -130,31 +129,59 @@ void TileTaskWorkerPool::PlaybackToMemory( stride = info.minRowBytes(); DCHECK_GT(stride, 0u); - if (!needs_copy) { - skia::RefPtr<SkSurface> surface = skia::AdoptRef( - SkSurface::NewRasterDirect(info, memory, stride, &surface_props)); - AutoSkipImageCanvas canvas(surface->getCanvas(), include_images); - raster_source->PlaybackToCanvas(canvas, canvas_bitmap_rect, - canvas_playback_rect, scale); - return; - } - - skia::RefPtr<SkSurface> surface = - skia::AdoptRef(SkSurface::NewRaster(info, &surface_props)); - AutoSkipImageCanvas canvas(surface->getCanvas(), include_images); - // TODO(reveman): Improve partial raster support by reducing the size of - // playback rect passed to PlaybackToCanvas. crbug.com/519070 - raster_source->PlaybackToCanvas(canvas, canvas_bitmap_rect, - canvas_bitmap_rect, scale); - { TRACE_EVENT0("cc", "TileTaskWorkerPool::PlaybackToMemory::ConvertPixels"); - SkImageInfo dst_info = - SkImageInfo::Make(info.width(), info.height(), buffer_color_type, - info.alphaType(), info.profileType()); - bool rv = surface->getCanvas()->readPixels(dst_info, memory, stride, 0, 0); - DCHECK(rv); + switch (format) { + case RGBA_8888: + case BGRA_8888: { + skia::RefPtr<SkSurface> surface = skia::AdoptRef( + SkSurface::NewRasterDirect(info, memory, stride, &surface_props)); + AutoSkipImageCanvas canvas(surface->getCanvas(), include_images); + raster_source->PlaybackToCanvas(canvas, canvas_bitmap_rect, + canvas_playback_rect, scale); + return; + } + case RGBA_4444: + case ETC1: { + skia::RefPtr<SkSurface> surface = + skia::AdoptRef(SkSurface::NewRaster(info, &surface_props)); + AutoSkipImageCanvas canvas(surface->getCanvas(), include_images); + // TODO(reveman): Improve partial raster support by reducing the size of + // playback rect passed to PlaybackToCanvas. crbug.com/519070 + raster_source->PlaybackToCanvas(canvas, canvas_bitmap_rect, + canvas_bitmap_rect, scale); + + if (format == ETC1) { + DCHECK_EQ(size.width() % 4, 0); + DCHECK_EQ(size.height() % 4, 0); + scoped_ptr<TextureCompressor> texture_compressor = + TextureCompressor::Create(TextureCompressor::kFormatETC1); + texture_compressor->Compress( + reinterpret_cast<const uint8_t*>( + surface->peekPixels(nullptr, nullptr)), + reinterpret_cast<uint8_t*>(memory), size.width(), size.height(), + TextureCompressor::kQualityHigh); + } else { + SkImageInfo dst_info = SkImageInfo::Make( + info.width(), info.height(), ResourceFormatToSkColorType(format), + info.alphaType(), info.profileType()); + bool rv = + surface->getCanvas()->readPixels(dst_info, memory, stride, 0, 0); + DCHECK(rv); + } + return; + } + case ALPHA_8: + case LUMINANCE_8: + case RGB_565: + case RED_8: + case LUMINANCE_F16: + NOTREACHED(); + return; + } + + NOTREACHED(); } } diff --git a/cc/raster/tile_task_worker_pool_perftest.cc b/cc/raster/tile_task_worker_pool_perftest.cc index 0abdf8e..086d7b1 100644 --- a/cc/raster/tile_task_worker_pool_perftest.cc +++ b/cc/raster/tile_task_worker_pool_perftest.cc @@ -259,7 +259,7 @@ class TileTaskWorkerPoolPerfTest Create3dOutputSurfaceAndResourceProvider(); tile_task_worker_pool_ = ZeroCopyTileTaskWorkerPool::Create( task_runner_.get(), task_graph_runner_.get(), - resource_provider_.get(), false); + resource_provider_.get(), PlatformColor::BestTextureFormat()); break; case TILE_TASK_WORKER_POOL_TYPE_ONE_COPY: Create3dOutputSurfaceAndResourceProvider(); @@ -267,7 +267,8 @@ class TileTaskWorkerPoolPerfTest task_runner_.get(), task_graph_runner_.get(), context_provider_.get(), resource_provider_.get(), std::numeric_limits<int>::max(), false, - std::numeric_limits<int>::max(), false); + std::numeric_limits<int>::max(), + PlatformColor::BestTextureFormat()); break; case TILE_TASK_WORKER_POOL_TYPE_GPU: Create3dOutputSurfaceAndResourceProvider(); diff --git a/cc/raster/tile_task_worker_pool_unittest.cc b/cc/raster/tile_task_worker_pool_unittest.cc index 9f8b003..2473629e 100644 --- a/cc/raster/tile_task_worker_pool_unittest.cc +++ b/cc/raster/tile_task_worker_pool_unittest.cc @@ -147,14 +147,15 @@ class TileTaskWorkerPoolTest Create3dOutputSurfaceAndResourceProvider(); tile_task_worker_pool_ = ZeroCopyTileTaskWorkerPool::Create( base::ThreadTaskRunnerHandle::Get().get(), &task_graph_runner_, - resource_provider_.get(), false); + resource_provider_.get(), PlatformColor::BestTextureFormat()); break; case TILE_TASK_WORKER_POOL_TYPE_ONE_COPY: Create3dOutputSurfaceAndResourceProvider(); tile_task_worker_pool_ = OneCopyTileTaskWorkerPool::Create( base::ThreadTaskRunnerHandle::Get().get(), &task_graph_runner_, context_provider_.get(), resource_provider_.get(), - kMaxBytesPerCopyOperation, false, kMaxStagingBuffers, false); + kMaxBytesPerCopyOperation, false, kMaxStagingBuffers, + PlatformColor::BestTextureFormat()); break; case TILE_TASK_WORKER_POOL_TYPE_GPU: Create3dOutputSurfaceAndResourceProvider(); diff --git a/cc/raster/zero_copy_tile_task_worker_pool.cc b/cc/raster/zero_copy_tile_task_worker_pool.cc index 4310f96..1fd8e3d 100644 --- a/cc/raster/zero_copy_tile_task_worker_pool.cc +++ b/cc/raster/zero_copy_tile_task_worker_pool.cc @@ -68,22 +68,22 @@ scoped_ptr<TileTaskWorkerPool> ZeroCopyTileTaskWorkerPool::Create( base::SequencedTaskRunner* task_runner, TaskGraphRunner* task_graph_runner, ResourceProvider* resource_provider, - bool use_rgba_4444_texture_format) { - return make_scoped_ptr<TileTaskWorkerPool>(new ZeroCopyTileTaskWorkerPool( - task_runner, task_graph_runner, resource_provider, - use_rgba_4444_texture_format)); + ResourceFormat preferred_tile_format) { + return make_scoped_ptr<TileTaskWorkerPool>( + new ZeroCopyTileTaskWorkerPool(task_runner, task_graph_runner, + resource_provider, preferred_tile_format)); } ZeroCopyTileTaskWorkerPool::ZeroCopyTileTaskWorkerPool( base::SequencedTaskRunner* task_runner, TaskGraphRunner* task_graph_runner, ResourceProvider* resource_provider, - bool use_rgba_4444_texture_format) + ResourceFormat preferred_tile_format) : task_runner_(task_runner), task_graph_runner_(task_graph_runner), namespace_token_(task_graph_runner->GetNamespaceToken()), resource_provider_(resource_provider), - use_rgba_4444_texture_format_(use_rgba_4444_texture_format) {} + preferred_tile_format_(preferred_tile_format) {} ZeroCopyTileTaskWorkerPool::~ZeroCopyTileTaskWorkerPool() { } @@ -125,9 +125,13 @@ void ZeroCopyTileTaskWorkerPool::CheckForCompletedTasks() { ResourceFormat ZeroCopyTileTaskWorkerPool::GetResourceFormat( bool must_support_alpha) const { - return use_rgba_4444_texture_format_ - ? RGBA_4444 - : resource_provider_->best_texture_format(); + if (resource_provider_->IsResourceFormatSupported(preferred_tile_format_) && + (DoesResourceFormatSupportAlpha(preferred_tile_format_) || + !must_support_alpha)) { + return preferred_tile_format_; + } + + return resource_provider_->best_texture_format(); } bool ZeroCopyTileTaskWorkerPool::GetResourceRequiresSwizzle( diff --git a/cc/raster/zero_copy_tile_task_worker_pool.h b/cc/raster/zero_copy_tile_task_worker_pool.h index ffbde20..a961e41 100644 --- a/cc/raster/zero_copy_tile_task_worker_pool.h +++ b/cc/raster/zero_copy_tile_task_worker_pool.h @@ -32,7 +32,7 @@ class CC_EXPORT ZeroCopyTileTaskWorkerPool : public TileTaskWorkerPool, base::SequencedTaskRunner* task_runner, TaskGraphRunner* task_graph_runner, ResourceProvider* resource_provider, - bool use_rgba_4444_texture_format); + ResourceFormat preferred_tile_format); // Overridden from TileTaskWorkerPool: TileTaskRunner* AsTileTaskRunner() override; @@ -55,7 +55,7 @@ class CC_EXPORT ZeroCopyTileTaskWorkerPool : public TileTaskWorkerPool, ZeroCopyTileTaskWorkerPool(base::SequencedTaskRunner* task_runner, TaskGraphRunner* task_graph_runner, ResourceProvider* resource_provider, - bool use_rgba_4444_texture_format); + ResourceFormat preferred_tile_format); private: scoped_refptr<base::trace_event::ConvertableToTraceFormat> StateAsValue() @@ -66,7 +66,7 @@ class CC_EXPORT ZeroCopyTileTaskWorkerPool : public TileTaskWorkerPool, const NamespaceToken namespace_token_; ResourceProvider* resource_provider_; - bool use_rgba_4444_texture_format_; + ResourceFormat preferred_tile_format_; Task::Vector completed_tasks_; diff --git a/cc/resources/platform_color.h b/cc/resources/platform_color.h index f7d3705..26d6b02 100644 --- a/cc/resources/platform_color.h +++ b/cc/resources/platform_color.h @@ -24,7 +24,19 @@ class PlatformColor { } // Returns the most efficient texture format for this platform. - static ResourceFormat BestTextureFormat(bool supports_bgra8888) { + static ResourceFormat BestTextureFormat() { + switch (Format()) { + case SOURCE_FORMAT_BGRA8: + return BGRA_8888; + case SOURCE_FORMAT_RGBA8: + return RGBA_8888; + } + NOTREACHED(); + return RGBA_8888; + } + + // Returns the most efficient supported texture format for this platform. + static ResourceFormat BestSupportedTextureFormat(bool supports_bgra8888) { switch (Format()) { case SOURCE_FORMAT_BGRA8: return (supports_bgra8888) ? BGRA_8888 : RGBA_8888; diff --git a/cc/resources/resource_format.cc b/cc/resources/resource_format.cc index ba4e65d..ec553d8 100644 --- a/cc/resources/resource_format.cc +++ b/cc/resources/resource_format.cc @@ -101,10 +101,11 @@ gfx::BufferFormat BufferFormat(ResourceFormat format) { return gfx::BufferFormat::RGBA_4444; case RGBA_8888: return gfx::BufferFormat::RGBA_8888; + case ETC1: + return gfx::BufferFormat::ETC1; case ALPHA_8: case LUMINANCE_8: case RGB_565: - case ETC1: case LUMINANCE_F16: break; } @@ -112,4 +113,26 @@ gfx::BufferFormat BufferFormat(ResourceFormat format) { return gfx::BufferFormat::RGBA_8888; } +bool IsResourceFormatCompressed(ResourceFormat format) { + return format == ETC1; +} + +bool DoesResourceFormatSupportAlpha(ResourceFormat format) { + switch (format) { + case RGBA_4444: + case RGBA_8888: + case BGRA_8888: + case ALPHA_8: + return true; + case LUMINANCE_8: + case RGB_565: + case ETC1: + case RED_8: + case LUMINANCE_F16: + return false; + } + NOTREACHED(); + return false; +} + } // namespace cc diff --git a/cc/resources/resource_format.h b/cc/resources/resource_format.h index 9a900d4..5266f31 100644 --- a/cc/resources/resource_format.h +++ b/cc/resources/resource_format.h @@ -39,6 +39,9 @@ CC_EXPORT GLenum GLDataFormat(ResourceFormat format); CC_EXPORT GLenum GLInternalFormat(ResourceFormat format); CC_EXPORT gfx::BufferFormat BufferFormat(ResourceFormat format); +bool IsResourceFormatCompressed(ResourceFormat format); +bool DoesResourceFormatSupportAlpha(ResourceFormat format); + } // namespace cc #endif // CC_RESOURCES_RESOURCE_FORMAT_H_ diff --git a/cc/resources/resource_provider.cc b/cc/resources/resource_provider.cc index 98354a1..8913b0c 100644 --- a/cc/resources/resource_provider.cc +++ b/cc/resources/resource_provider.cc @@ -425,6 +425,32 @@ ResourceProvider::~ResourceProvider() { gl->Finish(); } +bool ResourceProvider::IsResourceFormatSupported(ResourceFormat format) const { + ContextProvider::Capabilities caps; + if (output_surface_->context_provider()) + caps = output_surface_->context_provider()->ContextCapabilities(); + + switch (format) { + case ALPHA_8: + case RGBA_4444: + case RGBA_8888: + case RGB_565: + case LUMINANCE_8: + return true; + case BGRA_8888: + return caps.gpu.texture_format_bgra8888; + case ETC1: + return caps.gpu.texture_format_etc1; + case RED_8: + return caps.gpu.texture_rg; + case LUMINANCE_F16: + return caps.gpu.texture_half_float_linear; + } + + NOTREACHED(); + return false; +} + bool ResourceProvider::InUseByConsumer(ResourceId id) { Resource* resource = GetResource(id); return resource->lock_for_read_count > 0 || resource->exported_count > 0 || @@ -1220,10 +1246,10 @@ void ResourceProvider::Initialize() { max_texture_size_ = 0; // Context expects cleared value. gl->GetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size_); best_texture_format_ = - PlatformColor::BestTextureFormat(use_texture_format_bgra_); + PlatformColor::BestSupportedTextureFormat(use_texture_format_bgra_); - best_render_buffer_format_ = - PlatformColor::BestTextureFormat(caps.gpu.render_buffer_format_bgra8888); + best_render_buffer_format_ = PlatformColor::BestSupportedTextureFormat( + caps.gpu.render_buffer_format_bgra8888); texture_id_allocator_.reset( new TextureIdAllocator(gl, id_allocation_chunk_size_)); diff --git a/cc/resources/resource_provider.h b/cc/resources/resource_provider.h index ea5b3e1..a033967 100644 --- a/cc/resources/resource_provider.h +++ b/cc/resources/resource_provider.h @@ -111,6 +111,8 @@ class CC_EXPORT ResourceProvider } size_t num_resources() const { return resources_.size(); } + bool IsResourceFormatSupported(ResourceFormat format) const; + // Checks whether a resource is in use by a consumer. bool InUseByConsumer(ResourceId id); diff --git a/cc/test/layer_tree_pixel_resource_test.cc b/cc/test/layer_tree_pixel_resource_test.cc index 347933c..5d810ab 100644 --- a/cc/test/layer_tree_pixel_resource_test.cc +++ b/cc/test/layer_tree_pixel_resource_test.cc @@ -147,7 +147,8 @@ void LayerTreeHostPixelResourceTest::CreateResourceAndTileTaskWorkerPool( *resource_pool = ResourcePool::Create(resource_provider, task_runner); *tile_task_worker_pool = ZeroCopyTileTaskWorkerPool::Create( - task_runner, task_graph_runner(), resource_provider, false); + task_runner, task_graph_runner(), resource_provider, + PlatformColor::BestTextureFormat()); break; case ONE_COPY_TILE_TASK_WORKER_POOL: EXPECT_TRUE(context_provider); @@ -158,7 +159,8 @@ void LayerTreeHostPixelResourceTest::CreateResourceAndTileTaskWorkerPool( *tile_task_worker_pool = OneCopyTileTaskWorkerPool::Create( task_runner, task_graph_runner(), context_provider, resource_provider, max_bytes_per_copy_operation, false, - max_staging_buffer_usage_in_bytes, false); + max_staging_buffer_usage_in_bytes, + PlatformColor::BestTextureFormat()); break; } } diff --git a/cc/tiles/tile_manager.cc b/cc/tiles/tile_manager.cc index 63e9968..704df07 100644 --- a/cc/tiles/tile_manager.cc +++ b/cc/tiles/tile_manager.cc @@ -833,8 +833,6 @@ scoped_refptr<RasterTask> TileManager::CreateRasterTask( if (resource) { resource_content_id = tile->invalidated_id(); DCHECK_EQ(DetermineResourceFormat(tile), resource->format()); - DCHECK_EQ(tile->desired_texture_size().ToString(), - resource->size().ToString()); } else { resource = resource_pool_->AcquireResource(tile->desired_texture_size(), DetermineResourceFormat(tile)); diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc index bd759da..1ae252f 100644 --- a/cc/trees/layer_tree_host_impl.cc +++ b/cc/trees/layer_tree_host_impl.cc @@ -2226,7 +2226,7 @@ void LayerTreeHostImpl::CreateResourceAndTileTaskWorkerPool( *tile_task_worker_pool = ZeroCopyTileTaskWorkerPool::Create( GetTaskRunner(), task_graph_runner, resource_provider_.get(), - settings_.renderer_settings.use_rgba_4444_textures); + settings_.renderer_settings.preferred_tile_format); return; } @@ -2240,7 +2240,7 @@ void LayerTreeHostImpl::CreateResourceAndTileTaskWorkerPool( GetTaskRunner(), task_graph_runner, context_provider, resource_provider_.get(), max_copy_texture_chromium_size, settings_.use_partial_raster, settings_.max_staging_buffer_usage_in_bytes, - settings_.renderer_settings.use_rgba_4444_textures); + settings_.renderer_settings.preferred_tile_format); } void LayerTreeHostImpl::RecordMainFrameTiming( diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index 5e09f0c..2c36b9d 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -1525,6 +1525,7 @@ void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer( cc::switches::kEnableBeginFrameScheduling, cc::switches::kEnableGpuBenchmarking, cc::switches::kEnableMainFrameBeforeActivation, + cc::switches::kEnableTileCompression, cc::switches::kShowCompositedLayerBorders, cc::switches::kShowFPSCounter, cc::switches::kShowLayerAnimationBounds, diff --git a/content/renderer/gpu/render_widget_compositor.cc b/content/renderer/gpu/render_widget_compositor.cc index 004addd..2d97eca 100644 --- a/content/renderer/gpu/render_widget_compositor.cc +++ b/content/renderer/gpu/render_widget_compositor.cc @@ -406,14 +406,16 @@ void RenderWidgetCompositor::Initialize(float device_scale_factor) { // low end, so always use default policy. bool use_low_memory_policy = base::SysInfo::IsLowEndDevice() && !using_synchronous_compositor; - // RGBA_4444 textures are only enabled by default for low end devices - // and are disabled for Android WebView as it doesn't support the format. - settings.renderer_settings.use_rgba_4444_textures = use_low_memory_policy; if (use_low_memory_policy) { // On low-end we want to be very carefull about killing other // apps. So initially we use 50% more memory to avoid flickering // or raster-on-demand. settings.max_memory_for_prepaint_percentage = 67; + + // RGBA_4444 textures are only enabled by default for low end devices + // and are disabled for Android WebView as it doesn't support the format. + if (!cmd->HasSwitch(switches::kDisableRGBA4444Textures)) + settings.renderer_settings.preferred_tile_format = cc::RGBA_4444; } else { // On other devices we have increased memory excessively to avoid // raster-on-demand already, so now we reserve 50% _only_ to avoid @@ -449,10 +451,14 @@ void RenderWidgetCompositor::Initialize(float device_scale_factor) { if (cmd->HasSwitch(cc::switches::kEnableBeginFrameScheduling)) settings.use_external_begin_frame_source = true; - settings.renderer_settings.use_rgba_4444_textures |= - cmd->HasSwitch(switches::kEnableRGBA4444Textures); - settings.renderer_settings.use_rgba_4444_textures &= - !cmd->HasSwitch(switches::kDisableRGBA4444Textures); + if (cmd->HasSwitch(switches::kEnableRGBA4444Textures) && + !cmd->HasSwitch(switches::kDisableRGBA4444Textures)) { + settings.renderer_settings.preferred_tile_format = cc::RGBA_4444; + } + + if (cmd->HasSwitch(cc::switches::kEnableTileCompression)) { + settings.renderer_settings.preferred_tile_format = cc::ETC1; + } if (delegate_->ForOOPIF()) { // TODO(simonhong): Apply BeginFrame scheduling for OOPIF. diff --git a/ui/compositor/compositor.cc b/ui/compositor/compositor.cc index 313e12c..e359f66 100644 --- a/ui/compositor/compositor.cc +++ b/ui/compositor/compositor.cc @@ -146,8 +146,8 @@ Compositor::Compositor(ui::ContextFactory* context_factory, settings.use_zero_copy = IsUIZeroCopyEnabled(); - settings.renderer_settings.use_rgba_4444_textures = - command_line->HasSwitch(switches::kUIEnableRGBA4444Textures); + if (command_line->HasSwitch(switches::kUIEnableRGBA4444Textures)) + settings.renderer_settings.preferred_tile_format = cc::RGBA_4444; // UI compositor always uses partial raster if not using zero-copy. Zero copy // doesn't currently support partial raster. |