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> |
| 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/release_callback.h" | 23 #include "cc/resources/release_callback.h" |
| 24 #include "cc/resources/resource_format.h" | 24 #include "cc/resources/resource_format.h" |
| 25 #include "cc/resources/resource_helper.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" |
| 33 #include "third_party/skia/include/core/SkCanvas.h" | 34 #include "third_party/skia/include/core/SkCanvas.h" |
| 34 #include "ui/gfx/size.h" | 35 #include "ui/gfx/size.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 const gfx::Vector2d& dest_offset); | 147 const gfx::Vector2d& dest_offset); |
| 147 | 148 |
| 148 // Check upload status. | 149 // Check upload status. |
| 149 size_t NumBlockingUploads(); | 150 size_t NumBlockingUploads(); |
| 150 void MarkPendingUploadsAsNonBlocking(); | 151 void MarkPendingUploadsAsNonBlocking(); |
| 151 size_t EstimatedUploadsPerTick(); | 152 size_t EstimatedUploadsPerTick(); |
| 152 void FlushUploads(); | 153 void FlushUploads(); |
| 153 void ReleaseCachedData(); | 154 void ReleaseCachedData(); |
| 154 base::TimeTicks EstimatedUploadCompletionTime(size_t uploads_per_tick); | 155 base::TimeTicks EstimatedUploadCompletionTime(size_t uploads_per_tick); |
| 155 | 156 |
| 156 // Flush all context operations, kicking uploads and ensuring ordering with | |
| 157 // respect to other contexts. | |
| 158 void Flush(); | |
| 159 | |
| 160 // Finish all context operations, causing any pending callbacks to be | |
| 161 // scheduled. | |
| 162 void Finish(); | |
| 163 | |
| 164 // Only flush the command buffer if supported. | |
| 165 // Returns true if the shallow flush occurred, false otherwise. | |
| 166 bool ShallowFlushIfSupported(); | |
| 167 | |
| 168 // Creates accounting for a child. Returns a child ID. | 157 // Creates accounting for a child. Returns a child ID. |
| 169 int CreateChild(const ReturnCallback& return_callback); | 158 int CreateChild(const ReturnCallback& return_callback); |
| 170 | 159 |
| 171 // Destroys accounting for the child, deleting all accounted resources. | 160 // Destroys accounting for the child, deleting all accounted resources. |
| 172 void DestroyChild(int child); | 161 void DestroyChild(int child); |
| 173 | 162 |
| 174 // Gets the child->parent resource ID map. | 163 // Gets the child->parent resource ID map. |
| 175 const ResourceIdMap& GetChildToParentMap(int child) const; | 164 const ResourceIdMap& GetChildToParentMap(int child) const; |
| 176 | 165 |
| 177 // Prepares resources to be transfered to the parent, moving them to | 166 // Prepares resources to be transfered to the parent, moving them to |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 | 288 |
| 300 private: | 289 private: |
| 301 ResourceProvider* resource_provider_; | 290 ResourceProvider* resource_provider_; |
| 302 ResourceProvider::ResourceId resource_id_; | 291 ResourceProvider::ResourceId resource_id_; |
| 303 SkBitmap sk_bitmap_; | 292 SkBitmap sk_bitmap_; |
| 304 scoped_ptr<SkCanvas> sk_canvas_; | 293 scoped_ptr<SkCanvas> sk_canvas_; |
| 305 | 294 |
| 306 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware); | 295 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware); |
| 307 }; | 296 }; |
| 308 | 297 |
| 309 // The following class is needed to modify GL resources using GPU | |
| 310 // raster. The user must ensure that they only use GPU raster on | |
| 311 // GL resources while an instance of this class is alive. | |
| 312 class CC_EXPORT ScopedGpuRaster { | |
| 313 public: | |
| 314 ScopedGpuRaster(ResourceProvider* resource_provider); | |
| 315 ~ScopedGpuRaster(); | |
| 316 | |
| 317 private: | |
| 318 ResourceProvider* resource_provider_; | |
| 319 | |
| 320 DISALLOW_COPY_AND_ASSIGN(ScopedGpuRaster); | |
| 321 }; | |
| 322 | |
| 323 class Fence : public base::RefCounted<Fence> { | 298 class Fence : public base::RefCounted<Fence> { |
| 324 public: | 299 public: |
| 325 Fence() {} | 300 Fence() {} |
| 326 virtual bool HasPassed() = 0; | 301 virtual bool HasPassed() = 0; |
| 327 | 302 |
| 328 protected: | 303 protected: |
| 329 friend class base::RefCounted<Fence>; | 304 friend class base::RefCounted<Fence>; |
| 330 virtual ~Fence() {} | 305 virtual ~Fence() {} |
| 331 | 306 |
| 332 private: | 307 private: |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 379 | 354 |
| 380 // Enable read lock fences for a specific resource. | 355 // Enable read lock fences for a specific resource. |
| 381 void EnableReadLockFences(ResourceProvider::ResourceId id, bool enable); | 356 void EnableReadLockFences(ResourceProvider::ResourceId id, bool enable); |
| 382 | 357 |
| 383 // Indicates if we can currently lock this resource for write. | 358 // Indicates if we can currently lock this resource for write. |
| 384 bool CanLockForWrite(ResourceId id); | 359 bool CanLockForWrite(ResourceId id); |
| 385 | 360 |
| 386 // Copy pixels from source to destination. | 361 // Copy pixels from source to destination. |
| 387 void CopyResource(ResourceId source_id, ResourceId dest_id); | 362 void CopyResource(ResourceId source_id, ResourceId dest_id); |
| 388 | 363 |
| 389 static GLint GetActiveTextureUnit(gpu::gles2::GLES2Interface* gl); | 364 ResourceHelper* GetResourceHelper() { return resource_helper_.get(); } |
| 390 | 365 |
| 391 private: | 366 private: |
| 392 class GpuRasterBuffer; | 367 class GpuRasterBuffer; |
| 393 class ImageRasterBuffer; | 368 class ImageRasterBuffer; |
| 394 class PixelRasterBuffer; | 369 class PixelRasterBuffer; |
| 395 | 370 |
| 396 struct Resource { | 371 struct Resource { |
| 397 enum Origin { Internal, External, Delegated }; | 372 enum Origin { Internal, External, Delegated }; |
| 398 | 373 |
| 399 Resource(); | 374 Resource(); |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 630 void UnmapImage(const Resource* resource); | 605 void UnmapImage(const Resource* resource); |
| 631 | 606 |
| 632 void BindImageForSampling(Resource* resource); | 607 void BindImageForSampling(Resource* resource); |
| 633 // Binds the given GL resource to a texture target for sampling using the | 608 // Binds the given GL resource to a texture target for sampling using the |
| 634 // specified filter for both minification and magnification. Returns the | 609 // specified filter for both minification and magnification. Returns the |
| 635 // texture target used. The resource must be locked for reading. | 610 // texture target used. The resource must be locked for reading. |
| 636 GLenum BindForSampling(ResourceProvider::ResourceId resource_id, | 611 GLenum BindForSampling(ResourceProvider::ResourceId resource_id, |
| 637 GLenum unit, | 612 GLenum unit, |
| 638 GLenum filter); | 613 GLenum filter); |
| 639 | 614 |
| 640 // Returns NULL if the output_surface_ does not have a ContextProvider. | |
| 641 gpu::gles2::GLES2Interface* ContextGL() const; | |
|
danakj
2014/07/09 16:01:33
These are private methods used internally in Resou
sohanjg
2014/07/10 15:11:06
Done.
Had to pull them to public though, because
| |
| 642 class GrContext* GrContext() const; | |
| 643 | |
| 644 void BeginGpuRaster(); | |
| 645 void EndGpuRaster(); | |
| 646 | |
| 647 OutputSurface* output_surface_; | 615 OutputSurface* output_surface_; |
| 648 SharedBitmapManager* shared_bitmap_manager_; | 616 SharedBitmapManager* shared_bitmap_manager_; |
| 649 bool lost_output_surface_; | 617 bool lost_output_surface_; |
| 650 int highp_threshold_min_; | 618 int highp_threshold_min_; |
| 651 ResourceId next_id_; | 619 ResourceId next_id_; |
| 652 ResourceMap resources_; | 620 ResourceMap resources_; |
| 653 int next_child_; | 621 int next_child_; |
| 654 ChildMap children_; | 622 ChildMap children_; |
| 655 | 623 |
| 656 ResourceType default_resource_type_; | 624 ResourceType default_resource_type_; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 667 bool use_rgba_4444_texture_format_; | 635 bool use_rgba_4444_texture_format_; |
| 668 | 636 |
| 669 const size_t id_allocation_chunk_size_; | 637 const size_t id_allocation_chunk_size_; |
| 670 scoped_ptr<IdAllocator> texture_id_allocator_; | 638 scoped_ptr<IdAllocator> texture_id_allocator_; |
| 671 scoped_ptr<IdAllocator> buffer_id_allocator_; | 639 scoped_ptr<IdAllocator> buffer_id_allocator_; |
| 672 | 640 |
| 673 bool use_sync_query_; | 641 bool use_sync_query_; |
| 674 | 642 |
| 675 bool use_distance_field_text_; | 643 bool use_distance_field_text_; |
| 676 | 644 |
| 645 scoped_ptr<ResourceHelper> resource_helper_; | |
| 646 | |
| 677 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); | 647 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); |
| 678 }; | 648 }; |
| 679 | 649 |
| 680 | 650 |
| 681 // TODO(epenner): Move these format conversions to resource_format.h | 651 // TODO(epenner): Move these format conversions to resource_format.h |
| 682 // once that builds on mac (npapi.h currently #includes OpenGL.h). | 652 // once that builds on mac (npapi.h currently #includes OpenGL.h). |
| 683 inline unsigned BitsPerPixel(ResourceFormat format) { | 653 inline unsigned BitsPerPixel(ResourceFormat format) { |
| 684 DCHECK_LE(format, RESOURCE_FORMAT_MAX); | 654 DCHECK_LE(format, RESOURCE_FORMAT_MAX); |
| 685 static const unsigned format_bits_per_pixel[RESOURCE_FORMAT_MAX + 1] = { | 655 static const unsigned format_bits_per_pixel[RESOURCE_FORMAT_MAX + 1] = { |
| 686 32, // RGBA_8888 | 656 32, // RGBA_8888 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 719 return format_gl_data_format[format]; | 689 return format_gl_data_format[format]; |
| 720 } | 690 } |
| 721 | 691 |
| 722 inline GLenum GLInternalFormat(ResourceFormat format) { | 692 inline GLenum GLInternalFormat(ResourceFormat format) { |
| 723 return GLDataFormat(format); | 693 return GLDataFormat(format); |
| 724 } | 694 } |
| 725 | 695 |
| 726 } // namespace cc | 696 } // namespace cc |
| 727 | 697 |
| 728 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ | 698 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ |
| OLD | NEW |