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