| 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 #ifndef CC_RESOURCES_RESOURCE_PROVIDER_H_ | 5 #ifndef CC_RESOURCES_RESOURCE_PROVIDER_H_ |
| 6 #define CC_RESOURCES_RESOURCE_PROVIDER_H_ | 6 #define CC_RESOURCES_RESOURCE_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/callback.h" | 15 #include "base/callback.h" |
| 16 #include "base/containers/hash_tables.h" | 16 #include "base/containers/hash_tables.h" |
| 17 #include "base/memory/linked_ptr.h" | 17 #include "base/memory/linked_ptr.h" |
| 18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/threading/thread_checker.h" | 19 #include "base/threading/thread_checker.h" |
| 20 #include "cc/base/cc_export.h" | 20 #include "cc/base/cc_export.h" |
| 21 #include "cc/output/context_provider.h" | 21 #include "cc/output/context_provider.h" |
| 22 #include "cc/output/output_surface.h" | 22 #include "cc/output/output_surface.h" |
| 23 #include "cc/resources/raster_buffer.h" |
| 23 #include "cc/resources/release_callback.h" | 24 #include "cc/resources/release_callback.h" |
| 24 #include "cc/resources/resource_format.h" | 25 #include "cc/resources/resource_format.h" |
| 25 #include "cc/resources/return_callback.h" | 26 #include "cc/resources/return_callback.h" |
| 26 #include "cc/resources/shared_bitmap.h" | 27 #include "cc/resources/shared_bitmap.h" |
| 27 #include "cc/resources/single_release_callback.h" | 28 #include "cc/resources/single_release_callback.h" |
| 28 #include "cc/resources/texture_mailbox.h" | 29 #include "cc/resources/texture_mailbox.h" |
| 29 #include "cc/resources/transferable_resource.h" | 30 #include "cc/resources/transferable_resource.h" |
| 30 #include "third_party/khronos/GLES2/gl2.h" | 31 #include "third_party/khronos/GLES2/gl2.h" |
| 31 #include "third_party/khronos/GLES2/gl2ext.h" | 32 #include "third_party/khronos/GLES2/gl2ext.h" |
| 32 #include "third_party/skia/include/core/SkBitmap.h" | 33 #include "third_party/skia/include/core/SkBitmap.h" |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 virtual bool HasPassed() = 0; | 307 virtual bool HasPassed() = 0; |
| 307 | 308 |
| 308 protected: | 309 protected: |
| 309 friend class base::RefCounted<Fence>; | 310 friend class base::RefCounted<Fence>; |
| 310 virtual ~Fence() {} | 311 virtual ~Fence() {} |
| 311 | 312 |
| 312 private: | 313 private: |
| 313 DISALLOW_COPY_AND_ASSIGN(Fence); | 314 DISALLOW_COPY_AND_ASSIGN(Fence); |
| 314 }; | 315 }; |
| 315 | 316 |
| 316 // Returns a canvas for gpu rasterization. | 317 // Returns a RasterBuffer for gpu rasterization. |
| 317 // Call Unmap before the resource can be read or used for compositing. | 318 // Call Release before the resource can be read or used for compositing. |
| 318 // It is used for direct gpu rasterization. | 319 // It is used for direct gpu rasterization. |
| 319 SkCanvas* MapGpuRasterBuffer(ResourceId id); | 320 RasterBuffer* AcquireGpuRasterBuffer(ResourceId id); |
| 320 void UnmapGpuRasterBuffer(ResourceId id); | 321 void ReleaseGpuRasterBuffer(ResourceId id); |
| 321 | 322 |
| 322 // Returns a canvas backed by an image buffer. UnmapImageRasterBuffer | 323 // Returns a RasterBuffer backed by an image buffer. ReleaseImageRasterBuffer |
| 323 // returns true if canvas was written to while mapped. | 324 // returns true if RasterBuffer was written to while acquired. |
| 324 // Rasterizing to the canvas writes the content into the image buffer, | 325 // Rasterizing to the RasterBuffer writes the content into the image buffer, |
| 325 // which is internally bound to the underlying resource when read. | 326 // which is internally bound to the underlying resource when read. |
| 326 // Call Unmap before the resource can be read or used for compositing. | 327 // Call Release before the resource can be read or used for compositing. |
| 327 // It is used by ImageRasterWorkerPool. | 328 // It is used by ImageRasterWorkerPool. |
| 328 SkCanvas* MapImageRasterBuffer(ResourceId id); | 329 RasterBuffer* AcquireImageRasterBuffer(ResourceId id); |
| 329 bool UnmapImageRasterBuffer(ResourceId id); | 330 bool ReleaseImageRasterBuffer(ResourceId id); |
| 330 | 331 |
| 331 // Returns a canvas backed by pixel buffer. UnmapPixelRasterBuffer | 332 // Returns a RasterBuffer backed by pixel buffer. ReleasePixelRasterBuffer |
| 332 // returns true if canvas was written to while mapped. | 333 // returns true if RasterBuffer was written to while acquired. |
| 333 // The pixel buffer needs to be uploaded to the underlying resource | 334 // The pixel buffer needs to be uploaded to the underlying resource |
| 334 // using BeginSetPixels before the resouce can be used for compositing. | 335 // using BeginSetPixels before the resouce can be used for compositing. |
| 335 // It is used by PixelRasterWorkerPool. | 336 // It is used by PixelRasterWorkerPool. |
| 336 void AcquirePixelRasterBuffer(ResourceId id); | 337 RasterBuffer* AcquirePixelRasterBuffer(ResourceId id); |
| 337 void ReleasePixelRasterBuffer(ResourceId id); | 338 bool ReleasePixelRasterBuffer(ResourceId id); |
| 338 SkCanvas* MapPixelRasterBuffer(ResourceId id); | |
| 339 bool UnmapPixelRasterBuffer(ResourceId id); | |
| 340 | 339 |
| 341 // Asynchronously update pixels from acquired pixel buffer. | 340 // Asynchronously update pixels from acquired pixel buffer. |
| 342 void BeginSetPixels(ResourceId id); | 341 void BeginSetPixels(ResourceId id); |
| 343 void ForceSetPixelsToComplete(ResourceId id); | 342 void ForceSetPixelsToComplete(ResourceId id); |
| 344 bool DidSetPixelsComplete(ResourceId id); | 343 bool DidSetPixelsComplete(ResourceId id); |
| 345 | 344 |
| 346 // For tests only! This prevents detecting uninitialized reads. | 345 // For tests only! This prevents detecting uninitialized reads. |
| 347 // Use SetPixels or LockForWrite to allocate implicitly. | 346 // Use SetPixels or LockForWrite to allocate implicitly. |
| 348 void AllocateForTesting(ResourceId id); | 347 void AllocateForTesting(ResourceId id); |
| 349 | 348 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 ResourceType type; | 437 ResourceType type; |
| 439 ResourceFormat format; | 438 ResourceFormat format; |
| 440 SharedBitmapId shared_bitmap_id; | 439 SharedBitmapId shared_bitmap_id; |
| 441 SharedBitmap* shared_bitmap; | 440 SharedBitmap* shared_bitmap; |
| 442 linked_ptr<GpuRasterBuffer> gpu_raster_buffer; | 441 linked_ptr<GpuRasterBuffer> gpu_raster_buffer; |
| 443 linked_ptr<ImageRasterBuffer> image_raster_buffer; | 442 linked_ptr<ImageRasterBuffer> image_raster_buffer; |
| 444 linked_ptr<PixelRasterBuffer> pixel_raster_buffer; | 443 linked_ptr<PixelRasterBuffer> pixel_raster_buffer; |
| 445 }; | 444 }; |
| 446 typedef base::hash_map<ResourceId, Resource> ResourceMap; | 445 typedef base::hash_map<ResourceId, Resource> ResourceMap; |
| 447 | 446 |
| 448 class RasterBuffer { | |
| 449 public: | |
| 450 virtual ~RasterBuffer(); | |
| 451 | |
| 452 SkCanvas* LockForWrite(); | |
| 453 // Returns true if canvas was written to while locked. | |
| 454 bool UnlockForWrite(); | |
| 455 | |
| 456 protected: | |
| 457 RasterBuffer(const Resource* resource, ResourceProvider* resource_provider); | |
| 458 const Resource* resource() const { return resource_; } | |
| 459 ResourceProvider* resource_provider() const { return resource_provider_; } | |
| 460 | |
| 461 virtual SkCanvas* DoLockForWrite() = 0; | |
| 462 virtual bool DoUnlockForWrite() = 0; | |
| 463 | |
| 464 private: | |
| 465 const Resource* resource_; | |
| 466 ResourceProvider* resource_provider_; | |
| 467 SkCanvas* locked_canvas_; | |
| 468 int canvas_save_count_; | |
| 469 }; | |
| 470 | |
| 471 class GpuRasterBuffer : public RasterBuffer { | 447 class GpuRasterBuffer : public RasterBuffer { |
| 472 public: | 448 public: |
| 473 GpuRasterBuffer(const Resource* resource, | 449 GpuRasterBuffer(const Resource* resource, |
| 474 ResourceProvider* resource_provider, | 450 ResourceProvider* resource_provider, |
| 475 bool use_distance_field_text); | 451 bool use_distance_field_text); |
| 476 virtual ~GpuRasterBuffer(); | 452 virtual ~GpuRasterBuffer(); |
| 477 | 453 |
| 478 protected: | 454 virtual skia::RefPtr<SkCanvas> AcquireSkCanvas() OVERRIDE; |
| 479 virtual SkCanvas* DoLockForWrite() OVERRIDE; | 455 virtual void ReleaseSkCanvas(const skia::RefPtr<SkCanvas>& canvas) OVERRIDE; |
| 480 virtual bool DoUnlockForWrite() OVERRIDE; | |
| 481 skia::RefPtr<SkSurface> CreateSurface(); | |
| 482 | 456 |
| 483 private: | 457 private: |
| 458 const Resource* resource_; |
| 459 ResourceProvider* resource_provider_; |
| 484 skia::RefPtr<SkSurface> surface_; | 460 skia::RefPtr<SkSurface> surface_; |
| 485 uint32_t surface_generation_id_; | |
| 486 const bool use_distance_field_text_; | |
| 487 | 461 |
| 488 DISALLOW_COPY_AND_ASSIGN(GpuRasterBuffer); | 462 DISALLOW_COPY_AND_ASSIGN(GpuRasterBuffer); |
| 489 }; | 463 }; |
| 490 | 464 |
| 491 class BitmapRasterBuffer : public RasterBuffer { | 465 class ImageRasterBuffer : public RasterBuffer { |
| 492 public: | |
| 493 virtual ~BitmapRasterBuffer(); | |
| 494 | |
| 495 protected: | |
| 496 BitmapRasterBuffer(const Resource* resource, | |
| 497 ResourceProvider* resource_provider); | |
| 498 | |
| 499 virtual SkCanvas* DoLockForWrite() OVERRIDE; | |
| 500 virtual bool DoUnlockForWrite() OVERRIDE; | |
| 501 | |
| 502 virtual uint8_t* MapBuffer(int* stride) = 0; | |
| 503 virtual void UnmapBuffer() = 0; | |
| 504 | |
| 505 private: | |
| 506 uint8_t* mapped_buffer_; | |
| 507 SkBitmap raster_bitmap_; | |
| 508 uint32_t raster_bitmap_generation_id_; | |
| 509 skia::RefPtr<SkCanvas> raster_canvas_; | |
| 510 }; | |
| 511 | |
| 512 class ImageRasterBuffer : public BitmapRasterBuffer { | |
| 513 public: | 466 public: |
| 514 ImageRasterBuffer(const Resource* resource, | 467 ImageRasterBuffer(const Resource* resource, |
| 515 ResourceProvider* resource_provider); | 468 ResourceProvider* resource_provider); |
| 516 virtual ~ImageRasterBuffer(); | 469 virtual ~ImageRasterBuffer(); |
| 517 | 470 |
| 518 protected: | 471 void MapBuffer(); |
| 519 virtual uint8_t* MapBuffer(int* stride) OVERRIDE; | 472 bool UnmapBuffer(); |
| 520 virtual void UnmapBuffer() OVERRIDE; | 473 |
| 474 virtual skia::RefPtr<SkCanvas> AcquireSkCanvas() OVERRIDE; |
| 475 virtual void ReleaseSkCanvas(const skia::RefPtr<SkCanvas>& canvas) OVERRIDE; |
| 521 | 476 |
| 522 private: | 477 private: |
| 478 const Resource* resource_; |
| 479 ResourceProvider* resource_provider_; |
| 480 uint8_t* mapped_buffer_; |
| 481 SkBitmap raster_bitmap_; |
| 482 bool raster_bitmap_changed_; |
| 483 int stride_; |
| 484 |
| 523 DISALLOW_COPY_AND_ASSIGN(ImageRasterBuffer); | 485 DISALLOW_COPY_AND_ASSIGN(ImageRasterBuffer); |
| 524 }; | 486 }; |
| 525 | 487 |
| 526 class PixelRasterBuffer : public BitmapRasterBuffer { | 488 class PixelRasterBuffer : public RasterBuffer { |
| 527 public: | 489 public: |
| 528 PixelRasterBuffer(const Resource* resource, | 490 PixelRasterBuffer(const Resource* resource, |
| 529 ResourceProvider* resource_provider); | 491 ResourceProvider* resource_provider); |
| 530 virtual ~PixelRasterBuffer(); | 492 virtual ~PixelRasterBuffer(); |
| 531 | 493 |
| 532 protected: | 494 void MapBuffer(); |
| 533 virtual uint8_t* MapBuffer(int* stride) OVERRIDE; | 495 bool UnmapBuffer(); |
| 534 virtual void UnmapBuffer() OVERRIDE; | 496 |
| 497 virtual skia::RefPtr<SkCanvas> AcquireSkCanvas() OVERRIDE; |
| 498 virtual void ReleaseSkCanvas(const skia::RefPtr<SkCanvas>& canvas) OVERRIDE; |
| 535 | 499 |
| 536 private: | 500 private: |
| 501 const Resource* resource_; |
| 502 ResourceProvider* resource_provider_; |
| 503 uint8_t* mapped_buffer_; |
| 504 SkBitmap raster_bitmap_; |
| 505 bool raster_bitmap_changed_; |
| 506 int stride_; |
| 507 |
| 537 DISALLOW_COPY_AND_ASSIGN(PixelRasterBuffer); | 508 DISALLOW_COPY_AND_ASSIGN(PixelRasterBuffer); |
| 538 }; | 509 }; |
| 539 | 510 |
| 540 static bool CompareResourceMapIteratorsByChildId( | 511 static bool CompareResourceMapIteratorsByChildId( |
| 541 const std::pair<ReturnedResource, ResourceMap::iterator>& a, | 512 const std::pair<ReturnedResource, ResourceMap::iterator>& a, |
| 542 const std::pair<ReturnedResource, ResourceMap::iterator>& b); | 513 const std::pair<ReturnedResource, ResourceMap::iterator>& b); |
| 543 | 514 |
| 544 struct Child { | 515 struct Child { |
| 545 Child(); | 516 Child(); |
| 546 ~Child(); | 517 ~Child(); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 return format_gl_data_format[format]; | 667 return format_gl_data_format[format]; |
| 697 } | 668 } |
| 698 | 669 |
| 699 inline GLenum GLInternalFormat(ResourceFormat format) { | 670 inline GLenum GLInternalFormat(ResourceFormat format) { |
| 700 return GLDataFormat(format); | 671 return GLDataFormat(format); |
| 701 } | 672 } |
| 702 | 673 |
| 703 } // namespace cc | 674 } // namespace cc |
| 704 | 675 |
| 705 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ | 676 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ |
| OLD | NEW |