Index: webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc |
diff --git a/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc b/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc |
index d0311b7f20b0ef62d8e027fcea5278b9a10236e8..742b58651898a55dc8243df711efc36289033aa0 100644 |
--- a/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc |
+++ b/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc |
@@ -27,14 +27,18 @@ |
#include "base/synchronization/lock.h" |
#include "gpu/command_buffer/client/gles2_implementation.h" |
#include "gpu/command_buffer/client/gles2_lib.h" |
+#include "gpu/command_buffer/client/gpu_memory_buffer_factory.h" |
+#include "gpu/command_buffer/client/image_factory.h" |
#include "gpu/command_buffer/client/transfer_buffer.h" |
#include "gpu/command_buffer/common/constants.h" |
#include "gpu/command_buffer/service/command_buffer_service.h" |
#include "gpu/command_buffer/service/context_group.h" |
#include "gpu/command_buffer/service/gl_context_virtual.h" |
#include "gpu/command_buffer/service/gpu_scheduler.h" |
+#include "gpu/command_buffer/service/image_manager.h" |
#include "gpu/command_buffer/service/transfer_buffer_manager.h" |
#include "ui/gl/gl_context.h" |
+#include "ui/gl/gl_image.h" |
#include "ui/gl/gl_share_group.h" |
#include "ui/gl/gl_surface.h" |
#include "webkit/gpu/gl_bindings_skia_cmd_buffer.h" |
@@ -44,6 +48,9 @@ using gpu::CommandBuffer; |
using gpu::CommandBufferService; |
using gpu::gles2::GLES2CmdHelper; |
using gpu::gles2::GLES2Implementation; |
+using gpu::gles2::ImageFactory; |
+using gpu::gles2::ImageManager; |
+using gpu::GpuMemoryBuffer; |
using gpu::GpuScheduler; |
using gpu::TransferBuffer; |
using gpu::TransferBufferManager; |
@@ -162,6 +169,8 @@ class GLInProcessContext { |
void OnContextLost(); |
+ ::gpu::gles2::ImageManager* GetImageManager(); |
+ |
base::Closure context_lost_callback_; |
scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; |
scoped_ptr<CommandBufferService> command_buffer_; |
@@ -172,6 +181,7 @@ class GLInProcessContext { |
scoped_ptr<GLES2CmdHelper> gles2_helper_; |
scoped_ptr<TransferBuffer> transfer_buffer_; |
scoped_ptr<GLES2Implementation> gles2_implementation_; |
+ scoped_ptr< ::gpu::gles2::ImageFactory> image_factory_; |
scoped_ptr<WebKit::WebGraphicsContext3D::WebGraphicsSyncPointCallback> |
signal_sync_point_callback_; |
Error last_error_; |
@@ -190,6 +200,68 @@ const size_t kStartTransferBufferSize = 4 * 1024 * 1024; |
const size_t kMinTransferBufferSize = 1 * 256 * 1024; |
const size_t kMaxTransferBufferSize = 16 * 1024 * 1024; |
+class ImageFactoryInProcess : public ImageFactory { |
+ public: |
+ ImageFactoryInProcess(); |
+ explicit ImageFactoryInProcess(ImageManager* image_manager); |
+ virtual ~ImageFactoryInProcess(); |
+ void SetImageManager(ImageManager* image_manager); |
+ |
+ // methods from ImageFactory |
+ virtual scoped_ptr<GpuMemoryBuffer> CreateGpuMemoryBuffer( |
+ int width, int height, GLenum internalformat, |
+ unsigned int* image_id) OVERRIDE; |
reveman
2013/05/14 01:21:04
nit: unsigned
kaanb
2013/05/14 18:12:11
Done.
|
+ virtual void DeleteGpuMemoryBuffer(unsigned int image_id) OVERRIDE; |
reveman
2013/05/14 01:21:04
nit: unsigned
kaanb
2013/05/14 18:12:11
Done.
|
+ private: |
+ scoped_refptr<ImageManager> image_manager_; |
+ unsigned int next_id_; |
reveman
2013/05/14 01:21:04
nit: unsigned
kaanb
2013/05/14 18:12:11
Done.
|
+ base::Lock lock_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ImageFactoryInProcess); |
+}; |
+ |
+ImageFactoryInProcess::ImageFactoryInProcess() |
+ : image_manager_(NULL), |
+ next_id_(0) { |
+} |
+ |
+ImageFactoryInProcess::ImageFactoryInProcess( |
+ ImageManager* image_manager) : image_manager_(image_manager), |
+ next_id_(0) { |
+} |
+ |
+ImageFactoryInProcess::~ImageFactoryInProcess() { |
+} |
+ |
+void ImageFactoryInProcess::SetImageManager(ImageManager* image_manager) { |
+ image_manager_ = image_manager; |
+} |
+ |
+scoped_ptr<GpuMemoryBuffer> ImageFactoryInProcess::CreateGpuMemoryBuffer( |
+ int width, int height, GLenum internalformat, unsigned int* image_id) { |
+ base::AutoLock scoped_lock(lock_); |
+ // TODO(kaanb): Check with reviewers if GL_RGBA8_OES is the right |
+ // constant to use. If not which header should we include to make GL_RGBA8 |
+ // visible? |
+ // For Android WebView we assume the |internalformat| will always be |
+ // GL_RGBA8_OES. |
+ DCHECK_EQ(GL_RGBA8_OES, internalformat); |
+ scoped_ptr<GpuMemoryBuffer> buffer = |
+ ::gpu::gles2::GetProcessDefaultGpuMemoryBufferFactory().Run( |
+ width, height); |
reveman
2013/05/14 01:21:04
nit: factory being a callback might be less confus
kaanb
2013/05/14 18:12:11
Done.
|
+ scoped_refptr<gfx::GLImage> gl_image = |
+ gfx::GLImage::CreateGLImageForGpuMemoryBuffer(buffer->GetNativeBuffer(), |
+ gfx::Size(width, height)); |
+ *image_id = ++next_id_; // Valid image_ids start from 1. |
+ image_manager_->AddImage(gl_image, *image_id); |
+ return buffer.Pass(); |
+} |
+ |
+void ImageFactoryInProcess::DeleteGpuMemoryBuffer(unsigned int image_id) { |
+ base::AutoLock scoped_lock(lock_); |
+ image_manager_->RemoveImage(image_id); |
+} |
+ |
// Singleton used to initialize and terminate the gles2 library. |
class GLES2Initializer { |
public: |
@@ -252,6 +324,9 @@ static base::LazyInstance< |
static bool g_use_virtualized_gl_context = false; |
+static base::LazyInstance<ImageFactoryInProcess> g_image_factory = |
+ LAZY_INSTANCE_INITIALIZER; |
+ |
namespace { |
// Also calls DetachFromThread on all GLES2Decoders before the lock is released |
@@ -417,6 +492,10 @@ GLES2Implementation* GLInProcessContext::GetImplementation() { |
return gles2_implementation_.get(); |
} |
+::gpu::gles2::ImageManager* GLInProcessContext::GetImageManager() { |
+ return decoder_->GetContextGroup()->image_manager(); |
+} |
+ |
GLInProcessContext::GLInProcessContext(bool share_resources) |
: last_error_(SUCCESS), |
share_resources_(share_resources), |
@@ -593,13 +672,21 @@ bool GLInProcessContext::Initialize( |
// Create a transfer buffer. |
transfer_buffer_.reset(new TransferBuffer(gles2_helper_.get())); |
+ if (share_resources_) { |
+ g_image_factory.Pointer()->SetImageManager(GetImageManager()); |
+ } else { |
+ // Create the image factory, this object retains its ownership. |
+ image_factory_.reset(new ImageFactoryInProcess(GetImageManager())); |
+ } |
+ |
// Create the object exposing the OpenGL API. |
gles2_implementation_.reset(new GLES2Implementation( |
gles2_helper_.get(), |
context_group ? context_group->GetImplementation()->share_group() : NULL, |
transfer_buffer_.get(), |
true, |
- false)); |
+ false, |
+ image_factory_.get())); |
if (!gles2_implementation_->Initialize( |
kStartTransferBufferSize, |
@@ -1096,6 +1183,13 @@ void WebGraphicsContext3DInProcessCommandBufferImpl::name( \ |
gl_->glname(a1, a2, a3); \ |
} |
+#define DELEGATE_TO_GL_3R(name, glname, t1, t2, t3, rt) \ |
+rt WebGraphicsContext3DInProcessCommandBufferImpl::name( \ |
+ t1 a1, t2 a2, t3 a3) { \ |
+ ClearContext(); \ |
+ return gl_->glname(a1, a2, a3); \ |
+} |
+ |
#define DELEGATE_TO_GL_4(name, glname, t1, t2, t3, t4) \ |
void WebGraphicsContext3DInProcessCommandBufferImpl::name( \ |
t1 a1, t2 a2, t3 a3, t4 a4) { \ |
@@ -1829,6 +1923,19 @@ void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() { |
} |
} |
+DELEGATE_TO_GL_3R(createImageCHROMIUM, CreateImageCHROMIUM, |
+ WGC3Dsizei, WGC3Dsizei, WGC3Denum, WGC3Duint); |
+ |
+DELEGATE_TO_GL_1(destroyImageCHROMIUM, DestroyImageCHROMIUM, WGC3Duint); |
+ |
+DELEGATE_TO_GL_3(getImageParameterivCHROMIUM, GetImageParameterivCHROMIUM, |
+ WGC3Duint, WGC3Denum, GLint*); |
+ |
+DELEGATE_TO_GL_2R(mapImageCHROMIUM, MapImageCHROMIUM, |
+ WGC3Duint, WGC3Denum, void*); |
+ |
+DELEGATE_TO_GL_1(unmapImageCHROMIUM, UnmapImageCHROMIUM, WGC3Duint); |
+ |
DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM, |
WebGLId, WGC3Dint, const WGC3Dchar*) |