| 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> |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 void UnmapDirectRasterBuffer(ResourceId id); | 324 void UnmapDirectRasterBuffer(ResourceId id); |
| 325 | 325 |
| 326 // Returns a canvas backed by an image buffer. | 326 // Returns a canvas backed by an image buffer. |
| 327 // Rasterizing to the canvas writes the content into the image buffer, | 327 // Rasterizing to the canvas writes the content into the image buffer, |
| 328 // which is internally bound to the underlying resource when read. | 328 // which is internally bound to the underlying resource when read. |
| 329 // Call Unmap before the resource can be read or used for compositing. | 329 // Call Unmap before the resource can be read or used for compositing. |
| 330 // It is used by ImageRasterWorkerPool. | 330 // It is used by ImageRasterWorkerPool. |
| 331 SkCanvas* MapImageRasterBuffer(ResourceId id); | 331 SkCanvas* MapImageRasterBuffer(ResourceId id); |
| 332 void UnmapImageRasterBuffer(ResourceId id); | 332 void UnmapImageRasterBuffer(ResourceId id); |
| 333 | 333 |
| 334 // Returns a canvas backed by pixel buffer. UnmapPixelRasterBuffer | 334 // Returns a canvas backed by pixel buffer. |
| 335 // returns true if canvas was written to while mapped. | |
| 336 // The pixel buffer needs to be uploaded to the underlying resource | 335 // The pixel buffer needs to be uploaded to the underlying resource |
| 337 // using BeginSetPixels before the resouce can be used for compositing. | 336 // using BeginSetPixels before the resouce can be used for compositing. |
| 338 // It is used by PixelRasterWorkerPool. | 337 // It is used by PixelRasterWorkerPool. |
| 339 void AcquirePixelRasterBuffer(ResourceId id); | 338 void AcquirePixelRasterBuffer(ResourceId id); |
| 340 void ReleasePixelRasterBuffer(ResourceId id); | 339 void ReleasePixelRasterBuffer(ResourceId id); |
| 341 SkCanvas* MapPixelRasterBuffer(ResourceId id); | 340 SkCanvas* MapPixelRasterBuffer(ResourceId id); |
| 342 bool UnmapPixelRasterBuffer(ResourceId id); | 341 void 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 linked_ptr<ImageRasterBuffer> image_raster_buffer; | 443 linked_ptr<ImageRasterBuffer> image_raster_buffer; |
| 445 linked_ptr<PixelRasterBuffer> pixel_raster_buffer; | 444 linked_ptr<PixelRasterBuffer> pixel_raster_buffer; |
| 446 }; | 445 }; |
| 447 typedef base::hash_map<ResourceId, Resource> ResourceMap; | 446 typedef base::hash_map<ResourceId, Resource> ResourceMap; |
| 448 | 447 |
| 449 class RasterBuffer { | 448 class RasterBuffer { |
| 450 public: | 449 public: |
| 451 virtual ~RasterBuffer(); | 450 virtual ~RasterBuffer(); |
| 452 | 451 |
| 453 SkCanvas* LockForWrite(); | 452 SkCanvas* LockForWrite(); |
| 454 // Returns true if canvas was written to while locked. | 453 void UnlockForWrite(); |
| 455 bool UnlockForWrite(); | |
| 456 | 454 |
| 457 protected: | 455 protected: |
| 458 RasterBuffer(const Resource* resource, ResourceProvider* resource_provider); | 456 RasterBuffer(const Resource* resource, ResourceProvider* resource_provider); |
| 459 const Resource* resource() const { return resource_; } | 457 const Resource* resource() const { return resource_; } |
| 460 ResourceProvider* resource_provider() const { return resource_provider_; } | 458 ResourceProvider* resource_provider() const { return resource_provider_; } |
| 461 | 459 |
| 462 virtual SkCanvas* DoLockForWrite() = 0; | 460 virtual SkCanvas* DoLockForWrite() = 0; |
| 463 virtual bool DoUnlockForWrite() = 0; | 461 virtual void DoUnlockForWrite() = 0; |
| 464 | 462 |
| 465 private: | 463 private: |
| 466 const Resource* resource_; | 464 const Resource* resource_; |
| 467 ResourceProvider* resource_provider_; | 465 ResourceProvider* resource_provider_; |
| 468 SkCanvas* locked_canvas_; | 466 SkCanvas* locked_canvas_; |
| 469 int canvas_save_count_; | 467 int canvas_save_count_; |
| 470 }; | 468 }; |
| 471 | 469 |
| 472 class DirectRasterBuffer : public RasterBuffer { | 470 class DirectRasterBuffer : public RasterBuffer { |
| 473 public: | 471 public: |
| 474 DirectRasterBuffer(const Resource* resource, | 472 DirectRasterBuffer(const Resource* resource, |
| 475 ResourceProvider* resource_provider); | 473 ResourceProvider* resource_provider); |
| 476 virtual ~DirectRasterBuffer(); | 474 virtual ~DirectRasterBuffer(); |
| 477 | 475 |
| 478 protected: | 476 protected: |
| 479 virtual SkCanvas* DoLockForWrite() OVERRIDE; | 477 virtual SkCanvas* DoLockForWrite() OVERRIDE; |
| 480 virtual bool DoUnlockForWrite() OVERRIDE; | 478 virtual void DoUnlockForWrite() OVERRIDE; |
| 481 skia::RefPtr<SkSurface> CreateSurface(); | 479 skia::RefPtr<SkSurface> CreateSurface(); |
| 482 | 480 |
| 483 private: | 481 private: |
| 484 skia::RefPtr<SkSurface> surface_; | 482 skia::RefPtr<SkSurface> surface_; |
| 485 uint32_t surface_generation_id_; | |
| 486 | |
| 487 DISALLOW_COPY_AND_ASSIGN(DirectRasterBuffer); | 483 DISALLOW_COPY_AND_ASSIGN(DirectRasterBuffer); |
| 488 }; | 484 }; |
| 489 | 485 |
| 490 class BitmapRasterBuffer : public RasterBuffer { | 486 class BitmapRasterBuffer : public RasterBuffer { |
| 491 public: | 487 public: |
| 492 virtual ~BitmapRasterBuffer(); | 488 virtual ~BitmapRasterBuffer(); |
| 493 | 489 |
| 494 protected: | 490 protected: |
| 495 BitmapRasterBuffer(const Resource* resource, | 491 BitmapRasterBuffer(const Resource* resource, |
| 496 ResourceProvider* resource_provider); | 492 ResourceProvider* resource_provider); |
| 497 | 493 |
| 498 virtual SkCanvas* DoLockForWrite() OVERRIDE; | 494 virtual SkCanvas* DoLockForWrite() OVERRIDE; |
| 499 virtual bool DoUnlockForWrite() OVERRIDE; | 495 virtual void DoUnlockForWrite() OVERRIDE; |
| 500 | 496 |
| 501 virtual uint8_t* MapBuffer(int* stride) = 0; | 497 virtual uint8_t* MapBuffer(int* stride) = 0; |
| 502 virtual void UnmapBuffer() = 0; | 498 virtual void UnmapBuffer() = 0; |
| 503 | 499 |
| 504 private: | 500 private: |
| 505 uint8_t* mapped_buffer_; | 501 uint8_t* mapped_buffer_; |
| 506 SkBitmap raster_bitmap_; | 502 SkBitmap raster_bitmap_; |
| 507 uint32_t raster_bitmap_generation_id_; | |
| 508 skia::RefPtr<SkCanvas> raster_canvas_; | 503 skia::RefPtr<SkCanvas> raster_canvas_; |
| 509 }; | 504 }; |
| 510 | 505 |
| 511 class ImageRasterBuffer : public BitmapRasterBuffer { | 506 class ImageRasterBuffer : public BitmapRasterBuffer { |
| 512 public: | 507 public: |
| 513 ImageRasterBuffer(const Resource* resource, | 508 ImageRasterBuffer(const Resource* resource, |
| 514 ResourceProvider* resource_provider); | 509 ResourceProvider* resource_provider); |
| 515 virtual ~ImageRasterBuffer(); | 510 virtual ~ImageRasterBuffer(); |
| 516 | 511 |
| 517 protected: | 512 protected: |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 return format_gl_data_format[format]; | 685 return format_gl_data_format[format]; |
| 691 } | 686 } |
| 692 | 687 |
| 693 inline GLenum GLInternalFormat(ResourceFormat format) { | 688 inline GLenum GLInternalFormat(ResourceFormat format) { |
| 694 return GLDataFormat(format); | 689 return GLDataFormat(format); |
| 695 } | 690 } |
| 696 | 691 |
| 697 } // namespace cc | 692 } // namespace cc |
| 698 | 693 |
| 699 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ | 694 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ |
| OLD | NEW |