| 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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 virtual bool HasPassed() = 0; | 310 virtual bool HasPassed() = 0; |
| 310 | 311 |
| 311 protected: | 312 protected: |
| 312 friend class base::RefCounted<Fence>; | 313 friend class base::RefCounted<Fence>; |
| 313 virtual ~Fence() {} | 314 virtual ~Fence() {} |
| 314 | 315 |
| 315 private: | 316 private: |
| 316 DISALLOW_COPY_AND_ASSIGN(Fence); | 317 DISALLOW_COPY_AND_ASSIGN(Fence); |
| 317 }; | 318 }; |
| 318 | 319 |
| 319 // Returns a canvas for gpu rasterization. | 320 // Returns a RasterBuffer for gpu rasterization. |
| 320 // Call Unmap before the resource can be read or used for compositing. | 321 // Call Release before the resource can be read or used for compositing. |
| 321 // It is used for direct gpu rasterization. | 322 // It is used for direct gpu rasterization. |
| 322 SkCanvas* MapGpuRasterBuffer(ResourceId id); | 323 RasterBuffer* AcquireGpuRasterBuffer(ResourceId id); |
| 323 void UnmapGpuRasterBuffer(ResourceId id); | 324 void ReleaseGpuRasterBuffer(ResourceId id); |
| 324 | 325 |
| 325 // Returns a canvas backed by an image buffer. UnmapImageRasterBuffer | 326 // Returns a RasterBuffer backed by an image buffer. ReleaseImageRasterBuffer |
| 326 // returns true if canvas was written to while mapped. | 327 // returns true if RasterBuffer was written to while acquired. |
| 327 // Rasterizing to the canvas writes the content into the image buffer, | 328 // Rasterizing to the RasterBuffer writes the content into the image buffer, |
| 328 // which is internally bound to the underlying resource when read. | 329 // which is internally bound to the underlying resource when read. |
| 329 // Call Unmap before the resource can be read or used for compositing. | 330 // Call Release before the resource can be read or used for compositing. |
| 330 // It is used by ImageRasterWorkerPool. | 331 // It is used by ImageRasterWorkerPool. |
| 331 SkCanvas* MapImageRasterBuffer(ResourceId id); | 332 RasterBuffer* AcquireImageRasterBuffer(ResourceId id); |
| 332 bool UnmapImageRasterBuffer(ResourceId id); | 333 bool ReleaseImageRasterBuffer(ResourceId id); |
| 333 | 334 |
| 334 // Returns a canvas backed by pixel buffer. UnmapPixelRasterBuffer | 335 // Returns a RasterBuffer backed by pixel buffer. ReleasePixelRasterBuffer |
| 335 // returns true if canvas was written to while mapped. | 336 // returns true if RasterBuffer was written to while acquired. |
| 336 // The pixel buffer needs to be uploaded to the underlying resource | 337 // The pixel buffer needs to be uploaded to the underlying resource |
| 337 // using BeginSetPixels before the resouce can be used for compositing. | 338 // using BeginSetPixels before the resouce can be used for compositing. |
| 338 // It is used by PixelRasterWorkerPool. | 339 // It is used by PixelRasterWorkerPool. |
| 339 void AcquirePixelRasterBuffer(ResourceId id); | 340 RasterBuffer* AcquirePixelRasterBuffer(ResourceId id); |
| 340 void ReleasePixelRasterBuffer(ResourceId id); | 341 bool ReleasePixelRasterBuffer(ResourceId id); |
| 341 SkCanvas* MapPixelRasterBuffer(ResourceId id); | |
| 342 bool UnmapPixelRasterBuffer(ResourceId id); | |
| 343 | 342 |
| 344 // Asynchronously update pixels from acquired pixel buffer. | 343 // Asynchronously update pixels from acquired pixel buffer. |
| 345 void BeginSetPixels(ResourceId id); | 344 void BeginSetPixels(ResourceId id); |
| 346 void ForceSetPixelsToComplete(ResourceId id); | 345 void ForceSetPixelsToComplete(ResourceId id); |
| 347 bool DidSetPixelsComplete(ResourceId id); | 346 bool DidSetPixelsComplete(ResourceId id); |
| 348 | 347 |
| 349 // For tests only! This prevents detecting uninitialized reads. | 348 // For tests only! This prevents detecting uninitialized reads. |
| 350 // Use SetPixels or LockForWrite to allocate implicitly. | 349 // Use SetPixels or LockForWrite to allocate implicitly. |
| 351 void AllocateForTesting(ResourceId id); | 350 void AllocateForTesting(ResourceId id); |
| 352 | 351 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 ResourceType type; | 442 ResourceType type; |
| 444 ResourceFormat format; | 443 ResourceFormat format; |
| 445 SharedBitmapId shared_bitmap_id; | 444 SharedBitmapId shared_bitmap_id; |
| 446 SharedBitmap* shared_bitmap; | 445 SharedBitmap* shared_bitmap; |
| 447 linked_ptr<GpuRasterBuffer> gpu_raster_buffer; | 446 linked_ptr<GpuRasterBuffer> gpu_raster_buffer; |
| 448 linked_ptr<ImageRasterBuffer> image_raster_buffer; | 447 linked_ptr<ImageRasterBuffer> image_raster_buffer; |
| 449 linked_ptr<PixelRasterBuffer> pixel_raster_buffer; | 448 linked_ptr<PixelRasterBuffer> pixel_raster_buffer; |
| 450 }; | 449 }; |
| 451 typedef base::hash_map<ResourceId, Resource> ResourceMap; | 450 typedef base::hash_map<ResourceId, Resource> ResourceMap; |
| 452 | 451 |
| 453 class RasterBuffer { | |
| 454 public: | |
| 455 virtual ~RasterBuffer(); | |
| 456 | |
| 457 SkCanvas* LockForWrite(); | |
| 458 // Returns true if canvas was written to while locked. | |
| 459 bool UnlockForWrite(); | |
| 460 | |
| 461 protected: | |
| 462 RasterBuffer(const Resource* resource, ResourceProvider* resource_provider); | |
| 463 const Resource* resource() const { return resource_; } | |
| 464 ResourceProvider* resource_provider() const { return resource_provider_; } | |
| 465 | |
| 466 virtual SkCanvas* DoLockForWrite() = 0; | |
| 467 virtual bool DoUnlockForWrite() = 0; | |
| 468 | |
| 469 private: | |
| 470 const Resource* resource_; | |
| 471 ResourceProvider* resource_provider_; | |
| 472 SkCanvas* locked_canvas_; | |
| 473 int canvas_save_count_; | |
| 474 }; | |
| 475 | |
| 476 class GpuRasterBuffer : public RasterBuffer { | 452 class GpuRasterBuffer : public RasterBuffer { |
| 477 public: | 453 public: |
| 478 GpuRasterBuffer(const Resource* resource, | 454 GpuRasterBuffer(const Resource* resource, |
| 479 ResourceProvider* resource_provider, | 455 ResourceProvider* resource_provider, |
| 480 bool use_distance_field_text); | 456 bool use_distance_field_text); |
| 481 virtual ~GpuRasterBuffer(); | 457 virtual ~GpuRasterBuffer(); |
| 482 | 458 |
| 483 protected: | 459 virtual skia::RefPtr<SkCanvas> AcquireSkCanvas() OVERRIDE; |
| 484 virtual SkCanvas* DoLockForWrite() OVERRIDE; | 460 virtual void ReleaseSkCanvas(const skia::RefPtr<SkCanvas>& canvas) OVERRIDE; |
| 485 virtual bool DoUnlockForWrite() OVERRIDE; | |
| 486 skia::RefPtr<SkSurface> CreateSurface(); | |
| 487 | 461 |
| 488 private: | 462 private: |
| 463 const Resource* resource_; |
| 464 ResourceProvider* resource_provider_; |
| 489 skia::RefPtr<SkSurface> surface_; | 465 skia::RefPtr<SkSurface> surface_; |
| 490 uint32_t surface_generation_id_; | |
| 491 const bool use_distance_field_text_; | |
| 492 | 466 |
| 493 DISALLOW_COPY_AND_ASSIGN(GpuRasterBuffer); | 467 DISALLOW_COPY_AND_ASSIGN(GpuRasterBuffer); |
| 494 }; | 468 }; |
| 495 | 469 |
| 496 class BitmapRasterBuffer : public RasterBuffer { | 470 class ImageRasterBuffer : public RasterBuffer { |
| 497 public: | |
| 498 virtual ~BitmapRasterBuffer(); | |
| 499 | |
| 500 protected: | |
| 501 BitmapRasterBuffer(const Resource* resource, | |
| 502 ResourceProvider* resource_provider); | |
| 503 | |
| 504 virtual SkCanvas* DoLockForWrite() OVERRIDE; | |
| 505 virtual bool DoUnlockForWrite() OVERRIDE; | |
| 506 | |
| 507 virtual uint8_t* MapBuffer(int* stride) = 0; | |
| 508 virtual void UnmapBuffer() = 0; | |
| 509 | |
| 510 private: | |
| 511 uint8_t* mapped_buffer_; | |
| 512 SkBitmap raster_bitmap_; | |
| 513 uint32_t raster_bitmap_generation_id_; | |
| 514 skia::RefPtr<SkCanvas> raster_canvas_; | |
| 515 }; | |
| 516 | |
| 517 class ImageRasterBuffer : public BitmapRasterBuffer { | |
| 518 public: | 471 public: |
| 519 ImageRasterBuffer(const Resource* resource, | 472 ImageRasterBuffer(const Resource* resource, |
| 520 ResourceProvider* resource_provider); | 473 ResourceProvider* resource_provider); |
| 521 virtual ~ImageRasterBuffer(); | 474 virtual ~ImageRasterBuffer(); |
| 522 | 475 |
| 523 protected: | 476 void MapBuffer(); |
| 524 virtual uint8_t* MapBuffer(int* stride) OVERRIDE; | 477 bool UnmapBuffer(); |
| 525 virtual void UnmapBuffer() OVERRIDE; | 478 |
| 479 virtual skia::RefPtr<SkCanvas> AcquireSkCanvas() OVERRIDE; |
| 480 virtual void ReleaseSkCanvas(const skia::RefPtr<SkCanvas>& canvas) OVERRIDE; |
| 526 | 481 |
| 527 private: | 482 private: |
| 483 const Resource* resource_; |
| 484 ResourceProvider* resource_provider_; |
| 485 uint8_t* mapped_buffer_; |
| 486 SkBitmap raster_bitmap_; |
| 487 bool raster_bitmap_changed_; |
| 488 int stride_; |
| 489 |
| 528 DISALLOW_COPY_AND_ASSIGN(ImageRasterBuffer); | 490 DISALLOW_COPY_AND_ASSIGN(ImageRasterBuffer); |
| 529 }; | 491 }; |
| 530 | 492 |
| 531 class PixelRasterBuffer : public BitmapRasterBuffer { | 493 class PixelRasterBuffer : public RasterBuffer { |
| 532 public: | 494 public: |
| 533 PixelRasterBuffer(const Resource* resource, | 495 PixelRasterBuffer(const Resource* resource, |
| 534 ResourceProvider* resource_provider); | 496 ResourceProvider* resource_provider); |
| 535 virtual ~PixelRasterBuffer(); | 497 virtual ~PixelRasterBuffer(); |
| 536 | 498 |
| 537 protected: | 499 void MapBuffer(); |
| 538 virtual uint8_t* MapBuffer(int* stride) OVERRIDE; | 500 bool UnmapBuffer(); |
| 539 virtual void UnmapBuffer() OVERRIDE; | 501 |
| 502 virtual skia::RefPtr<SkCanvas> AcquireSkCanvas() OVERRIDE; |
| 503 virtual void ReleaseSkCanvas(const skia::RefPtr<SkCanvas>& canvas) OVERRIDE; |
| 540 | 504 |
| 541 private: | 505 private: |
| 506 const Resource* resource_; |
| 507 ResourceProvider* resource_provider_; |
| 508 uint8_t* mapped_buffer_; |
| 509 SkBitmap raster_bitmap_; |
| 510 bool raster_bitmap_changed_; |
| 511 int stride_; |
| 512 |
| 542 DISALLOW_COPY_AND_ASSIGN(PixelRasterBuffer); | 513 DISALLOW_COPY_AND_ASSIGN(PixelRasterBuffer); |
| 543 }; | 514 }; |
| 544 | 515 |
| 545 static bool CompareResourceMapIteratorsByChildId( | 516 static bool CompareResourceMapIteratorsByChildId( |
| 546 const std::pair<ReturnedResource, ResourceMap::iterator>& a, | 517 const std::pair<ReturnedResource, ResourceMap::iterator>& a, |
| 547 const std::pair<ReturnedResource, ResourceMap::iterator>& b); | 518 const std::pair<ReturnedResource, ResourceMap::iterator>& b); |
| 548 | 519 |
| 549 struct Child { | 520 struct Child { |
| 550 Child(); | 521 Child(); |
| 551 ~Child(); | 522 ~Child(); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 return format_gl_data_format[format]; | 675 return format_gl_data_format[format]; |
| 705 } | 676 } |
| 706 | 677 |
| 707 inline GLenum GLInternalFormat(ResourceFormat format) { | 678 inline GLenum GLInternalFormat(ResourceFormat format) { |
| 708 return GLDataFormat(format); | 679 return GLDataFormat(format); |
| 709 } | 680 } |
| 710 | 681 |
| 711 } // namespace cc | 682 } // namespace cc |
| 712 | 683 |
| 713 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ | 684 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ |
| OLD | NEW |