diff options
18 files changed, 303 insertions, 10 deletions
diff --git a/android_webview/android_webview.gyp b/android_webview/android_webview.gyp index 65f33bc..e2b6b6f8 100644 --- a/android_webview/android_webview.gyp +++ b/android_webview/android_webview.gyp @@ -1,4 +1,4 @@ -# Copyright (c) 2009 The Chromium Authors. All rights reserved. +# Copyright 2009 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. { @@ -126,6 +126,10 @@ 'browser/browser_view_renderer_impl.h', 'browser/find_helper.cc', 'browser/find_helper.h', + 'browser/gpu_memory_buffer_factory_impl.cc', + 'browser/gpu_memory_buffer_factory_impl.h', + 'browser/gpu_memory_buffer_impl.cc', + 'browser/gpu_memory_buffer_impl.h', 'browser/icon_helper.cc', 'browser/icon_helper.h', 'browser/input_stream.h', @@ -161,6 +165,8 @@ 'common/aw_resource.h', 'common/aw_switches.cc', 'common/aw_switches.h', + 'common/gpu_memory_buffer_factory_proxy.cc', + 'common/gpu_memory_buffer_factory_proxy.h', 'common/render_view_messages.cc', 'common/render_view_messages.h', 'common/renderer_picture_map.cc', diff --git a/android_webview/browser/gpu_memory_buffer_factory_impl.cc b/android_webview/browser/gpu_memory_buffer_factory_impl.cc new file mode 100644 index 0000000..c860420 --- /dev/null +++ b/android_webview/browser/gpu_memory_buffer_factory_impl.cc @@ -0,0 +1,16 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "android_webview/browser/gpu_memory_buffer_factory_impl.h" + +#include "android_webview/browser/gpu_memory_buffer_impl.h" + +namespace android_webview { + +scoped_ptr<gfx::GpuMemoryBuffer> CreateGpuMemoryBuffer(gfx::Size size) { + scoped_ptr<GpuMemoryBufferImpl> result(new GpuMemoryBufferImpl(size)); + return result.PassAs<gfx::GpuMemoryBuffer>(); +} + +} // namespace android_webview diff --git a/android_webview/browser/gpu_memory_buffer_factory_impl.h b/android_webview/browser/gpu_memory_buffer_factory_impl.h new file mode 100644 index 0000000..545053b --- /dev/null +++ b/android_webview/browser/gpu_memory_buffer_factory_impl.h @@ -0,0 +1,22 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ANDROID_WEBVIEW_BROWSER_GPU_MEMORY_BUFFER_FACTORY_IMPL_H_ +#define ANDROID_WEBVIEW_BROWSER_GPU_MEMORY_BUFFER_FACTORY_IMPL_H_ + +#include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" +#include "ui/gl/gpu_memory_buffer.h" + +namespace gfx { +class Size; +} + +namespace android_webview { + +scoped_ptr<gfx::GpuMemoryBuffer> CreateGpuMemoryBuffer(gfx::Size size); + +} // namespace android_webview + +#endif // ANDROID_WEBVIEW_BROWSER_GPU_MEMORY_BUFFER_FACTORY_IMPL_H_ diff --git a/android_webview/browser/gpu_memory_buffer_impl.cc b/android_webview/browser/gpu_memory_buffer_impl.cc new file mode 100644 index 0000000..e67ad67 --- /dev/null +++ b/android_webview/browser/gpu_memory_buffer_impl.cc @@ -0,0 +1,61 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "android_webview/browser/gpu_memory_buffer_impl.h" + +#include "android_webview/browser/gpu_memory_buffer_factory_impl.h" +#include "android_webview/common/gpu_memory_buffer_factory_proxy.h" +#include "android_webview/public/browser/draw_gl.h" +#include "base/bind.h" +#include "base/logging.h" +#include "ui/gfx/size.h" +#include "ui/gl/gpu_memory_buffer.h" + +namespace android_webview { + +// Provides hardware rendering functions from the Android glue layer. +AwDrawGLFunctionTable* g_gl_draw_functions = NULL; + +GpuMemoryBufferImpl::GpuMemoryBufferImpl(const gfx::Size& size) + : buffer_id_(g_gl_draw_functions->create_graphic_buffer( + size.width(), size.height())), + size_(size) { +} + +GpuMemoryBufferImpl::~GpuMemoryBufferImpl() { + DCHECK(buffer_id_ != 0); + g_gl_draw_functions->release_graphic_buffer(buffer_id_); + buffer_id_ = 0; +} + +void GpuMemoryBufferImpl::MapForWrite(void** vaddr) { + DCHECK(buffer_id_ != 0); + int err = g_gl_draw_functions->lock_for_write(buffer_id_, vaddr); + DCHECK(err == 0); +} + +void GpuMemoryBufferImpl::Unmap() { + DCHECK(buffer_id_ != 0); + int err = g_gl_draw_functions->unlock(buffer_id_); + DCHECK(err == 0); +} + +void* GpuMemoryBufferImpl::GetNativeBuffer() { + DCHECK(buffer_id_ != 0); + return g_gl_draw_functions->get_native_buffer(buffer_id_); +} + +uint32 GpuMemoryBufferImpl::GetStride() { + DCHECK(buffer_id_ != 0); + return g_gl_draw_functions->get_stride(buffer_id_); +} + +// static +void GpuMemoryBufferImpl::SetAwDrawGLFunctionTable( + AwDrawGLFunctionTable* table) { + g_gl_draw_functions = table; + SetGpuMemoryBufferFactoryProxy(base::Bind(&CreateGpuMemoryBuffer)); +} + +} // namespace android_webview diff --git a/android_webview/browser/gpu_memory_buffer_impl.h b/android_webview/browser/gpu_memory_buffer_impl.h new file mode 100644 index 0000000..dc6f598 --- /dev/null +++ b/android_webview/browser/gpu_memory_buffer_impl.h @@ -0,0 +1,38 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ANDROID_WEBVIEW_BROWSER_GPU_MEMORY_BUFFER_IMPL_H_ +#define ANDROID_WEBVIEW_BROWSER_GPU_MEMORY_BUFFER_IMPL_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "ui/gfx/size.h" +#include "ui/gl/gpu_memory_buffer.h" + +struct AwDrawGLFunctionTable; + +namespace android_webview { + +class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { + public: + static void SetAwDrawGLFunctionTable(AwDrawGLFunctionTable* table); + GpuMemoryBufferImpl(const gfx::Size& size); + virtual ~GpuMemoryBufferImpl(); + + // methods from GpuMemoryBuffer + virtual void MapForWrite(void** vaddr) OVERRIDE; + virtual void Unmap() OVERRIDE; + virtual void* GetNativeBuffer() OVERRIDE; + virtual uint32 GetStride() OVERRIDE; + + private: + int buffer_id_; + gfx::Size size_; + + DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferImpl); +}; + +} // namespace android_webview + +#endif // ANDROID_WEBVIEW_BROWSER_GPU_MEMORY_BUFFER_IMPL_H_ diff --git a/android_webview/common/DEPS b/android_webview/common/DEPS index d0f9352..cbef04a 100644 --- a/android_webview/common/DEPS +++ b/android_webview/common/DEPS @@ -1,4 +1,6 @@ include_rules = [ "-android_webview", "+android_webview/common", + + "+ui/gl/gpu_memory_buffer.h", ] diff --git a/android_webview/common/aw_switches.cc b/android_webview/common/aw_switches.cc index c3fbf1b..2b8a332 100644 --- a/android_webview/common/aw_switches.cc +++ b/android_webview/common/aw_switches.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -9,4 +9,6 @@ namespace switches { const char kMergeUIAndRendererCompositorThreads[] = "merge-ui-and-compositor-threads"; +const char kUseZeroCopyBuffers[] = "use-zero-copy-buffers"; + } // namespace switches diff --git a/android_webview/common/aw_switches.h b/android_webview/common/aw_switches.h index c812122..a8df1ec 100644 --- a/android_webview/common/aw_switches.h +++ b/android_webview/common/aw_switches.h @@ -1,4 +1,4 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -10,6 +10,9 @@ namespace switches { // Merge the Browser UI and the renderer compositor threads. extern const char kMergeUIAndRendererCompositorThreads[]; +// Uses zero-copy buffers in graphics pipeline. +extern const char kUseZeroCopyBuffers[]; + } // namespace switches #endif // ANDROID_WEBVIEW_COMMON_AW_SWITCHES_H_ diff --git a/android_webview/common/gpu_memory_buffer_factory_proxy.cc b/android_webview/common/gpu_memory_buffer_factory_proxy.cc new file mode 100644 index 0000000..e10c042 --- /dev/null +++ b/android_webview/common/gpu_memory_buffer_factory_proxy.cc @@ -0,0 +1,27 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "android_webview/common/gpu_memory_buffer_factory_proxy.h" + +#include "android_webview/common/aw_switches.h" +#include "base/command_line.h" +#include "base/logging.h" + +namespace android_webview { + +gfx::GpuMemoryBuffer::Create* g_pixel_buffer_factory_ = NULL; + +const gfx::GpuMemoryBuffer::Create& GetGpuMemoryBufferFactoryProxy() { + return *g_pixel_buffer_factory_; +} + +void SetGpuMemoryBufferFactoryProxy( + const gfx::GpuMemoryBuffer::Create& factory) { + DCHECK(g_pixel_buffer_factory_ == NULL); + g_pixel_buffer_factory_ = + CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseZeroCopyBuffers) + ? new gfx::GpuMemoryBuffer::Create(factory) : NULL; +} + +} // namespace android_webview diff --git a/android_webview/common/gpu_memory_buffer_factory_proxy.h b/android_webview/common/gpu_memory_buffer_factory_proxy.h new file mode 100644 index 0000000..8e24f18 --- /dev/null +++ b/android_webview/common/gpu_memory_buffer_factory_proxy.h @@ -0,0 +1,19 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ANDROID_WEBVIEW_COMMON_GPU_MEMORY_BUFFER_FACTORY_PROXY_H_ +#define ANDROID_WEBVIEW_COMMON_GPU_MEMORY_BUFFER_FACTORY_PROXY_H_ + +#include "base/basictypes.h" +#include "ui/gl/gpu_memory_buffer.h" + +namespace android_webview { + +const gfx::GpuMemoryBuffer::Create& GetGpuMemoryBufferFactoryProxy(); +void SetGpuMemoryBufferFactoryProxy( + const gfx::GpuMemoryBuffer::Create& factory); + +} // namespace android_webview + +#endif // ANDROID_WEBVIEW_COMMON_GPU_MEMORY_BUFFER_FACTORY_PROXY_H_ diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java index b5d4e8d..bbf7101 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwContents.java +++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -348,6 +348,10 @@ public class AwContents { nativeSetAwDrawSWFunctionTable(functionTablePointer); } + public static void setAwDrawGLFunctionTable(int functionTablePointer) { + nativeSetAwDrawGLFunctionTable(functionTablePointer); + } + public static int getAwDrawGLFunction() { return nativeGetAwDrawGLFunction(); } @@ -1304,6 +1308,7 @@ public class AwContents { AwContentsClientBridge contentsClientBridge); private static native void nativeDestroy(int nativeAwContents); private static native void nativeSetAwDrawSWFunctionTable(int functionTablePointer); + private static native void nativeSetAwDrawGLFunctionTable(int functionTablePointer); private static native int nativeGetAwDrawGLFunction(); private native int nativeGetWebContents(int nativeAwContents); diff --git a/android_webview/native/aw_contents.cc b/android_webview/native/aw_contents.cc index 61c9345..6d2db78 100644 --- a/android_webview/native/aw_contents.cc +++ b/android_webview/native/aw_contents.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,6 +7,7 @@ #include "android_webview/browser/aw_browser_context.h" #include "android_webview/browser/aw_browser_main_parts.h" #include "android_webview/browser/browser_view_renderer_impl.h" +#include "android_webview/browser/gpu_memory_buffer_impl.h" #include "android_webview/browser/net_disk_cache_remover.h" #include "android_webview/browser/renderer_host/aw_render_view_host_ext.h" #include "android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.h" @@ -42,6 +43,7 @@ #include "ui/gfx/android/java_bitmap.h" struct AwDrawSWFunctionTable; +struct AwDrawGLFunctionTable; using base::android::AttachCurrentThread; using base::android::ConvertJavaStringToUTF16; @@ -181,6 +183,12 @@ void SetAwDrawSWFunctionTable(JNIEnv* env, jclass, jint function_table) { } // static +void SetAwDrawGLFunctionTable(JNIEnv* env, jclass, jint function_table) { + GpuMemoryBufferImpl::SetAwDrawGLFunctionTable( + reinterpret_cast<AwDrawGLFunctionTable*>(function_table)); +} + +// static jint GetAwDrawGLFunction(JNIEnv* env, jclass) { return reinterpret_cast<jint>(&DrawGLFunction); } diff --git a/android_webview/public/browser/draw_gl.h b/android_webview/public/browser/draw_gl.h index 441793e..bfbf8a4 100644 --- a/android_webview/public/browser/draw_gl.h +++ b/android_webview/public/browser/draw_gl.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -78,6 +78,29 @@ typedef void (AwDrawGLFunction)(int view_context, AwDrawGLInfo* draw_info, void* spare); +// Called to create a GraphicBuffer +typedef int AwCreateGraphicBufferFunction(int w, int h); +// Called to release a GraphicBuffer +typedef void AwReleaseGraphicBufferFunction(int buffer_id); +// Called to lock a GraphicBuffer for writing +typedef int AwLockForWriteFunction(int buffer_id, void** vaddr); +// Called to unlock a GraphicBuffer +typedef int AwUnlockFunction(int buffer_id); +// Called to get a native buffer pointer +typedef void* AwGetNativeBufferFunction(int buffer_id); +// Called to get the stride of the buffer +typedef unsigned int AwGetStrideFunction(int buffer_id); + +// Set of functions used in rendering in hardware mode +struct AwDrawGLFunctionTable { + AwCreateGraphicBufferFunction* create_graphic_buffer; + AwReleaseGraphicBufferFunction* release_graphic_buffer; + AwLockForWriteFunction* lock_for_write; + AwUnlockFunction* unlock; + AwGetNativeBufferFunction* get_native_buffer; + AwGetStrideFunction* get_stride; +}; + #ifdef __cplusplus } // extern "C" #endif diff --git a/android_webview/renderer/DEPS b/android_webview/renderer/DEPS index 31b0def..2263fab 100644 --- a/android_webview/renderer/DEPS +++ b/android_webview/renderer/DEPS @@ -6,7 +6,9 @@ include_rules = [ "+components/visitedlink/renderer", "+content/public/renderer", - + "+third_party/WebKit/Source/WebKit/chromium/public", "+third_party/WebKit/Source/Platform/chromium/public", + + "+ui/gl/gpu_memory_buffer.h", ] diff --git a/android_webview/renderer/aw_content_renderer_client.cc b/android_webview/renderer/aw_content_renderer_client.cc index ef07daf..773ea6a 100644 --- a/android_webview/renderer/aw_content_renderer_client.cc +++ b/android_webview/renderer/aw_content_renderer_client.cc @@ -1,10 +1,11 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "android_webview/renderer/aw_content_renderer_client.h" #include "android_webview/common/aw_resource.h" +#include "android_webview/common/gpu_memory_buffer_factory_proxy.h" #include "android_webview/common/url_constants.h" #include "android_webview/renderer/aw_render_view_ext.h" #include "android_webview/renderer/view_renderer.h" @@ -107,4 +108,9 @@ bool AwContentRendererClient::ShouldCreateCompositorInputHandler() const { return should_create_compositor_input_handler_; } +gfx::GpuMemoryBuffer::Create +AwContentRendererClient::GetGpuMemoryBufferFactory() const { + return GetGpuMemoryBufferFactoryProxy(); +} + } // namespace android_webview diff --git a/android_webview/renderer/aw_content_renderer_client.h b/android_webview/renderer/aw_content_renderer_client.h index 513e589..f616464 100644 --- a/android_webview/renderer/aw_content_renderer_client.h +++ b/android_webview/renderer/aw_content_renderer_client.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,8 +7,9 @@ #include "content/public/renderer/content_renderer_client.h" -#include "base/compiler_specific.h" #include "android_webview/renderer/aw_render_process_observer.h" +#include "base/compiler_specific.h" +#include "ui/gl/gpu_memory_buffer.h" namespace components { class VisitedLinkSlave; @@ -42,6 +43,7 @@ class AwContentRendererClient : public content::ContentRendererClient { virtual void PrefetchHostName(const char* hostname, size_t length) OVERRIDE; virtual MessageLoop* OverrideCompositorMessageLoop() const OVERRIDE; virtual bool ShouldCreateCompositorInputHandler() const OVERRIDE; + virtual gfx::GpuMemoryBuffer::Create GetGpuMemoryBufferFactory() const; private: scoped_ptr<AwRenderProcessObserver> aw_render_process_observer_; diff --git a/ui/gl/gl.gyp b/ui/gl/gl.gyp index ea9f280..3e87376 100644 --- a/ui/gl/gl.gyp +++ b/ui/gl/gl.gyp @@ -97,6 +97,7 @@ 'gl_surface_osmesa.h', 'gl_switches.cc', 'gl_switches.h', + 'gpu_memory_buffer.h', 'gpu_switching_manager.cc', 'gpu_switching_manager.h', 'safe_shared_memory_pool.h', diff --git a/ui/gl/gpu_memory_buffer.h b/ui/gl/gpu_memory_buffer.h new file mode 100644 index 0000000..2e24903 --- /dev/null +++ b/ui/gl/gpu_memory_buffer.h @@ -0,0 +1,50 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GL_GPU_MEMORY_BUFFER_H_ +#define UI_GL_GPU_MEMORY_BUFFER_H_ + +#include "base/basictypes.h" +#include "base/callback.h" +#include "base/memory/scoped_ptr.h" + +namespace gfx { +class Size; + +// Interface for creating and accessing a zero-copy GPU memory buffer. +// This design evolved from the generalization of GraphicBuffer API +// of Android framework. +// +// THREADING CONSIDERATIONS: +// +// This interface is thread-safe. However, multiple threads calling +// MapForWrite() simultaneously may result in undefined behavior +// and is not allowed. +class GpuMemoryBuffer { + public: + typedef base::Callback<scoped_ptr<gfx::GpuMemoryBuffer>(gfx::Size)> Create; + + // Frees a previously allocated buffer. Freeing a buffer that is still + // mapped in any process is undefined behavior. + virtual ~GpuMemoryBuffer() {} + + // Maps the buffer so the client can write the bitmap data in |*vaddr| + // subsequently. This call may block, for instance if the hardware needs + // to finish rendering or if CPU caches need to be synchronized. + virtual void MapForWrite(void** vaddr) = 0; + + // Unmaps the buffer. Called after all changes to the buffer are + // completed. + virtual void Unmap() = 0; + + // Returns the native pointer for the buffer. + virtual void* GetNativeBuffer() = 0; + + // Returns the stride in pixels for the buffer. + virtual uint32 GetStride() = 0; +}; + +} // namespace gfx + +#endif // UI_GL_GPU_MEMORY_BUFFER_H_ |