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

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

Issue 375303002: cc: Refactor ResourceProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixing typing error in build.gn Created 6 years, 5 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/scoped_gpu_raster.h » ('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 997 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 1008
1009 base::TimeDelta upload_one_texture_time = 1009 base::TimeDelta upload_one_texture_time =
1010 base::TimeDelta::FromMicroseconds( 1010 base::TimeDelta::FromMicroseconds(
1011 base::Time::kMicrosecondsPerSecond * kTextureUploadTickRate) / 1011 base::Time::kMicrosecondsPerSecond * kTextureUploadTickRate) /
1012 uploads_per_tick; 1012 uploads_per_tick;
1013 1013
1014 size_t total_uploads = NumBlockingUploads() + uploads_per_tick; 1014 size_t total_uploads = NumBlockingUploads() + uploads_per_tick;
1015 return gfx::FrameTime::Now() + upload_one_texture_time * total_uploads; 1015 return gfx::FrameTime::Now() + upload_one_texture_time * total_uploads;
1016 } 1016 }
1017 1017
1018 void ResourceProvider::Flush() {
1019 DCHECK(thread_checker_.CalledOnValidThread());
1020 GLES2Interface* gl = ContextGL();
1021 if (gl)
1022 gl->Flush();
1023 }
1024
1025 void ResourceProvider::Finish() {
1026 DCHECK(thread_checker_.CalledOnValidThread());
1027 GLES2Interface* gl = ContextGL();
1028 if (gl)
1029 gl->Finish();
1030 }
1031
1032 bool ResourceProvider::ShallowFlushIfSupported() {
1033 DCHECK(thread_checker_.CalledOnValidThread());
1034 GLES2Interface* gl = ContextGL();
1035 if (!gl)
1036 return false;
1037
1038 gl->ShallowFlushCHROMIUM();
1039 return true;
1040 }
1041
1042 ResourceProvider::Resource* ResourceProvider::GetResource(ResourceId id) { 1018 ResourceProvider::Resource* ResourceProvider::GetResource(ResourceId id) {
1043 DCHECK(thread_checker_.CalledOnValidThread()); 1019 DCHECK(thread_checker_.CalledOnValidThread());
1044 ResourceMap::iterator it = resources_.find(id); 1020 ResourceMap::iterator it = resources_.find(id);
1045 CHECK(it != resources_.end()); 1021 CHECK(it != resources_.end());
1046 return &it->second; 1022 return &it->second;
1047 } 1023 }
1048 1024
1049 const ResourceProvider::Resource* ResourceProvider::LockForRead(ResourceId id) { 1025 const ResourceProvider::Resource* ResourceProvider::LockForRead(ResourceId id) {
1050 Resource* resource = GetResource(id); 1026 Resource* resource = GetResource(id);
1051 DCHECK(!resource->locked_for_write || 1027 DCHECK(!resource->locked_for_write ||
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 ResourceProvider::PopulateSkBitmapWithResource( 1198 ResourceProvider::PopulateSkBitmapWithResource(
1223 &sk_bitmap_, resource_provider->LockForWrite(resource_id)); 1199 &sk_bitmap_, resource_provider->LockForWrite(resource_id));
1224 DCHECK(valid()); 1200 DCHECK(valid());
1225 sk_canvas_.reset(new SkCanvas(sk_bitmap_)); 1201 sk_canvas_.reset(new SkCanvas(sk_bitmap_));
1226 } 1202 }
1227 1203
1228 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { 1204 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() {
1229 resource_provider_->UnlockForWrite(resource_id_); 1205 resource_provider_->UnlockForWrite(resource_id_);
1230 } 1206 }
1231 1207
1232 ResourceProvider::ScopedGpuRaster::ScopedGpuRaster(
1233 ResourceProvider* resource_provider)
1234 : resource_provider_(resource_provider) {
1235 resource_provider_->BeginGpuRaster();
1236 }
1237
1238 ResourceProvider::ScopedGpuRaster::~ScopedGpuRaster() {
1239 resource_provider_->EndGpuRaster();
1240 }
1241
1242 ResourceProvider::ResourceProvider(OutputSurface* output_surface, 1208 ResourceProvider::ResourceProvider(OutputSurface* output_surface,
1243 SharedBitmapManager* shared_bitmap_manager, 1209 SharedBitmapManager* shared_bitmap_manager,
1244 int highp_threshold_min, 1210 int highp_threshold_min,
1245 bool use_rgba_4444_texture_format, 1211 bool use_rgba_4444_texture_format,
1246 size_t id_allocation_chunk_size, 1212 size_t id_allocation_chunk_size,
1247 bool use_distance_field_text) 1213 bool use_distance_field_text)
1248 : output_surface_(output_surface), 1214 : output_surface_(output_surface),
1249 shared_bitmap_manager_(shared_bitmap_manager), 1215 shared_bitmap_manager_(shared_bitmap_manager),
1250 lost_output_surface_(false), 1216 lost_output_surface_(false),
1251 highp_threshold_min_(highp_threshold_min), 1217 highp_threshold_min_(highp_threshold_min),
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 for (ResourceMap::const_iterator itr = resources_.begin(); 1290 for (ResourceMap::const_iterator itr = resources_.begin();
1325 itr != resources_.end(); 1291 itr != resources_.end();
1326 ++itr) { 1292 ++itr) {
1327 DCHECK_NE(GLTexture, itr->second.type); 1293 DCHECK_NE(GLTexture, itr->second.type);
1328 } 1294 }
1329 #endif // DCHECK_IS_ON 1295 #endif // DCHECK_IS_ON
1330 1296
1331 texture_uploader_.reset(); 1297 texture_uploader_.reset();
1332 texture_id_allocator_.reset(); 1298 texture_id_allocator_.reset();
1333 buffer_id_allocator_.reset(); 1299 buffer_id_allocator_.reset();
1334 Finish(); 1300 gl->Finish();
1335 } 1301 }
1336 1302
1337 int ResourceProvider::CreateChild(const ReturnCallback& return_callback) { 1303 int ResourceProvider::CreateChild(const ReturnCallback& return_callback) {
1338 DCHECK(thread_checker_.CalledOnValidThread()); 1304 DCHECK(thread_checker_.CalledOnValidThread());
1339 1305
1340 Child child_info; 1306 Child child_info;
1341 child_info.return_callback = return_callback; 1307 child_info.return_callback = return_callback;
1342 1308
1343 int child = next_child_++; 1309 int child = next_child_++;
1344 children_[child] = child_info; 1310 children_[child] = child_info;
(...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after
2276 GLES2Interface* ResourceProvider::ContextGL() const { 2242 GLES2Interface* ResourceProvider::ContextGL() const {
2277 ContextProvider* context_provider = output_surface_->context_provider(); 2243 ContextProvider* context_provider = output_surface_->context_provider();
2278 return context_provider ? context_provider->ContextGL() : NULL; 2244 return context_provider ? context_provider->ContextGL() : NULL;
2279 } 2245 }
2280 2246
2281 class GrContext* ResourceProvider::GrContext() const { 2247 class GrContext* ResourceProvider::GrContext() const {
2282 ContextProvider* context_provider = output_surface_->context_provider(); 2248 ContextProvider* context_provider = output_surface_->context_provider();
2283 return context_provider ? context_provider->GrContext() : NULL; 2249 return context_provider ? context_provider->GrContext() : NULL;
2284 } 2250 }
2285 2251
2286 void ResourceProvider::BeginGpuRaster() {
2287 GLES2Interface* gl = ContextGL();
2288 DCHECK(gl);
2289
2290 // TODO(alokp): Use a trace macro to push/pop markers.
2291 // Using push/pop functions directly incurs cost to evaluate function
2292 // arguments even when tracing is disabled.
2293 gl->PushGroupMarkerEXT(0, "GpuRasterization");
2294
2295 class GrContext* gr_context = GrContext();
2296 if (gr_context)
2297 gr_context->resetContext();
2298 }
2299
2300 void ResourceProvider::EndGpuRaster() {
2301 GLES2Interface* gl = ContextGL();
2302 DCHECK(gl);
2303
2304 class GrContext* gr_context = GrContext();
2305 if (gr_context)
2306 gr_context->flush();
2307
2308 // TODO(alokp): Use a trace macro to push/pop markers.
2309 // Using push/pop functions directly incurs cost to evaluate function
2310 // arguments even when tracing is disabled.
2311 gl->PopGroupMarkerEXT();
2312 }
2313
2314 } // namespace cc 2252 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_provider.h ('k') | cc/resources/scoped_gpu_raster.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698