Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: cc/resources/resource_provider.cc

Issue 869433003: (not for commit) Simplified multi-threaded Ganesh with lock on Flush only. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/resources/resource_provider.h ('k') | cc/resources/resource_provider_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/resources/resource_provider.h" 5 #include "cc/resources/resource_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 423
424 ResourceProvider::Child::~Child() {} 424 ResourceProvider::Child::~Child() {}
425 425
426 scoped_ptr<ResourceProvider> ResourceProvider::Create( 426 scoped_ptr<ResourceProvider> ResourceProvider::Create(
427 OutputSurface* output_surface, 427 OutputSurface* output_surface,
428 SharedBitmapManager* shared_bitmap_manager, 428 SharedBitmapManager* shared_bitmap_manager,
429 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, 429 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
430 BlockingTaskRunner* blocking_main_thread_task_runner, 430 BlockingTaskRunner* blocking_main_thread_task_runner,
431 int highp_threshold_min, 431 int highp_threshold_min,
432 bool use_rgba_4444_texture_format, 432 bool use_rgba_4444_texture_format,
433 bool use_worker_context_for_gr,
433 size_t id_allocation_chunk_size) { 434 size_t id_allocation_chunk_size) {
434 scoped_ptr<ResourceProvider> resource_provider( 435 scoped_ptr<ResourceProvider> resource_provider(new ResourceProvider(
435 new ResourceProvider(output_surface, 436 output_surface, shared_bitmap_manager, gpu_memory_buffer_manager,
436 shared_bitmap_manager, 437 blocking_main_thread_task_runner, highp_threshold_min,
437 gpu_memory_buffer_manager, 438 use_rgba_4444_texture_format, use_worker_context_for_gr,
438 blocking_main_thread_task_runner, 439 id_allocation_chunk_size));
439 highp_threshold_min,
440 use_rgba_4444_texture_format,
441 id_allocation_chunk_size));
442 440
443 if (resource_provider->ContextGL()) 441 if (resource_provider->ContextGL())
444 resource_provider->InitializeGL(); 442 resource_provider->InitializeGL();
445 else 443 else
446 resource_provider->InitializeSoftware(); 444 resource_provider->InitializeSoftware();
447 445
448 DCHECK_NE(InvalidType, resource_provider->default_resource_type()); 446 DCHECK_NE(InvalidType, resource_provider->default_resource_type());
449 return resource_provider.Pass(); 447 return resource_provider.Pass();
450 } 448 }
451 449
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( 1078 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer(
1081 size_, ToGpuMemoryBufferFormat(format_), gfx::GpuMemoryBuffer::MAP); 1079 size_, ToGpuMemoryBufferFormat(format_), gfx::GpuMemoryBuffer::MAP);
1082 gpu_memory_buffer_ = gpu_memory_buffer.release(); 1080 gpu_memory_buffer_ = gpu_memory_buffer.release();
1083 } 1081 }
1084 1082
1085 return gpu_memory_buffer_; 1083 return gpu_memory_buffer_;
1086 } 1084 }
1087 1085
1088 ResourceProvider::ScopedWriteLockGr::ScopedWriteLockGr( 1086 ResourceProvider::ScopedWriteLockGr::ScopedWriteLockGr(
1089 ResourceProvider* resource_provider, 1087 ResourceProvider* resource_provider,
1090 ResourceProvider::ResourceId resource_id, 1088 ResourceProvider::ResourceId resource_id)
1089 : resource_provider_(resource_provider),
1090 resource_(resource_provider->LockForWrite(resource_id)) {
1091 resource_provider_->LazyAllocate(resource_);
1092 }
1093
1094 ResourceProvider::ScopedWriteLockGr::~ScopedWriteLockGr() {
1095 DCHECK(thread_checker_.CalledOnValidThread());
1096 DCHECK(resource_->locked_for_write);
1097 resource_provider_->UnlockForWrite(resource_);
1098 }
1099
1100 SkSurface* ResourceProvider::ScopedWriteLockGr::GetSkSurface(
1091 bool use_distance_field_text, 1101 bool use_distance_field_text,
1092 bool can_use_lcd_text, 1102 bool can_use_lcd_text,
1093 int msaa_sample_count) 1103 int msaa_sample_count) {
1094 : resource_provider_(resource_provider), 1104 // TODO(vmiura): Update DCHECK later to match worker thread.
1095 resource_(resource_provider->LockForWrite(resource_id)) { 1105 // DCHECK(thread_checker_.CalledOnValidThread());
1096 // Create the sk_surface.
1097 DCHECK(thread_checker_.CalledOnValidThread());
1098 DCHECK(resource_->locked_for_write); 1106 DCHECK(resource_->locked_for_write);
1099 1107
1100 resource_provider_->LazyAllocate(resource_);
1101
1102 GrBackendTextureDesc desc; 1108 GrBackendTextureDesc desc;
1103 desc.fFlags = kRenderTarget_GrBackendTextureFlag; 1109 desc.fFlags = kRenderTarget_GrBackendTextureFlag;
1104 desc.fWidth = resource_->size.width(); 1110 desc.fWidth = resource_->size.width();
1105 desc.fHeight = resource_->size.height(); 1111 desc.fHeight = resource_->size.height();
1106 desc.fConfig = ToGrPixelConfig(resource_->format); 1112 desc.fConfig = ToGrPixelConfig(resource_->format);
1107 desc.fOrigin = kTopLeft_GrSurfaceOrigin; 1113 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
1108 desc.fTextureHandle = resource_->gl_id; 1114 desc.fTextureHandle = resource_->gl_id;
1109 desc.fSampleCnt = msaa_sample_count; 1115 desc.fSampleCnt = msaa_sample_count;
1110 1116
1111 class GrContext* gr_context = resource_provider_->GrContext(); 1117 class GrContext* gr_context = resource_provider_->GrContext();
1112 skia::RefPtr<GrTexture> gr_texture = 1118 skia::RefPtr<GrTexture> gr_texture =
1113 skia::AdoptRef(gr_context->wrapBackendTexture(desc)); 1119 skia::AdoptRef(gr_context->wrapBackendTexture(desc));
1114 if (gr_texture) { 1120 if (gr_texture) {
1115 uint32_t flags = use_distance_field_text 1121 uint32_t flags = use_distance_field_text
1116 ? SkSurfaceProps::kUseDistanceFieldFonts_Flag 1122 ? SkSurfaceProps::kUseDistanceFieldFonts_Flag
1117 : 0; 1123 : 0;
1118 // Use unknown pixel geometry to disable LCD text. 1124 // Use unknown pixel geometry to disable LCD text.
1119 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry); 1125 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry);
1120 if (can_use_lcd_text) { 1126 if (can_use_lcd_text) {
1121 // LegacyFontHost will get LCD text and skia figures out what type to use. 1127 // LegacyFontHost will get LCD text and skia figures out what type to use.
1122 surface_props = 1128 surface_props =
1123 SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType); 1129 SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType);
1124 } 1130 }
1125 sk_surface_ = skia::AdoptRef(SkSurface::NewRenderTargetDirect( 1131 // TODO(vmiura): I removed this reference so that we don't delete it on the
1126 gr_texture->asRenderTarget(), &surface_props)); 1132 // compositor thread later. For now, releasing it on the worker thread.
1133 // resource_->sk_surface = skia::AdoptRef(SkSurface::NewRenderTargetDirect(
1134 // gr_texture->asRenderTarget(), &surface_props));
1135 return SkSurface::NewRenderTargetDirect(gr_texture->asRenderTarget(),
1136 &surface_props);
1127 } 1137 }
1128 } 1138 return nullptr;
1129
1130 ResourceProvider::ScopedWriteLockGr::~ScopedWriteLockGr() {
1131 DCHECK(thread_checker_.CalledOnValidThread());
1132 resource_provider_->UnlockForWrite(resource_);
1133 } 1139 }
1134 1140
1135 ResourceProvider::SynchronousFence::SynchronousFence( 1141 ResourceProvider::SynchronousFence::SynchronousFence(
1136 gpu::gles2::GLES2Interface* gl) 1142 gpu::gles2::GLES2Interface* gl)
1137 : gl_(gl), has_synchronized_(true) { 1143 : gl_(gl), has_synchronized_(true) {
1138 } 1144 }
1139 1145
1140 ResourceProvider::SynchronousFence::~SynchronousFence() { 1146 ResourceProvider::SynchronousFence::~SynchronousFence() {
1141 } 1147 }
1142 1148
(...skipping 18 matching lines...) Expand all
1161 gl_->Finish(); 1167 gl_->Finish();
1162 } 1168 }
1163 1169
1164 ResourceProvider::ResourceProvider( 1170 ResourceProvider::ResourceProvider(
1165 OutputSurface* output_surface, 1171 OutputSurface* output_surface,
1166 SharedBitmapManager* shared_bitmap_manager, 1172 SharedBitmapManager* shared_bitmap_manager,
1167 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, 1173 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
1168 BlockingTaskRunner* blocking_main_thread_task_runner, 1174 BlockingTaskRunner* blocking_main_thread_task_runner,
1169 int highp_threshold_min, 1175 int highp_threshold_min,
1170 bool use_rgba_4444_texture_format, 1176 bool use_rgba_4444_texture_format,
1177 bool use_worker_context_for_gr,
1171 size_t id_allocation_chunk_size) 1178 size_t id_allocation_chunk_size)
1172 : output_surface_(output_surface), 1179 : output_surface_(output_surface),
1173 shared_bitmap_manager_(shared_bitmap_manager), 1180 shared_bitmap_manager_(shared_bitmap_manager),
1174 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), 1181 gpu_memory_buffer_manager_(gpu_memory_buffer_manager),
1175 blocking_main_thread_task_runner_(blocking_main_thread_task_runner), 1182 blocking_main_thread_task_runner_(blocking_main_thread_task_runner),
1176 lost_output_surface_(false), 1183 lost_output_surface_(false),
1177 highp_threshold_min_(highp_threshold_min), 1184 highp_threshold_min_(highp_threshold_min),
1178 next_id_(1), 1185 next_id_(1),
1179 next_child_(1), 1186 next_child_(1),
1180 default_resource_type_(InvalidType), 1187 default_resource_type_(InvalidType),
1181 use_texture_storage_ext_(false), 1188 use_texture_storage_ext_(false),
1182 use_texture_format_bgra_(false), 1189 use_texture_format_bgra_(false),
1183 use_texture_usage_hint_(false), 1190 use_texture_usage_hint_(false),
1184 use_compressed_texture_etc1_(false), 1191 use_compressed_texture_etc1_(false),
1185 yuv_resource_format_(LUMINANCE_8), 1192 yuv_resource_format_(LUMINANCE_8),
1186 max_texture_size_(0), 1193 max_texture_size_(0),
1187 best_texture_format_(RGBA_8888), 1194 best_texture_format_(RGBA_8888),
1188 use_rgba_4444_texture_format_(use_rgba_4444_texture_format), 1195 use_rgba_4444_texture_format_(use_rgba_4444_texture_format),
1196 use_worker_context_for_gr_(use_worker_context_for_gr),
1189 id_allocation_chunk_size_(id_allocation_chunk_size), 1197 id_allocation_chunk_size_(id_allocation_chunk_size),
1190 use_sync_query_(false) { 1198 use_sync_query_(false) {
1191 DCHECK(output_surface_->HasClient()); 1199 DCHECK(output_surface_->HasClient());
1192 DCHECK(id_allocation_chunk_size_); 1200 DCHECK(id_allocation_chunk_size_);
1193 } 1201 }
1194 1202
1195 void ResourceProvider::InitializeSoftware() { 1203 void ResourceProvider::InitializeSoftware() {
1196 DCHECK(thread_checker_.CalledOnValidThread()); 1204 DCHECK(thread_checker_.CalledOnValidThread());
1197 DCHECK_NE(Bitmap, default_resource_type_); 1205 DCHECK_NE(Bitmap, default_resource_type_);
1198 1206
(...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after
2129 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit); 2137 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit);
2130 return active_unit; 2138 return active_unit;
2131 } 2139 }
2132 2140
2133 GLES2Interface* ResourceProvider::ContextGL() const { 2141 GLES2Interface* ResourceProvider::ContextGL() const {
2134 ContextProvider* context_provider = output_surface_->context_provider(); 2142 ContextProvider* context_provider = output_surface_->context_provider();
2135 return context_provider ? context_provider->ContextGL() : NULL; 2143 return context_provider ? context_provider->ContextGL() : NULL;
2136 } 2144 }
2137 2145
2138 class GrContext* ResourceProvider::GrContext() const { 2146 class GrContext* ResourceProvider::GrContext() const {
2139 ContextProvider* context_provider = output_surface_->context_provider(); 2147 ContextProvider* context_provider =
2148 use_worker_context_for_gr_ ? output_surface_->worker_context_provider()
2149 : output_surface_->context_provider();
2140 return context_provider ? context_provider->GrContext() : NULL; 2150 return context_provider ? context_provider->GrContext() : NULL;
2141 } 2151 }
2142 2152
2143 } // namespace cc 2153 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_provider.h ('k') | cc/resources/resource_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698