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

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

Issue 184573002: Use MSAA in GPU rasterization if Skia suggests it (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: the hunk, actually Created 6 years, 9 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') | chrome/app/generated_resources.grd » ('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"
11 #include "base/debug/trace_event.h" 11 #include "base/debug/trace_event.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "cc/base/switches.h"
15 #include "cc/base/util.h" 16 #include "cc/base/util.h"
16 #include "cc/output/gl_renderer.h" // For the GLC() macro. 17 #include "cc/output/gl_renderer.h" // For the GLC() macro.
17 #include "cc/resources/platform_color.h" 18 #include "cc/resources/platform_color.h"
18 #include "cc/resources/returned_resource.h" 19 #include "cc/resources/returned_resource.h"
19 #include "cc/resources/shared_bitmap_manager.h" 20 #include "cc/resources/shared_bitmap_manager.h"
20 #include "cc/resources/texture_uploader.h" 21 #include "cc/resources/texture_uploader.h"
21 #include "cc/resources/transferable_resource.h" 22 #include "cc/resources/transferable_resource.h"
22 #include "gpu/GLES2/gl2extchromium.h" 23 #include "gpu/GLES2/gl2extchromium.h"
23 #include "gpu/command_buffer/client/gles2_interface.h" 24 #include "gpu/command_buffer/client/gles2_interface.h"
24 #include "third_party/khronos/GLES2/gl2.h" 25 #include "third_party/khronos/GLES2/gl2.h"
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 ResourceProvider::DirectRasterBuffer::~DirectRasterBuffer() {} 406 ResourceProvider::DirectRasterBuffer::~DirectRasterBuffer() {}
406 407
407 SkCanvas* ResourceProvider::DirectRasterBuffer::DoLockForWrite() { 408 SkCanvas* ResourceProvider::DirectRasterBuffer::DoLockForWrite() {
408 if (!surface_) 409 if (!surface_)
409 surface_ = CreateSurface(); 410 surface_ = CreateSurface();
410 surface_generation_id_ = surface_ ? surface_->generationID() : 0u; 411 surface_generation_id_ = surface_ ? surface_->generationID() : 0u;
411 return surface_ ? surface_->getCanvas() : NULL; 412 return surface_ ? surface_->getCanvas() : NULL;
412 } 413 }
413 414
414 bool ResourceProvider::DirectRasterBuffer::DoUnlockForWrite() { 415 bool ResourceProvider::DirectRasterBuffer::DoUnlockForWrite() {
415 // generationID returns a non-zero, unique value corresponding to the content 416 if (surface_) {
416 // of surface. Hence, a change since DoLockForWrite was called means the 417 // generationID returns a non-zero, unique value corresponding to the
417 // surface has changed. 418 // content of surface. Hence, a change since DoLockForWrite was called
418 return surface_ ? surface_generation_id_ != surface_->generationID() : false; 419 // means the surface has changed.
420 if (surface_generation_id_ != surface_->generationID()) {
421 // Flush any pending or deferred work canvas or device might have. This
422 // also resolves the potential MSAA.
423 surface_->getCanvas()->flush();
424 return true;
425 }
426 }
427 return false;
419 } 428 }
420 429
421 skia::RefPtr<SkSurface> ResourceProvider::DirectRasterBuffer::CreateSurface() { 430 skia::RefPtr<SkSurface> ResourceProvider::DirectRasterBuffer::CreateSurface() {
422 skia::RefPtr<SkSurface> surface; 431 skia::RefPtr<SkSurface> surface;
423 switch (resource()->type) { 432 switch (resource()->type) {
424 case GLTexture: { 433 case GLTexture: {
425 DCHECK(resource()->gl_id); 434 DCHECK(resource()->gl_id);
426 class GrContext* gr_context = resource_provider()->GrContext(); 435 class GrContext* gr_context = resource_provider()->GrContext();
427 if (gr_context) { 436 if (gr_context) {
428 GrBackendTextureDesc desc; 437 GrBackendTextureDesc desc;
429 desc.fFlags = kRenderTarget_GrBackendTextureFlag; 438 desc.fFlags = kRenderTarget_GrBackendTextureFlag;
430 desc.fWidth = resource()->size.width(); 439 desc.fWidth = resource()->size.width();
431 desc.fHeight = resource()->size.height(); 440 desc.fHeight = resource()->size.height();
432 desc.fConfig = ToGrPixelConfig(resource()->format); 441 desc.fConfig = ToGrPixelConfig(resource()->format);
433 desc.fOrigin = kTopLeft_GrSurfaceOrigin; 442 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
434 desc.fTextureHandle = resource()->gl_id; 443 desc.fTextureHandle = resource()->gl_id;
444 desc.fSampleCnt = resource_provider()->num_gpu_rasterization_samples();
nduca 2014/03/01 22:02:28 i think it woudl be better if you obtained this fr
435 skia::RefPtr<GrTexture> gr_texture = 445 skia::RefPtr<GrTexture> gr_texture =
436 skia::AdoptRef(gr_context->wrapBackendTexture(desc)); 446 skia::AdoptRef(gr_context->wrapBackendTexture(desc));
437 surface = skia::AdoptRef( 447 surface = skia::AdoptRef(
438 SkSurface::NewRenderTargetDirect(gr_texture->asRenderTarget())); 448 SkSurface::NewRenderTargetDirect(gr_texture->asRenderTarget()));
439 } 449 }
440 break; 450 break;
441 } 451 }
442 case Bitmap: { 452 case Bitmap: {
443 DCHECK(resource()->pixels); 453 DCHECK(resource()->pixels);
444 DCHECK_EQ(RGBA_8888, resource()->format); 454 DCHECK_EQ(RGBA_8888, resource()->format);
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 lost_output_surface_(false), 1220 lost_output_surface_(false),
1211 highp_threshold_min_(highp_threshold_min), 1221 highp_threshold_min_(highp_threshold_min),
1212 next_id_(1), 1222 next_id_(1),
1213 next_child_(1), 1223 next_child_(1),
1214 default_resource_type_(InvalidType), 1224 default_resource_type_(InvalidType),
1215 use_texture_storage_ext_(false), 1225 use_texture_storage_ext_(false),
1216 use_texture_usage_hint_(false), 1226 use_texture_usage_hint_(false),
1217 use_compressed_texture_etc1_(false), 1227 use_compressed_texture_etc1_(false),
1218 max_texture_size_(0), 1228 max_texture_size_(0),
1219 best_texture_format_(RGBA_8888), 1229 best_texture_format_(RGBA_8888),
1230 num_gpu_rasterization_samples_(0),
1220 use_rgba_4444_texture_format_(use_rgba_4444_texture_format), 1231 use_rgba_4444_texture_format_(use_rgba_4444_texture_format),
1221 id_allocation_chunk_size_(id_allocation_chunk_size) { 1232 id_allocation_chunk_size_(id_allocation_chunk_size) {
1222 DCHECK(output_surface_->HasClient()); 1233 DCHECK(output_surface_->HasClient());
1223 DCHECK(id_allocation_chunk_size_); 1234 DCHECK(id_allocation_chunk_size_);
1224 } 1235 }
1225 1236
1226 void ResourceProvider::InitializeSoftware() { 1237 void ResourceProvider::InitializeSoftware() {
1227 DCHECK(thread_checker_.CalledOnValidThread()); 1238 DCHECK(thread_checker_.CalledOnValidThread());
1228 DCHECK_NE(Bitmap, default_resource_type_); 1239 DCHECK_NE(Bitmap, default_resource_type_);
1229 1240
(...skipping 23 matching lines...) Expand all
1253 use_compressed_texture_etc1_ = caps.gpu.texture_format_etc1; 1264 use_compressed_texture_etc1_ = caps.gpu.texture_format_etc1;
1254 1265
1255 GLES2Interface* gl = ContextGL(); 1266 GLES2Interface* gl = ContextGL();
1256 DCHECK(gl); 1267 DCHECK(gl);
1257 1268
1258 texture_uploader_ = TextureUploader::Create(gl); 1269 texture_uploader_ = TextureUploader::Create(gl);
1259 max_texture_size_ = 0; // Context expects cleared value. 1270 max_texture_size_ = 0; // Context expects cleared value.
1260 GLC(gl, gl->GetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size_)); 1271 GLC(gl, gl->GetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size_));
1261 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra); 1272 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra);
1262 1273
1274 switch (switches::GetGpuRasterizationType()) {
1275 default:
1276 NOTREACHED();
1277 case switches::GpuRasterizationGpu:
1278 num_gpu_rasterization_samples_ = 0;
1279 break;
1280 case switches::GpuRasterizationMsaa4:
1281 num_gpu_rasterization_samples_ = 4;
1282 break;
1283 case switches::GpuRasterizationMsaa16:
1284 num_gpu_rasterization_samples_ = 16;
1285 break;
1286 }
1287
1263 texture_id_allocator_.reset( 1288 texture_id_allocator_.reset(
1264 new TextureIdAllocator(gl, id_allocation_chunk_size_)); 1289 new TextureIdAllocator(gl, id_allocation_chunk_size_));
1265 buffer_id_allocator_.reset( 1290 buffer_id_allocator_.reset(
1266 new BufferIdAllocator(gl, id_allocation_chunk_size_)); 1291 new BufferIdAllocator(gl, id_allocation_chunk_size_));
1267 1292
1268 return true; 1293 return true;
1269 } 1294 }
1270 1295
1271 void ResourceProvider::CleanUpGLIfNeeded() { 1296 void ResourceProvider::CleanUpGLIfNeeded() {
1272 GLES2Interface* gl = ContextGL(); 1297 GLES2Interface* gl = ContextGL();
(...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after
2181 ContextProvider* context_provider = output_surface_->context_provider(); 2206 ContextProvider* context_provider = output_surface_->context_provider();
2182 return context_provider ? context_provider->ContextGL() : NULL; 2207 return context_provider ? context_provider->ContextGL() : NULL;
2183 } 2208 }
2184 2209
2185 class GrContext* ResourceProvider::GrContext() const { 2210 class GrContext* ResourceProvider::GrContext() const {
2186 ContextProvider* context_provider = output_surface_->context_provider(); 2211 ContextProvider* context_provider = output_surface_->context_provider();
2187 return context_provider ? context_provider->GrContext() : NULL; 2212 return context_provider ? context_provider->GrContext() : NULL;
2188 } 2213 }
2189 2214
2190 } // namespace cc 2215 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_provider.h ('k') | chrome/app/generated_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698