Chromium Code Reviews| Index: cc/resources/resource_provider.h |
| diff --git a/cc/resources/resource_provider.h b/cc/resources/resource_provider.h |
| index 7c94de45ea9a09ac05786d37cea81aa5e4d2d450..344528dc95efa99a431dfc433dc716e5758567e9 100644 |
| --- a/cc/resources/resource_provider.h |
| +++ b/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" |
| @@ -31,6 +32,8 @@ |
| #include "third_party/skia/include/core/SkCanvas.h" |
| #include "ui/gfx/size.h" |
| +class GrContext; |
| + |
| namespace gpu { |
| namespace gles { |
| class GLES2Interface; |
| @@ -307,33 +310,22 @@ 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); |
| + SkCanvas* MapDirectRasterBuffer(ResourceId id); |
| + void UnmapDirectRasterBuffer(ResourceId id); |
| - // Map/unmap the acquired pixel buffer. |
| - uint8_t* MapPixelBuffer(ResourceId id); |
| - void UnmapPixelBuffer(ResourceId id); |
| + SkCanvas* MapImageRasterBuffer(ResourceId id); |
| + void UnmapImageRasterBuffer(ResourceId id); |
| + |
| + void AcquirePixelRasterBuffer(ResourceId id); |
| + void ReleasePixelRasterBuffer(ResourceId id); |
| + SkCanvas* MapPixelRasterBuffer(ResourceId id); |
| + void 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); |
| - |
| // For tests only! This prevents detecting uninitialized reads. |
| // Use SetPixels or LockForWrite to allocate implicitly. |
| void AllocateForTesting(ResourceId id); |
| @@ -360,6 +352,10 @@ class CC_EXPORT ResourceProvider { |
| static GLint GetActiveTextureUnit(gpu::gles2::GLES2Interface* gl); |
| private: |
| + class DirectRasterBuffer; |
| + class ImageRasterBuffer; |
| + class PixelRasterBuffer; |
| + |
| struct Resource { |
| enum Origin { Internal, External, Delegated }; |
| @@ -417,9 +413,97 @@ class CC_EXPORT ResourceProvider { |
| ResourceType type; |
| ResourceFormat format; |
| SharedBitmap* shared_bitmap; |
| + linked_ptr<DirectRasterBuffer> direct_raster_buffer; |
| + linked_ptr<ImageRasterBuffer> image_raster_buffer; |
| + linked_ptr<PixelRasterBuffer> pixel_raster_buffer; |
|
reveman
2014/02/11 02:00:44
scoped_ptr would be preferred but I assume this ne
alokp
2014/02/11 07:05:21
Yes. It needs to be copyable.
|
| }; |
| typedef base::hash_map<ResourceId, Resource> ResourceMap; |
| + class RasterBuffer { |
| + public: |
| + virtual ~RasterBuffer(); |
| + |
| + SkCanvas* LockForWrite(); |
| + void 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 void 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); |
| + virtual ~DirectRasterBuffer(); |
| + |
| + protected: |
| + virtual SkCanvas* DoLockForWrite() OVERRIDE; |
| + virtual void DoUnlockForWrite() OVERRIDE; |
| + skia::RefPtr<SkSurface> CreateSurface(); |
| + |
| + private: |
| + skia::RefPtr<SkSurface> surface_; |
| + 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 void DoUnlockForWrite() OVERRIDE; |
| + |
| + virtual uint8_t* MapBuffer(int* stride) = 0; |
| + virtual void UnmapBuffer() = 0; |
| + |
| + private: |
| + uint8_t* buffer_; |
| + skia::RefPtr<SkCanvas> 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); |
| @@ -436,7 +520,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(); |
| } |
| @@ -471,8 +555,27 @@ class CC_EXPORT ResourceProvider { |
| void DestroyChildInternal(ChildMap::iterator it, DeleteStyle style); |
| void LazyCreate(Resource* resource); |
| void LazyAllocate(Resource* resource); |
| - void BindImageForSampling(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. |
| @@ -482,6 +585,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_; |