| 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 bool ResourceProvider::RasterBuffer::UnlockForWrite() { | 392 void 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 return DoUnlockForWrite(); | 397 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), surface_generation_id_(0u) {} | 403 : RasterBuffer(resource, resource_provider) {} |
| 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; | |
| 411 return surface_ ? surface_->getCanvas() : NULL; | 410 return surface_ ? surface_->getCanvas() : NULL; |
| 412 } | 411 } |
| 413 | 412 |
| 414 bool ResourceProvider::DirectRasterBuffer::DoUnlockForWrite() { | 413 void ResourceProvider::DirectRasterBuffer::DoUnlockForWrite() {} |
| 415 // generationID returns a non-zero, unique value corresponding to the content | |
| 416 // of surface. Hence, a change since DoLockForWrite was called means the | |
| 417 // surface has changed. | |
| 418 return surface_ ? surface_generation_id_ != surface_->generationID() : false; | |
| 419 } | |
| 420 | 414 |
| 421 skia::RefPtr<SkSurface> ResourceProvider::DirectRasterBuffer::CreateSurface() { | 415 skia::RefPtr<SkSurface> ResourceProvider::DirectRasterBuffer::CreateSurface() { |
| 422 skia::RefPtr<SkSurface> surface; | 416 skia::RefPtr<SkSurface> surface; |
| 423 switch (resource()->type) { | 417 switch (resource()->type) { |
| 424 case GLTexture: { | 418 case GLTexture: { |
| 425 DCHECK(resource()->gl_id); | 419 DCHECK(resource()->gl_id); |
| 426 class GrContext* gr_context = resource_provider()->GrContext(); | 420 class GrContext* gr_context = resource_provider()->GrContext(); |
| 427 if (gr_context) { | 421 if (gr_context) { |
| 428 GrBackendTextureDesc desc; | 422 GrBackendTextureDesc desc; |
| 429 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 423 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 452 } | 446 } |
| 453 default: | 447 default: |
| 454 NOTREACHED(); | 448 NOTREACHED(); |
| 455 } | 449 } |
| 456 return surface; | 450 return surface; |
| 457 } | 451 } |
| 458 | 452 |
| 459 ResourceProvider::BitmapRasterBuffer::BitmapRasterBuffer( | 453 ResourceProvider::BitmapRasterBuffer::BitmapRasterBuffer( |
| 460 const Resource* resource, | 454 const Resource* resource, |
| 461 ResourceProvider* resource_provider) | 455 ResourceProvider* resource_provider) |
| 462 : RasterBuffer(resource, resource_provider), | 456 : RasterBuffer(resource, resource_provider), mapped_buffer_(NULL) {} |
| 463 mapped_buffer_(NULL), | |
| 464 raster_bitmap_generation_id_(0u) {} | |
| 465 | 457 |
| 466 ResourceProvider::BitmapRasterBuffer::~BitmapRasterBuffer() {} | 458 ResourceProvider::BitmapRasterBuffer::~BitmapRasterBuffer() {} |
| 467 | 459 |
| 468 SkCanvas* ResourceProvider::BitmapRasterBuffer::DoLockForWrite() { | 460 SkCanvas* ResourceProvider::BitmapRasterBuffer::DoLockForWrite() { |
| 469 DCHECK(!mapped_buffer_); | 461 DCHECK(!mapped_buffer_); |
| 470 DCHECK(!raster_canvas_); | 462 DCHECK(!raster_canvas_); |
| 471 | 463 |
| 472 int stride = 0; | 464 int stride = 0; |
| 473 mapped_buffer_ = MapBuffer(&stride); | 465 mapped_buffer_ = MapBuffer(&stride); |
| 474 if (!mapped_buffer_) | 466 if (!mapped_buffer_) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 493 break; | 485 break; |
| 494 case LUMINANCE_8: | 486 case LUMINANCE_8: |
| 495 case RGB_565: | 487 case RGB_565: |
| 496 case ETC1: | 488 case ETC1: |
| 497 NOTREACHED(); | 489 NOTREACHED(); |
| 498 break; | 490 break; |
| 499 } | 491 } |
| 500 skia::RefPtr<SkBitmapDevice> device = | 492 skia::RefPtr<SkBitmapDevice> device = |
| 501 skia::AdoptRef(new SkBitmapDevice(raster_bitmap_)); | 493 skia::AdoptRef(new SkBitmapDevice(raster_bitmap_)); |
| 502 raster_canvas_ = skia::AdoptRef(new SkCanvas(device.get())); | 494 raster_canvas_ = skia::AdoptRef(new SkCanvas(device.get())); |
| 503 raster_bitmap_generation_id_ = raster_bitmap_.getGenerationID(); | |
| 504 return raster_canvas_.get(); | 495 return raster_canvas_.get(); |
| 505 } | 496 } |
| 506 | 497 |
| 507 bool ResourceProvider::BitmapRasterBuffer::DoUnlockForWrite() { | 498 void ResourceProvider::BitmapRasterBuffer::DoUnlockForWrite() { |
| 508 raster_canvas_.clear(); | 499 raster_canvas_.clear(); |
| 509 | 500 |
| 510 // getGenerationID returns a non-zero, unique value corresponding to the | 501 SkBitmap::Config buffer_config = SkBitmapConfig(resource()->format); |
| 511 // pixels in bitmap. Hence, a change since DoLockForWrite was called means the | 502 if (mapped_buffer_ && (buffer_config != raster_bitmap_.config())) |
| 512 // bitmap has changed. | 503 CopyBitmap(raster_bitmap_, mapped_buffer_, buffer_config); |
| 513 bool raster_bitmap_changed = | |
| 514 raster_bitmap_generation_id_ != raster_bitmap_.getGenerationID(); | |
| 515 | |
| 516 if (raster_bitmap_changed) { | |
| 517 SkBitmap::Config buffer_config = SkBitmapConfig(resource()->format); | |
| 518 if (mapped_buffer_ && (buffer_config != raster_bitmap_.config())) | |
| 519 CopyBitmap(raster_bitmap_, mapped_buffer_, buffer_config); | |
| 520 } | |
| 521 raster_bitmap_.reset(); | 504 raster_bitmap_.reset(); |
| 522 | 505 |
| 523 UnmapBuffer(); | 506 UnmapBuffer(); |
| 524 mapped_buffer_ = NULL; | 507 mapped_buffer_ = NULL; |
| 525 return raster_bitmap_changed; | |
| 526 } | 508 } |
| 527 | 509 |
| 528 ResourceProvider::ImageRasterBuffer::ImageRasterBuffer( | 510 ResourceProvider::ImageRasterBuffer::ImageRasterBuffer( |
| 529 const Resource* resource, | 511 const Resource* resource, |
| 530 ResourceProvider* resource_provider) | 512 ResourceProvider* resource_provider) |
| 531 : BitmapRasterBuffer(resource, resource_provider) {} | 513 : BitmapRasterBuffer(resource, resource_provider) {} |
| 532 | 514 |
| 533 ResourceProvider::ImageRasterBuffer::~ImageRasterBuffer() {} | 515 ResourceProvider::ImageRasterBuffer::~ImageRasterBuffer() {} |
| 534 | 516 |
| 535 uint8_t* ResourceProvider::ImageRasterBuffer::MapBuffer(int* stride) { | 517 uint8_t* ResourceProvider::ImageRasterBuffer::MapBuffer(int* stride) { |
| (...skipping 1215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1751 resource->pixel_raster_buffer.reset(); | 1733 resource->pixel_raster_buffer.reset(); |
| 1752 ReleasePixelBuffer(resource); | 1734 ReleasePixelBuffer(resource); |
| 1753 } | 1735 } |
| 1754 | 1736 |
| 1755 SkCanvas* ResourceProvider::MapPixelRasterBuffer(ResourceId id) { | 1737 SkCanvas* ResourceProvider::MapPixelRasterBuffer(ResourceId id) { |
| 1756 Resource* resource = GetResource(id); | 1738 Resource* resource = GetResource(id); |
| 1757 DCHECK(resource->pixel_raster_buffer.get()); | 1739 DCHECK(resource->pixel_raster_buffer.get()); |
| 1758 return resource->pixel_raster_buffer->LockForWrite(); | 1740 return resource->pixel_raster_buffer->LockForWrite(); |
| 1759 } | 1741 } |
| 1760 | 1742 |
| 1761 bool ResourceProvider::UnmapPixelRasterBuffer(ResourceId id) { | 1743 void ResourceProvider::UnmapPixelRasterBuffer(ResourceId id) { |
| 1762 Resource* resource = GetResource(id); | 1744 Resource* resource = GetResource(id); |
| 1763 DCHECK(resource->pixel_raster_buffer.get()); | 1745 DCHECK(resource->pixel_raster_buffer.get()); |
| 1764 return resource->pixel_raster_buffer->UnlockForWrite(); | 1746 resource->pixel_raster_buffer->UnlockForWrite(); |
| 1765 } | 1747 } |
| 1766 | 1748 |
| 1767 void ResourceProvider::AcquirePixelBuffer(Resource* resource) { | 1749 void ResourceProvider::AcquirePixelBuffer(Resource* resource) { |
| 1768 DCHECK(resource->origin == Resource::Internal); | 1750 DCHECK(resource->origin == Resource::Internal); |
| 1769 DCHECK_EQ(resource->exported_count, 0); | 1751 DCHECK_EQ(resource->exported_count, 0); |
| 1770 DCHECK(!resource->image_id); | 1752 DCHECK(!resource->image_id); |
| 1771 DCHECK_NE(ETC1, resource->format); | 1753 DCHECK_NE(ETC1, resource->format); |
| 1772 | 1754 |
| 1773 if (resource->type == GLTexture) { | 1755 if (resource->type == GLTexture) { |
| 1774 GLES2Interface* gl = ContextGL(); | 1756 GLES2Interface* gl = ContextGL(); |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2181 ContextProvider* context_provider = output_surface_->context_provider(); | 2163 ContextProvider* context_provider = output_surface_->context_provider(); |
| 2182 return context_provider ? context_provider->ContextGL() : NULL; | 2164 return context_provider ? context_provider->ContextGL() : NULL; |
| 2183 } | 2165 } |
| 2184 | 2166 |
| 2185 class GrContext* ResourceProvider::GrContext() const { | 2167 class GrContext* ResourceProvider::GrContext() const { |
| 2186 ContextProvider* context_provider = output_surface_->context_provider(); | 2168 ContextProvider* context_provider = output_surface_->context_provider(); |
| 2187 return context_provider ? context_provider->GrContext() : NULL; | 2169 return context_provider ? context_provider->GrContext() : NULL; |
| 2188 } | 2170 } |
| 2189 | 2171 |
| 2190 } // namespace cc | 2172 } // namespace cc |
| OLD | NEW |