diff options
Diffstat (limited to 'chromium/cc/resources/resource_provider.h')
-rw-r--r-- | chromium/cc/resources/resource_provider.h | 261 |
1 files changed, 206 insertions, 55 deletions
diff --git a/chromium/cc/resources/resource_provider.h b/chromium/cc/resources/resource_provider.h index 6e5c61a2bfa..1d991e2b144 100644 --- a/chromium/cc/resources/resource_provider.h +++ b/chromium/cc/resources/resource_provider.h @@ -14,6 +14,7 @@ #include "base/basictypes.h" #include "base/callback.h" #include "base/containers/hash_tables.h" +#include "base/memory/linked_ptr.h" #include "base/memory/scoped_ptr.h" #include "base/threading/thread_checker.h" #include "cc/base/cc_export.h" @@ -22,6 +23,7 @@ #include "cc/resources/release_callback.h" #include "cc/resources/resource_format.h" #include "cc/resources/return_callback.h" +#include "cc/resources/shared_bitmap.h" #include "cc/resources/single_release_callback.h" #include "cc/resources/texture_mailbox.h" #include "cc/resources/transferable_resource.h" @@ -31,6 +33,8 @@ #include "third_party/skia/include/core/SkCanvas.h" #include "ui/gfx/size.h" +class GrContext; + namespace gpu { namespace gles { class GLES2Interface; @@ -71,11 +75,12 @@ class CC_EXPORT ResourceProvider { SharedBitmapManager* shared_bitmap_manager, int highp_threshold_min, bool use_rgba_4444_texture_format, - size_t id_allocation_chunk_size); + size_t id_allocation_chunk_size, + bool use_distance_field_text); virtual ~ResourceProvider(); void InitializeSoftware(); - bool InitializeGL(); + void InitializeGL(); void DidLoseOutputSurface() { lost_output_surface_ = true; } @@ -84,12 +89,14 @@ class CC_EXPORT ResourceProvider { return use_rgba_4444_texture_format_ ? RGBA_4444 : best_texture_format_; } ResourceFormat best_texture_format() const { return best_texture_format_; } + bool use_sync_query() const { return use_sync_query_; } size_t num_resources() const { return resources_.size(); } // Checks whether a resource is in use by a consumer. bool InUseByConsumer(ResourceId id); bool IsLost(ResourceId id); + bool AllowOverlay(ResourceId id); // Producer interface. @@ -97,32 +104,31 @@ class CC_EXPORT ResourceProvider { ResourceType GetResourceType(ResourceId id); // Creates a resource of the default resource type. - ResourceId CreateResource(gfx::Size size, + ResourceId CreateResource(const gfx::Size& size, GLint wrap_mode, TextureUsageHint hint, ResourceFormat format); // Creates a resource which is tagged as being managed for GPU memory // accounting purposes. - ResourceId CreateManagedResource(gfx::Size size, + ResourceId CreateManagedResource(const gfx::Size& size, GLenum target, GLint wrap_mode, TextureUsageHint hint, ResourceFormat format); // You can also explicitly create a specific resource type. - ResourceId CreateGLTexture(gfx::Size size, + ResourceId CreateGLTexture(const gfx::Size& size, GLenum target, GLenum texture_pool, GLint wrap_mode, TextureUsageHint hint, ResourceFormat format); - ResourceId CreateBitmap(gfx::Size size, GLint wrap_mode); - // Wraps an external texture into a GL resource. - ResourceId CreateResourceFromExternalTexture( - unsigned texture_target, - unsigned texture_id); + ResourceId CreateBitmap(const gfx::Size& size, GLint wrap_mode); + // Wraps an IOSurface into a GL resource. + ResourceId CreateResourceFromIOSurface(const gfx::Size& size, + unsigned io_surface_id); // Wraps an external texture mailbox into a GL resource. ResourceId CreateResourceFromTextureMailbox( @@ -135,9 +141,9 @@ class CC_EXPORT ResourceProvider { // the resource). void SetPixels(ResourceId id, const uint8_t* image, - gfx::Rect image_rect, - gfx::Rect source_rect, - gfx::Vector2d dest_offset); + const gfx::Rect& image_rect, + const gfx::Rect& source_rect, + const gfx::Vector2d& dest_offset); // Check upload status. size_t NumBlockingUploads(); @@ -265,9 +271,14 @@ class CC_EXPORT ResourceProvider { ResourceProvider::ResourceId resource_id); ~ScopedReadLockSoftware(); - const SkBitmap* sk_bitmap() const { return &sk_bitmap_; } + const SkBitmap* sk_bitmap() const { + DCHECK(valid()); + return &sk_bitmap_; + } GLint wrap_mode() const { return wrap_mode_; } + bool valid() const { return !!sk_bitmap_.getPixels(); } + private: ResourceProvider* resource_provider_; ResourceProvider::ResourceId resource_id_; @@ -284,6 +295,7 @@ class CC_EXPORT ResourceProvider { ~ScopedWriteLockSoftware(); SkCanvas* sk_canvas() { return sk_canvas_.get(); } + bool valid() const { return !!sk_bitmap_.getPixels(); } private: ResourceProvider* resource_provider_; @@ -307,35 +319,36 @@ class CC_EXPORT ResourceProvider { DISALLOW_COPY_AND_ASSIGN(Fence); }; - // Acquire pixel buffer for resource. The pixel buffer can be used to - // set resource pixels without performing unnecessary copying. - void AcquirePixelBuffer(ResourceId id); - void ReleasePixelBuffer(ResourceId id); - - // Map/unmap the acquired pixel buffer. - uint8_t* MapPixelBuffer(ResourceId id); - void UnmapPixelBuffer(ResourceId id); + // Returns a canvas for direct rasterization. + // Call Unmap before the resource can be read or used for compositing. + // It is used for direct gpu rasterization. + SkCanvas* MapDirectRasterBuffer(ResourceId id); + void UnmapDirectRasterBuffer(ResourceId id); + + // Returns a canvas backed by an image buffer. UnmapImageRasterBuffer + // returns true if canvas was written to while mapped. + // Rasterizing to the canvas writes the content into the image buffer, + // which is internally bound to the underlying resource when read. + // Call Unmap before the resource can be read or used for compositing. + // It is used by ImageRasterWorkerPool. + SkCanvas* MapImageRasterBuffer(ResourceId id); + bool UnmapImageRasterBuffer(ResourceId id); + + // Returns a canvas backed by pixel buffer. UnmapPixelRasterBuffer + // returns true if canvas was written to while mapped. + // The pixel buffer needs to be uploaded to the underlying resource + // using BeginSetPixels before the resouce can be used for compositing. + // It is used by PixelRasterWorkerPool. + void AcquirePixelRasterBuffer(ResourceId id); + void ReleasePixelRasterBuffer(ResourceId id); + SkCanvas* MapPixelRasterBuffer(ResourceId id); + bool UnmapPixelRasterBuffer(ResourceId id); // Asynchronously update pixels from acquired pixel buffer. void BeginSetPixels(ResourceId id); void ForceSetPixelsToComplete(ResourceId id); bool DidSetPixelsComplete(ResourceId id); - // Acquire and release an image. The image allows direct - // manipulation of texture memory. - void AcquireImage(ResourceId id); - void ReleaseImage(ResourceId id); - - // Maps the acquired image so that its pixels could be modified. - // Unmap is called when all pixels are set. - uint8_t* MapImage(ResourceId id); - void UnmapImage(ResourceId id); - - // Returns the stride for the image. - int GetImageStride(ResourceId id); - - base::SharedMemory* GetSharedMemory(ResourceId id); - // For tests only! This prevents detecting uninitialized reads. // Use SetPixels or LockForWrite to allocate implicitly. void AllocateForTesting(ResourceId id); @@ -348,10 +361,7 @@ class CC_EXPORT ResourceProvider { // Sets the current read fence. If a resource is locked for read // and has read fences enabled, the resource will not allow writes // until this fence has passed. - void SetReadLockFence(scoped_refptr<Fence> fence) { - current_read_lock_fence_ = fence; - } - Fence* GetReadLockFence() { return current_read_lock_fence_.get(); } + void SetReadLockFence(Fence* fence) { current_read_lock_fence_ = fence; } // Enable read lock fences for a specific resource. void EnableReadLockFences(ResourceProvider::ResourceId id, bool enable); @@ -359,14 +369,24 @@ class CC_EXPORT ResourceProvider { // Indicates if we can currently lock this resource for write. bool CanLockForWrite(ResourceId id); + // Copy pixels from source to destination. + void CopyResource(ResourceId source_id, ResourceId dest_id); + static GLint GetActiveTextureUnit(gpu::gles2::GLES2Interface* gl); private: + class DirectRasterBuffer; + class ImageRasterBuffer; + class PixelRasterBuffer; + struct Resource { + enum Origin { Internal, External, Delegated }; + Resource(); ~Resource(); Resource(unsigned texture_id, - gfx::Size size, + const gfx::Size& size, + Origin origin, GLenum target, GLenum filter, GLenum texture_pool, @@ -375,7 +395,13 @@ class CC_EXPORT ResourceProvider { ResourceFormat format); Resource(uint8_t* pixels, SharedBitmap* bitmap, - gfx::Size size, + const gfx::Size& size, + Origin origin, + GLenum filter, + GLint wrap_mode); + Resource(const SharedBitmapId& bitmap_id, + const gfx::Size& size, + Origin origin, GLenum filter, GLint wrap_mode); @@ -385,39 +411,138 @@ class CC_EXPORT ResourceProvider { unsigned gl_pixel_buffer_id; // Query used to determine when asynchronous set pixels complete. unsigned gl_upload_query_id; + // Query used to determine when read lock fence has passed. + unsigned gl_read_lock_query_id; TextureMailbox mailbox; ReleaseCallback release_callback; uint8_t* pixels; - uint8_t* pixel_buffer; int lock_for_read_count; int imported_count; int exported_count; - bool locked_for_write; - bool external; - bool marked_for_deletion; - bool pending_set_pixels; - bool set_pixels_completion_forced; - bool allocated; - bool enable_read_lock_fences; + bool dirty_image : 1; + bool locked_for_write : 1; + bool lost : 1; + bool marked_for_deletion : 1; + bool pending_set_pixels : 1; + bool set_pixels_completion_forced : 1; + bool allocated : 1; + bool enable_read_lock_fences : 1; + bool has_shared_bitmap_id : 1; + bool allow_overlay : 1; scoped_refptr<Fence> read_lock_fence; gfx::Size size; + Origin origin; GLenum target; // TODO(skyostil): Use a separate sampler object for filter state. GLenum original_filter; GLenum filter; unsigned image_id; unsigned bound_image_id; - bool dirty_image; GLenum texture_pool; GLint wrap_mode; - bool lost; TextureUsageHint hint; ResourceType type; ResourceFormat format; + SharedBitmapId shared_bitmap_id; SharedBitmap* shared_bitmap; + linked_ptr<DirectRasterBuffer> direct_raster_buffer; + linked_ptr<ImageRasterBuffer> image_raster_buffer; + linked_ptr<PixelRasterBuffer> pixel_raster_buffer; }; typedef base::hash_map<ResourceId, Resource> ResourceMap; + class RasterBuffer { + public: + virtual ~RasterBuffer(); + + SkCanvas* LockForWrite(); + // Returns true if canvas was written to while locked. + bool UnlockForWrite(); + + protected: + RasterBuffer(const Resource* resource, ResourceProvider* resource_provider); + const Resource* resource() const { return resource_; } + ResourceProvider* resource_provider() const { return resource_provider_; } + + virtual SkCanvas* DoLockForWrite() = 0; + virtual bool DoUnlockForWrite() = 0; + + private: + const Resource* resource_; + ResourceProvider* resource_provider_; + SkCanvas* locked_canvas_; + int canvas_save_count_; + }; + + class DirectRasterBuffer : public RasterBuffer { + public: + DirectRasterBuffer(const Resource* resource, + ResourceProvider* resource_provider, + bool use_distance_field_text); + virtual ~DirectRasterBuffer(); + + protected: + virtual SkCanvas* DoLockForWrite() OVERRIDE; + virtual bool DoUnlockForWrite() OVERRIDE; + skia::RefPtr<SkSurface> CreateSurface(); + + private: + skia::RefPtr<SkSurface> surface_; + uint32_t surface_generation_id_; + const bool use_distance_field_text_; + + DISALLOW_COPY_AND_ASSIGN(DirectRasterBuffer); + }; + + class BitmapRasterBuffer : public RasterBuffer { + public: + virtual ~BitmapRasterBuffer(); + + protected: + BitmapRasterBuffer(const Resource* resource, + ResourceProvider* resource_provider); + + virtual SkCanvas* DoLockForWrite() OVERRIDE; + virtual bool DoUnlockForWrite() OVERRIDE; + + virtual uint8_t* MapBuffer(int* stride) = 0; + virtual void UnmapBuffer() = 0; + + private: + uint8_t* mapped_buffer_; + SkBitmap raster_bitmap_; + uint32_t raster_bitmap_generation_id_; + skia::RefPtr<SkCanvas> raster_canvas_; + }; + + class ImageRasterBuffer : public BitmapRasterBuffer { + public: + ImageRasterBuffer(const Resource* resource, + ResourceProvider* resource_provider); + virtual ~ImageRasterBuffer(); + + protected: + virtual uint8_t* MapBuffer(int* stride) OVERRIDE; + virtual void UnmapBuffer() OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(ImageRasterBuffer); + }; + + class PixelRasterBuffer : public BitmapRasterBuffer { + public: + PixelRasterBuffer(const Resource* resource, + ResourceProvider* resource_provider); + virtual ~PixelRasterBuffer(); + + protected: + virtual uint8_t* MapBuffer(int* stride) OVERRIDE; + virtual void UnmapBuffer() OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(PixelRasterBuffer); + }; + static bool CompareResourceMapIteratorsByChildId( const std::pair<ReturnedResource, ResourceMap::iterator>& a, const std::pair<ReturnedResource, ResourceMap::iterator>& b); @@ -434,7 +559,7 @@ class CC_EXPORT ResourceProvider { }; typedef base::hash_map<int, Child> ChildMap; - bool ReadLockFenceHasPassed(Resource* resource) { + bool ReadLockFenceHasPassed(const Resource* resource) { return !resource->read_lock_fence.get() || resource->read_lock_fence->HasPassed(); } @@ -443,7 +568,8 @@ class CC_EXPORT ResourceProvider { SharedBitmapManager* shared_bitmap_manager, int highp_threshold_min, bool use_rgba_4444_texture_format, - size_t id_allocation_chunk_size); + size_t id_allocation_chunk_size, + bool use_distance_field_text); void CleanUpGLIfNeeded(); @@ -470,6 +596,26 @@ class CC_EXPORT ResourceProvider { void LazyCreate(Resource* resource); void LazyAllocate(Resource* resource); + // TODO(alokp): Move the implementation to PixelRasterBuffer. + // Acquire pixel buffer for resource. The pixel buffer can be used to + // set resource pixels without performing unnecessary copying. + void AcquirePixelBuffer(Resource* resource); + void ReleasePixelBuffer(Resource* resource); + // Map/unmap the acquired pixel buffer. + uint8_t* MapPixelBuffer(const Resource* resource, int* stride); + void UnmapPixelBuffer(const Resource* resource); + + // TODO(alokp): Move the implementation to ImageRasterBuffer. + // Acquire and release an image. The image allows direct + // manipulation of texture memory. + void AcquireImage(Resource* resource); + void ReleaseImage(Resource* resource); + // Maps the acquired image so that its pixels could be modified. + // Unmap is called when all pixels are set. + uint8_t* MapImage(const Resource* resource, int* stride); + void UnmapImage(const Resource* resource); + + void BindImageForSampling(Resource* resource); // Binds the given GL resource to a texture target for sampling using the // specified filter for both minification and magnification. Returns the // texture target used. The resource must be locked for reading. @@ -479,6 +625,7 @@ class CC_EXPORT ResourceProvider { // Returns NULL if the output_surface_ does not have a ContextProvider. gpu::gles2::GLES2Interface* ContextGL() const; + class GrContext* GrContext() const; OutputSurface* output_surface_; SharedBitmapManager* shared_bitmap_manager_; @@ -506,6 +653,10 @@ class CC_EXPORT ResourceProvider { scoped_ptr<IdAllocator> texture_id_allocator_; scoped_ptr<IdAllocator> buffer_id_allocator_; + bool use_sync_query_; + + bool use_distance_field_text_; + DISALLOW_COPY_AND_ASSIGN(ResourceProvider); }; |