Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 ResourceProvider::RasterBuffer::~RasterBuffer() {} | 382 ResourceProvider::RasterBuffer::~RasterBuffer() {} |
| 383 | 383 |
| 384 SkCanvas* ResourceProvider::RasterBuffer::LockForWrite() { | 384 SkCanvas* ResourceProvider::RasterBuffer::LockForWrite() { |
| 385 DCHECK(!locked_canvas_); | 385 DCHECK(!locked_canvas_); |
| 386 | 386 |
| 387 locked_canvas_ = DoLockForWrite(); | 387 locked_canvas_ = DoLockForWrite(); |
| 388 canvas_save_count_ = locked_canvas_ ? locked_canvas_->save() : 0; | 388 canvas_save_count_ = locked_canvas_ ? locked_canvas_->save() : 0; |
| 389 return locked_canvas_; | 389 return locked_canvas_; |
| 390 } | 390 } |
| 391 | 391 |
| 392 void ResourceProvider::RasterBuffer::UnlockForWrite() { | 392 bool ResourceProvider::RasterBuffer::UnlockForWrite() { |
| 393 if (locked_canvas_) { | 393 if (locked_canvas_) { |
| 394 locked_canvas_->restoreToCount(canvas_save_count_); | 394 locked_canvas_->restoreToCount(canvas_save_count_); |
| 395 locked_canvas_ = NULL; | 395 locked_canvas_ = NULL; |
| 396 } | 396 } |
| 397 DoUnlockForWrite(); | 397 return DoUnlockForWrite(); |
| 398 } | 398 } |
| 399 | 399 |
| 400 ResourceProvider::DirectRasterBuffer::DirectRasterBuffer( | 400 ResourceProvider::DirectRasterBuffer::DirectRasterBuffer( |
| 401 const Resource* resource, | 401 const Resource* resource, |
| 402 ResourceProvider* resource_provider) | 402 ResourceProvider* resource_provider) |
| 403 : RasterBuffer(resource, resource_provider) {} | 403 : RasterBuffer(resource, resource_provider), surface_generation_id_(0u) {} |
| 404 | 404 |
| 405 ResourceProvider::DirectRasterBuffer::~DirectRasterBuffer() {} | 405 ResourceProvider::DirectRasterBuffer::~DirectRasterBuffer() {} |
| 406 | 406 |
| 407 SkCanvas* ResourceProvider::DirectRasterBuffer::DoLockForWrite() { | 407 SkCanvas* ResourceProvider::DirectRasterBuffer::DoLockForWrite() { |
| 408 if (!surface_) | 408 if (!surface_) |
| 409 surface_ = CreateSurface(); | 409 surface_ = CreateSurface(); |
| 410 surface_generation_id_ = surface_ ? surface_->generationID() : 0u; | |
| 410 return surface_ ? surface_->getCanvas() : NULL; | 411 return surface_ ? surface_->getCanvas() : NULL; |
| 411 } | 412 } |
| 412 | 413 |
| 413 void ResourceProvider::DirectRasterBuffer::DoUnlockForWrite() {} | 414 bool ResourceProvider::DirectRasterBuffer::DoUnlockForWrite() { |
| 415 return surface_ ? surface_generation_id_ != surface_->generationID() : false; | |
| 416 } | |
| 414 | 417 |
| 415 skia::RefPtr<SkSurface> ResourceProvider::DirectRasterBuffer::CreateSurface() { | 418 skia::RefPtr<SkSurface> ResourceProvider::DirectRasterBuffer::CreateSurface() { |
| 416 skia::RefPtr<SkSurface> surface; | 419 skia::RefPtr<SkSurface> surface; |
| 417 switch (resource()->type) { | 420 switch (resource()->type) { |
| 418 case GLTexture: { | 421 case GLTexture: { |
| 419 DCHECK(resource()->gl_id); | 422 DCHECK(resource()->gl_id); |
| 420 class GrContext* gr_context = resource_provider()->GrContext(); | 423 class GrContext* gr_context = resource_provider()->GrContext(); |
| 421 if (gr_context) { | 424 if (gr_context) { |
| 422 GrBackendTextureDesc desc; | 425 GrBackendTextureDesc desc; |
| 423 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 426 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 446 } | 449 } |
| 447 default: | 450 default: |
| 448 NOTREACHED(); | 451 NOTREACHED(); |
| 449 } | 452 } |
| 450 return surface; | 453 return surface; |
| 451 } | 454 } |
| 452 | 455 |
| 453 ResourceProvider::BitmapRasterBuffer::BitmapRasterBuffer( | 456 ResourceProvider::BitmapRasterBuffer::BitmapRasterBuffer( |
| 454 const Resource* resource, | 457 const Resource* resource, |
| 455 ResourceProvider* resource_provider) | 458 ResourceProvider* resource_provider) |
| 456 : RasterBuffer(resource, resource_provider), mapped_buffer_(NULL) {} | 459 : RasterBuffer(resource, resource_provider), |
| 460 mapped_buffer_(NULL), | |
| 461 raster_bitmap_generation_id_(0u) {} | |
| 457 | 462 |
| 458 ResourceProvider::BitmapRasterBuffer::~BitmapRasterBuffer() {} | 463 ResourceProvider::BitmapRasterBuffer::~BitmapRasterBuffer() {} |
| 459 | 464 |
| 460 SkCanvas* ResourceProvider::BitmapRasterBuffer::DoLockForWrite() { | 465 SkCanvas* ResourceProvider::BitmapRasterBuffer::DoLockForWrite() { |
| 461 DCHECK(!mapped_buffer_); | 466 DCHECK(!mapped_buffer_); |
| 462 DCHECK(!raster_canvas_); | 467 DCHECK(!raster_canvas_); |
| 463 | 468 |
| 464 int stride = 0; | 469 int stride = 0; |
| 465 mapped_buffer_ = MapBuffer(&stride); | 470 mapped_buffer_ = MapBuffer(&stride); |
| 466 if (!mapped_buffer_) | 471 if (!mapped_buffer_) |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 485 break; | 490 break; |
| 486 case LUMINANCE_8: | 491 case LUMINANCE_8: |
| 487 case RGB_565: | 492 case RGB_565: |
| 488 case ETC1: | 493 case ETC1: |
| 489 NOTREACHED(); | 494 NOTREACHED(); |
| 490 break; | 495 break; |
| 491 } | 496 } |
| 492 skia::RefPtr<SkBitmapDevice> device = | 497 skia::RefPtr<SkBitmapDevice> device = |
| 493 skia::AdoptRef(new SkBitmapDevice(raster_bitmap_)); | 498 skia::AdoptRef(new SkBitmapDevice(raster_bitmap_)); |
| 494 raster_canvas_ = skia::AdoptRef(new SkCanvas(device.get())); | 499 raster_canvas_ = skia::AdoptRef(new SkCanvas(device.get())); |
| 500 raster_bitmap_generation_id_ = raster_bitmap_.getGenerationID(); | |
| 495 return raster_canvas_.get(); | 501 return raster_canvas_.get(); |
| 496 } | 502 } |
| 497 | 503 |
| 498 void ResourceProvider::BitmapRasterBuffer::DoUnlockForWrite() { | 504 bool ResourceProvider::BitmapRasterBuffer::DoUnlockForWrite() { |
| 499 raster_canvas_.clear(); | 505 raster_canvas_.clear(); |
| 500 | 506 |
| 501 SkBitmap::Config buffer_config = SkBitmapConfig(resource()->format); | 507 bool raster_bitmap_changed = |
| 502 if (mapped_buffer_ && (buffer_config != raster_bitmap_.config())) | 508 raster_bitmap_generation_id_ != raster_bitmap_.getGenerationID(); |
|
vmpstr
2014/02/19 00:49:31
Is this like a good check? According to skia heade
reveman
2014/02/19 01:41:13
Done.
| |
| 503 CopyBitmap(raster_bitmap_, mapped_buffer_, buffer_config); | 509 |
| 510 if (raster_bitmap_changed) { | |
| 511 SkBitmap::Config buffer_config = SkBitmapConfig(resource()->format); | |
| 512 if (mapped_buffer_ && (buffer_config != raster_bitmap_.config())) | |
| 513 CopyBitmap(raster_bitmap_, mapped_buffer_, buffer_config); | |
| 514 } | |
| 504 raster_bitmap_.reset(); | 515 raster_bitmap_.reset(); |
| 505 | 516 |
| 506 UnmapBuffer(); | 517 UnmapBuffer(); |
| 507 mapped_buffer_ = NULL; | 518 mapped_buffer_ = NULL; |
| 519 return raster_bitmap_changed; | |
| 508 } | 520 } |
| 509 | 521 |
| 510 ResourceProvider::ImageRasterBuffer::ImageRasterBuffer( | 522 ResourceProvider::ImageRasterBuffer::ImageRasterBuffer( |
| 511 const Resource* resource, | 523 const Resource* resource, |
| 512 ResourceProvider* resource_provider) | 524 ResourceProvider* resource_provider) |
| 513 : BitmapRasterBuffer(resource, resource_provider) {} | 525 : BitmapRasterBuffer(resource, resource_provider) {} |
| 514 | 526 |
| 515 ResourceProvider::ImageRasterBuffer::~ImageRasterBuffer() {} | 527 ResourceProvider::ImageRasterBuffer::~ImageRasterBuffer() {} |
| 516 | 528 |
| 517 uint8_t* ResourceProvider::ImageRasterBuffer::MapBuffer(int* stride) { | 529 uint8_t* ResourceProvider::ImageRasterBuffer::MapBuffer(int* stride) { |
| (...skipping 1212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1730 resource->pixel_raster_buffer.reset(); | 1742 resource->pixel_raster_buffer.reset(); |
| 1731 ReleasePixelBuffer(resource); | 1743 ReleasePixelBuffer(resource); |
| 1732 } | 1744 } |
| 1733 | 1745 |
| 1734 SkCanvas* ResourceProvider::MapPixelRasterBuffer(ResourceId id) { | 1746 SkCanvas* ResourceProvider::MapPixelRasterBuffer(ResourceId id) { |
| 1735 Resource* resource = GetResource(id); | 1747 Resource* resource = GetResource(id); |
| 1736 DCHECK(resource->pixel_raster_buffer.get()); | 1748 DCHECK(resource->pixel_raster_buffer.get()); |
| 1737 return resource->pixel_raster_buffer->LockForWrite(); | 1749 return resource->pixel_raster_buffer->LockForWrite(); |
| 1738 } | 1750 } |
| 1739 | 1751 |
| 1740 void ResourceProvider::UnmapPixelRasterBuffer(ResourceId id) { | 1752 bool ResourceProvider::UnmapPixelRasterBuffer(ResourceId id) { |
| 1741 Resource* resource = GetResource(id); | 1753 Resource* resource = GetResource(id); |
| 1742 DCHECK(resource->pixel_raster_buffer.get()); | 1754 DCHECK(resource->pixel_raster_buffer.get()); |
| 1743 resource->pixel_raster_buffer->UnlockForWrite(); | 1755 return resource->pixel_raster_buffer->UnlockForWrite(); |
| 1744 } | 1756 } |
| 1745 | 1757 |
| 1746 void ResourceProvider::AcquirePixelBuffer(Resource* resource) { | 1758 void ResourceProvider::AcquirePixelBuffer(Resource* resource) { |
| 1747 DCHECK(resource->origin == Resource::Internal); | 1759 DCHECK(resource->origin == Resource::Internal); |
| 1748 DCHECK_EQ(resource->exported_count, 0); | 1760 DCHECK_EQ(resource->exported_count, 0); |
| 1749 DCHECK(!resource->image_id); | 1761 DCHECK(!resource->image_id); |
| 1750 DCHECK_NE(ETC1, resource->format); | 1762 DCHECK_NE(ETC1, resource->format); |
| 1751 | 1763 |
| 1752 if (resource->type == GLTexture) { | 1764 if (resource->type == GLTexture) { |
| 1753 GLES2Interface* gl = ContextGL(); | 1765 GLES2Interface* gl = ContextGL(); |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2160 ContextProvider* context_provider = output_surface_->context_provider(); | 2172 ContextProvider* context_provider = output_surface_->context_provider(); |
| 2161 return context_provider ? context_provider->ContextGL() : NULL; | 2173 return context_provider ? context_provider->ContextGL() : NULL; |
| 2162 } | 2174 } |
| 2163 | 2175 |
| 2164 class GrContext* ResourceProvider::GrContext() const { | 2176 class GrContext* ResourceProvider::GrContext() const { |
| 2165 ContextProvider* context_provider = output_surface_->context_provider(); | 2177 ContextProvider* context_provider = output_surface_->context_provider(); |
| 2166 return context_provider ? context_provider->GrContext() : NULL; | 2178 return context_provider ? context_provider->GrContext() : NULL; |
| 2167 } | 2179 } |
| 2168 | 2180 |
| 2169 } // namespace cc | 2181 } // namespace cc |
| OLD | NEW |