| Index: cc/resources/resource_provider.h
|
| diff --git a/cc/resources/resource_provider.h b/cc/resources/resource_provider.h
|
| index 4988bc05f855884765aabbdc22f0df299ad282f5..dd7e200e3e1e73b13541ebb2130f7a3396690dcf 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"
|
| @@ -32,6 +33,8 @@
|
| #include "third_party/skia/include/core/SkCanvas.h"
|
| #include "ui/gfx/size.h"
|
|
|
| +class GrContext;
|
| +
|
| namespace gpu {
|
| namespace gles {
|
| class GLES2Interface;
|
| @@ -314,33 +317,34 @@ 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.
|
| + // 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);
|
| + void UnmapImageRasterBuffer(ResourceId id);
|
| +
|
| + // Returns a canvas backed by pixel buffer.
|
| + // 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);
|
| + 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);
|
| @@ -367,6 +371,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 };
|
|
|
| @@ -431,9 +439,98 @@ class CC_EXPORT ResourceProvider {
|
| bool has_shared_bitmap_id;
|
| 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();
|
| + 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* mapped_buffer_;
|
| + SkBitmap raster_bitmap_;
|
| + 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);
|
| @@ -450,7 +547,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();
|
| }
|
| @@ -485,8 +582,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.
|
| @@ -496,6 +612,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_;
|
|
|