From 70da38b26b718679d02e579c8b0ea89fd38de06a Mon Sep 17 00:00:00 2001 From: tfarina Date: Thu, 8 Jan 2015 19:16:10 -0800 Subject: Extract WebGraphicsContext3DInProcessCommandBufferImpl from webkit/. This moves it into gpu/blink/ along side WebGraphicsContext3DImpl, consolidating more this code as we are in the process of removing webkit/ glue directory altogether. This is one more step on this way. BUG=338338 TEST=compositor_unittests, gpu_unittests, content_unittests R=jamesr@chromium.org,piman@chromium.org TBR=boliu@chromium.org Review URL: https://codereview.chromium.org/841773006 Cr-Commit-Position: refs/heads/master@{#310694} --- android_webview/browser/hardware_renderer.cc | 4 +- android_webview/lib/main/aw_main_delegate.cc | 1 - .../synchronous_compositor_factory_impl.cc | 10 +- .../synchronous_compositor_factory_impl.h | 6 +- content/browser/gpu/gpu_ipc_browsertests.cc | 2 +- .../renderer_host/compositor_impl_android.cc | 2 +- content/common/gpu/client/gl_helper_benchmark.cc | 6 +- content/common/gpu/client/gl_helper_unittest.cc | 4 +- .../gpu/client/gpu_in_process_context_tests.cc | 4 +- .../android/synchronous_compositor_factory.h | 7 +- content/renderer/renderer_blink_platform_impl.cc | 4 +- gpu/blink/BUILD.gn | 2 + gpu/blink/gpu_blink.gyp | 2 + ...hicscontext3d_in_process_command_buffer_impl.cc | 178 ++++++++++++++++++++ ...phicscontext3d_in_process_command_buffer_impl.h | 105 ++++++++++++ ui/compositor/BUILD.gn | 1 + ui/compositor/compositor.gyp | 1 + ui/compositor/test/DEPS | 1 + ui/compositor/test/in_process_context_factory.cc | 4 +- webkit/common/gpu/BUILD.gn | 2 - webkit/common/gpu/context_provider_in_process.cc | 5 +- webkit/common/gpu/context_provider_in_process.h | 10 +- ...hicscontext3d_in_process_command_buffer_impl.cc | 180 --------------------- ...phicscontext3d_in_process_command_buffer_impl.h | 110 ------------- webkit/common/gpu/webkit_gpu.gyp | 2 - 25 files changed, 325 insertions(+), 328 deletions(-) create mode 100644 gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.cc create mode 100644 gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h delete mode 100644 webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc delete mode 100644 webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h diff --git a/android_webview/browser/hardware_renderer.cc b/android_webview/browser/hardware_renderer.cc index 65da79b..ae2c056 100644 --- a/android_webview/browser/hardware_renderer.cc +++ b/android_webview/browser/hardware_renderer.cc @@ -20,6 +20,7 @@ #include "cc/scheduler/begin_frame_source.h" #include "cc/trees/layer_tree_host.h" #include "cc/trees/layer_tree_settings.h" +#include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h" #include "gpu/command_buffer/client/gl_in_process_context.h" #include "gpu/command_buffer/common/gles2_cmd_utils.h" #include "ui/gfx/frame_time.h" @@ -28,14 +29,13 @@ #include "ui/gfx/transform.h" #include "ui/gl/gl_bindings.h" #include "webkit/common/gpu/context_provider_in_process.h" -#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" namespace android_webview { namespace { using gpu_blink::WebGraphicsContext3DImpl; -using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; +using gpu_blink::WebGraphicsContext3DInProcessCommandBufferImpl; scoped_refptr CreateContext( scoped_refptr surface, diff --git a/android_webview/lib/main/aw_main_delegate.cc b/android_webview/lib/main/aw_main_delegate.cc index 8fc7ff5..2164521 100644 --- a/android_webview/lib/main/aw_main_delegate.cc +++ b/android_webview/lib/main/aw_main_delegate.cc @@ -28,7 +28,6 @@ #include "gpu/command_buffer/client/gl_in_process_context.h" #include "gpu/command_buffer/service/gpu_switches.h" #include "media/base/media_switches.h" -#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" namespace android_webview { diff --git a/content/browser/android/in_process/synchronous_compositor_factory_impl.cc b/content/browser/android/in_process/synchronous_compositor_factory_impl.cc index 654db41..0fdf66e 100644 --- a/content/browser/android/in_process/synchronous_compositor_factory_impl.cc +++ b/content/browser/android/in_process/synchronous_compositor_factory_impl.cc @@ -10,14 +10,16 @@ #include "content/browser/android/in_process/synchronous_compositor_output_surface.h" #include "content/public/browser/browser_thread.h" #include "content/renderer/gpu/frame_swap_message_queue.h" +#include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h" #include "gpu/command_buffer/client/gl_in_process_context.h" #include "gpu/command_buffer/common/gles2_cmd_utils.h" #include "ui/gl/android/surface_texture.h" #include "ui/gl/gl_surface.h" #include "ui/gl/gl_surface_stub.h" #include "webkit/common/gpu/context_provider_in_process.h" -#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" +using gpu_blink::WebGraphicsContext3DImpl; +using gpu_blink::WebGraphicsContext3DInProcessCommandBufferImpl; using webkit::gpu::ContextProviderWebContext; namespace content { @@ -35,9 +37,6 @@ blink::WebGraphicsContext3D::Attributes GetDefaultAttribs() { return attributes; } -using gpu_blink::WebGraphicsContext3DImpl; -using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; - scoped_ptr CreateOffscreenContext( const blink::WebGraphicsContext3D::Attributes& attributes) { const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; @@ -160,7 +159,6 @@ class SynchronousCompositorFactoryImpl::VideoContextProvider DISALLOW_COPY_AND_ASSIGN(VideoContextProvider); }; -using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; SynchronousCompositorFactoryImpl::SynchronousCompositorFactoryImpl() : record_full_layer_(true), @@ -236,7 +234,7 @@ SynchronousCompositorFactoryImpl::CreateStreamTextureFactory(int frame_id) { return factory; } -webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl* +WebGraphicsContext3DInProcessCommandBufferImpl* SynchronousCompositorFactoryImpl::CreateOffscreenGraphicsContext3D( const blink::WebGraphicsContext3D::Attributes& attributes) { return WrapContextWithAttributes(CreateOffscreenContext(attributes), diff --git a/content/browser/android/in_process/synchronous_compositor_factory_impl.h b/content/browser/android/in_process/synchronous_compositor_factory_impl.h index 3f03685..a3739bd 100644 --- a/content/browser/android/in_process/synchronous_compositor_factory_impl.h +++ b/content/browser/android/in_process/synchronous_compositor_factory_impl.h @@ -16,11 +16,9 @@ namespace gpu { class GLInProcessContext; } -namespace webkit { -namespace gpu { +namespace gpu_blink { class WebGraphicsContext3DInProcessCommandBufferImpl; } -} namespace content { @@ -46,7 +44,7 @@ class SynchronousCompositorFactoryImpl : public SynchronousCompositorFactory { const std::string& debug_name) override; virtual scoped_refptr CreateStreamTextureFactory( int view_id) override; - virtual webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl* + virtual gpu_blink::WebGraphicsContext3DInProcessCommandBufferImpl* CreateOffscreenGraphicsContext3D( const blink::WebGraphicsContext3D::Attributes& attributes) override; diff --git a/content/browser/gpu/gpu_ipc_browsertests.cc b/content/browser/gpu/gpu_ipc_browsertests.cc index 4731a20..817d732 100644 --- a/content/browser/gpu/gpu_ipc_browsertests.cc +++ b/content/browser/gpu/gpu_ipc_browsertests.cc @@ -12,8 +12,8 @@ #include "content/public/browser/gpu_data_manager.h" #include "content/public/common/content_switches.h" #include "content/public/test/content_browser_test.h" +#include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h" #include "ui/gl/gl_switches.h" -#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" namespace { diff --git a/content/browser/renderer_host/compositor_impl_android.cc b/content/browser/renderer_host/compositor_impl_android.cc index f1fced0..3745a37 100644 --- a/content/browser/renderer_host/compositor_impl_android.cc +++ b/content/browser/renderer_host/compositor_impl_android.cc @@ -47,6 +47,7 @@ #include "content/common/gpu/gpu_process_launch_causes.h" #include "content/common/host_shared_bitmap_manager.h" #include "content/public/browser/android/compositor_client.h" +#include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h" #include "gpu/command_buffer/client/context_support.h" #include "gpu/command_buffer/client/gles2_interface.h" #include "third_party/khronos/GLES2/gl2.h" @@ -56,7 +57,6 @@ #include "ui/gfx/android/device_display_info.h" #include "ui/gfx/frame_time.h" #include "webkit/common/gpu/context_provider_in_process.h" -#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" namespace content { diff --git a/content/common/gpu/client/gl_helper_benchmark.cc b/content/common/gpu/client/gl_helper_benchmark.cc index a394fcf..75a204d 100644 --- a/content/common/gpu/client/gl_helper_benchmark.cc +++ b/content/common/gpu/client/gl_helper_benchmark.cc @@ -26,12 +26,12 @@ #include "content/common/gpu/client/gl_helper_scaling.h" #include "content/public/test/unittest_test_suite.h" #include "content/test/content_test_suite.h" +#include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkTypes.h" #include "ui/gfx/codec/png_codec.h" #include "ui/gl/gl_surface.h" -#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" #if defined(OS_MACOSX) #include "base/mac/scoped_nsautorelease_pool.h" @@ -59,7 +59,7 @@ class GLHelperTest : public testing::Test { void SetUp() override { WebGraphicsContext3D::Attributes attributes; bool lose_context_when_out_of_memory = false; - context_ = webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl:: + context_ = gpu_blink::WebGraphicsContext3DInProcessCommandBufferImpl:: CreateOffscreenContext(attributes, lose_context_when_out_of_memory); context_->InitializeOnCurrentThread(); @@ -107,7 +107,7 @@ class GLHelperTest : public testing::Test { base::CloseFile(f); } - scoped_ptr + scoped_ptr context_; scoped_ptr helper_; scoped_ptr helper_scaling_; diff --git a/content/common/gpu/client/gl_helper_unittest.cc b/content/common/gpu/client/gl_helper_unittest.cc index ba7d4fc..4796993 100644 --- a/content/common/gpu/client/gl_helper_unittest.cc +++ b/content/common/gpu/client/gl_helper_unittest.cc @@ -29,12 +29,12 @@ #include "content/common/gpu/client/gl_helper_scaling.h" #include "content/public/test/unittest_test_suite.h" #include "content/test/content_test_suite.h" +#include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h" #include "media/base/video_frame.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkTypes.h" #include "ui/gl/gl_implementation.h" -#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" #if defined(OS_MACOSX) #include "base/mac/scoped_nsautorelease_pool.h" @@ -44,7 +44,7 @@ namespace content { using blink::WebGLId; using blink::WebGraphicsContext3D; -using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; +using gpu_blink::WebGraphicsContext3DInProcessCommandBufferImpl; content::GLHelper::ScalerQuality kQualities[] = { content::GLHelper::SCALER_QUALITY_BEST, diff --git a/content/common/gpu/client/gpu_in_process_context_tests.cc b/content/common/gpu/client/gpu_in_process_context_tests.cc index 3e134f5..6e74057 100644 --- a/content/common/gpu/client/gpu_in_process_context_tests.cc +++ b/content/common/gpu/client/gpu_in_process_context_tests.cc @@ -8,13 +8,13 @@ #include #include "content/public/test/unittest_test_suite.h" +#include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/gl/gl_surface.h" -#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" namespace { -using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; +using gpu_blink::WebGraphicsContext3DInProcessCommandBufferImpl; class ContextTestBase : public testing::Test { public: diff --git a/content/renderer/android/synchronous_compositor_factory.h b/content/renderer/android/synchronous_compositor_factory.h index 6eb6430..3ee74a0 100644 --- a/content/renderer/android/synchronous_compositor_factory.h +++ b/content/renderer/android/synchronous_compositor_factory.h @@ -19,10 +19,13 @@ class ContextProvider; class OutputSurface; } +namespace gpu_blink { +class WebGraphicsContext3DInProcessCommandBufferImpl; +} + namespace webkit { namespace gpu { class ContextProviderWebContext; -class WebGraphicsContext3DInProcessCommandBufferImpl; } } @@ -62,7 +65,7 @@ class SynchronousCompositorFactory { const std::string& debug_name) = 0; virtual scoped_refptr CreateStreamTextureFactory( int frame_id) = 0; - virtual webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl* + virtual gpu_blink::WebGraphicsContext3DInProcessCommandBufferImpl* CreateOffscreenGraphicsContext3D( const blink::WebGraphicsContext3D::Attributes& attributes) = 0; diff --git a/content/renderer/renderer_blink_platform_impl.cc b/content/renderer/renderer_blink_platform_impl.cc index 9130436..2894dc6 100644 --- a/content/renderer/renderer_blink_platform_impl.cc +++ b/content/renderer/renderer_blink_platform_impl.cc @@ -84,7 +84,7 @@ #if defined(OS_ANDROID) #include "content/renderer/android/synchronous_compositor_factory.h" #include "content/renderer/media/android/audio_decoder_android.h" -#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" +#include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h" #endif #if defined(OS_MACOSX) @@ -964,7 +964,7 @@ RendererBlinkPlatformImpl::createOffscreenGraphicsContext3D( #if defined(OS_ANDROID) if (SynchronousCompositorFactory* factory = SynchronousCompositorFactory::GetInstance()) { - scoped_ptr + scoped_ptr in_process_context( factory->CreateOffscreenGraphicsContext3D(attributes)); if (!in_process_context || diff --git a/gpu/blink/BUILD.gn b/gpu/blink/BUILD.gn index 3d0e77a..464061c 100644 --- a/gpu/blink/BUILD.gn +++ b/gpu/blink/BUILD.gn @@ -10,6 +10,8 @@ component("blink") { "gpu_blink_export.h", "webgraphicscontext3d_impl.cc", "webgraphicscontext3d_impl.h", + "webgraphicscontext3d_in_process_command_buffer_impl.cc", + "webgraphicscontext3d_in_process_command_buffer_impl.h", ] defines = [ "GPU_BLINK_IMPLEMENTATION" ] diff --git a/gpu/blink/gpu_blink.gyp b/gpu/blink/gpu_blink.gyp index a1d3cb5..06a7c12 100644 --- a/gpu/blink/gpu_blink.gyp +++ b/gpu/blink/gpu_blink.gyp @@ -35,6 +35,8 @@ 'gpu_blink_export.h', 'webgraphicscontext3d_impl.cc', 'webgraphicscontext3d_impl.h', + 'webgraphicscontext3d_in_process_command_buffer_impl.cc', + 'webgraphicscontext3d_in_process_command_buffer_impl.h', ], 'defines': [ 'GPU_BLINK_IMPLEMENTATION', diff --git a/gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.cc b/gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.cc new file mode 100644 index 0000000..386d349 --- /dev/null +++ b/gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.cc @@ -0,0 +1,178 @@ +// Copyright (c) 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 "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h" + +#include +#ifndef GL_GLEXT_PROTOTYPES +#define GL_GLEXT_PROTOTYPES 1 +#endif +#include +#include + +#include + +#include "base/atomicops.h" +#include "base/bind.h" +#include "base/bind_helpers.h" +#include "base/callback.h" +#include "base/logging.h" +#include "gpu/command_buffer/client/gles2_implementation.h" +#include "gpu/command_buffer/common/gles2_cmd_utils.h" +#include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" +#include "ui/gfx/geometry/size.h" +#include "ui/gl/gl_implementation.h" + +using gpu::gles2::GLES2Implementation; +using gpu::GLInProcessContext; + +namespace gpu_blink { + +// static +scoped_ptr +WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext( + const blink::WebGraphicsContext3D::Attributes& attributes, + bool lose_context_when_out_of_memory, + gfx::AcceleratedWidget window) { + DCHECK_NE(gfx::GetGLImplementation(), gfx::kGLImplementationNone); + bool is_offscreen = false; + return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl( + scoped_ptr< ::gpu::GLInProcessContext>(), + attributes, + lose_context_when_out_of_memory, + is_offscreen, + window)); +} + +// static +scoped_ptr +WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext( + const blink::WebGraphicsContext3D::Attributes& attributes, + bool lose_context_when_out_of_memory) { + bool is_offscreen = true; + return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl( + scoped_ptr< ::gpu::GLInProcessContext>(), + attributes, + lose_context_when_out_of_memory, + is_offscreen, + gfx::kNullAcceleratedWidget)); +} + +scoped_ptr +WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext( + scoped_ptr< ::gpu::GLInProcessContext> context, + const blink::WebGraphicsContext3D::Attributes& attributes) { + bool lose_context_when_out_of_memory = false; // Not used. + bool is_offscreen = true; // Not used. + return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl( + context.Pass(), + attributes, + lose_context_when_out_of_memory, + is_offscreen, + gfx::kNullAcceleratedWidget /* window. Not used. */)); +} + +WebGraphicsContext3DInProcessCommandBufferImpl:: + WebGraphicsContext3DInProcessCommandBufferImpl( + scoped_ptr< ::gpu::GLInProcessContext> context, + const blink::WebGraphicsContext3D::Attributes& attributes, + bool lose_context_when_out_of_memory, + bool is_offscreen, + gfx::AcceleratedWidget window) + : share_resources_(attributes.shareResources), + webgl_context_(attributes.webGL), + is_offscreen_(is_offscreen), + window_(window), + context_(context.Pass()) { + ConvertAttributes(attributes, &attribs_); + attribs_.lose_context_when_out_of_memory = lose_context_when_out_of_memory; +} + +WebGraphicsContext3DInProcessCommandBufferImpl:: + ~WebGraphicsContext3DInProcessCommandBufferImpl() { +} + +size_t WebGraphicsContext3DInProcessCommandBufferImpl::GetMappedMemoryLimit() { + return context_->GetMappedMemoryLimit(); +} + +bool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() { + if (initialized_) + return true; + + if (initialize_failed_) + return false; + + if (!context_) { + // TODO(kbr): More work will be needed in this implementation to + // properly support GPU switching. Like in the out-of-process + // command buffer implementation, all previously created contexts + // will need to be lost either when the first context requesting the + // discrete GPU is created, or the last one is destroyed. + gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; + context_.reset(GLInProcessContext::Create( + NULL, /* service */ + NULL, /* surface */ + is_offscreen_, + window_, + gfx::Size(1, 1), + NULL, /* share_context */ + share_resources_, + attribs_, + gpu_preference, + ::gpu::GLInProcessContextSharedMemoryLimits(), + nullptr, + nullptr)); + } + + if (context_) { + base::Closure context_lost_callback = base::Bind( + &WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost, + base::Unretained(this)); + context_->SetContextLostCallback(context_lost_callback); + } else { + initialize_failed_ = true; + return false; + } + + real_gl_ = context_->GetImplementation(); + setGLInterface(real_gl_); + + if (real_gl_ && webgl_context_) + real_gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation"); + + initialized_ = true; + return true; +} + +bool +WebGraphicsContext3DInProcessCommandBufferImpl::InitializeOnCurrentThread() { + if (!MaybeInitializeGL()) + return false; + return context_ && !isContextLost(); +} + +bool WebGraphicsContext3DInProcessCommandBufferImpl::isContextLost() { + return context_lost_reason_ != GL_NO_ERROR; +} + +WGC3Denum WebGraphicsContext3DInProcessCommandBufferImpl:: + getGraphicsResetStatusARB() { + return context_lost_reason_; +} + +::gpu::ContextSupport* +WebGraphicsContext3DInProcessCommandBufferImpl::GetContextSupport() { + return real_gl_; +} + +void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() { + // TODO(kbr): improve the precision here. + context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB; + if (context_lost_callback_) { + context_lost_callback_->onContextLost(); + } +} + +} // namespace gpu_blink diff --git a/gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h b/gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h new file mode 100644 index 0000000..94816a8 --- /dev/null +++ b/gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h @@ -0,0 +1,105 @@ +// Copyright (c) 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. + +#ifndef GPU_BLINK_WEBGRAPHICSCONTEXT3D_IN_PROCESS_COMMAND_BUFFER_IMPL_H_ +#define GPU_BLINK_WEBGRAPHICSCONTEXT3D_IN_PROCESS_COMMAND_BUFFER_IMPL_H_ + +#include + +#include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" +#include "gpu/blink/gpu_blink_export.h" +#include "gpu/blink/webgraphicscontext3d_impl.h" +#include "gpu/command_buffer/client/gl_in_process_context.h" +#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" +#include "third_party/WebKit/public/platform/WebString.h" +#include "ui/gfx/native_widget_types.h" + +namespace gpu { +class ContextSupport; +class GLInProcessContext; + +namespace gles2 { +class GLES2Interface; +class GLES2Implementation; +struct ContextCreationAttribHelper; +} +} + +namespace gpu_blink { + +class GPU_BLINK_EXPORT WebGraphicsContext3DInProcessCommandBufferImpl + : public WebGraphicsContext3DImpl { + public: + enum MappedMemoryReclaimLimit { + kNoLimit = 0, + }; + + static scoped_ptr + CreateViewContext( + const blink::WebGraphicsContext3D::Attributes& attributes, + bool lose_context_when_out_of_memory, + gfx::AcceleratedWidget window); + + static scoped_ptr + CreateOffscreenContext( + const blink::WebGraphicsContext3D::Attributes& attributes, + bool lose_context_when_out_of_memory); + + static scoped_ptr + WrapContext( + scoped_ptr< ::gpu::GLInProcessContext> context, + const blink::WebGraphicsContext3D::Attributes& attributes); + + virtual ~WebGraphicsContext3DInProcessCommandBufferImpl(); + + size_t GetMappedMemoryLimit(); + + bool InitializeOnCurrentThread(); + + //---------------------------------------------------------------------- + // WebGraphicsContext3D methods + virtual bool isContextLost(); + + virtual WGC3Denum getGraphicsResetStatusARB(); + + ::gpu::ContextSupport* GetContextSupport(); + + ::gpu::gles2::GLES2Implementation* GetImplementation() { + return real_gl_; + } + + private: + WebGraphicsContext3DInProcessCommandBufferImpl( + scoped_ptr< ::gpu::GLInProcessContext> context, + const blink::WebGraphicsContext3D::Attributes& attributes, + bool lose_context_when_out_of_memory, + bool is_offscreen, + gfx::AcceleratedWidget window); + + void OnContextLost(); + + bool MaybeInitializeGL(); + + // Used to try to find bugs in code that calls gl directly through the gl api + // instead of going through WebGraphicsContext3D. + void ClearContext(); + + ::gpu::gles2::ContextCreationAttribHelper attribs_; + bool share_resources_; + bool webgl_context_; + + bool is_offscreen_; + // Only used when not offscreen. + gfx::AcceleratedWidget window_; + + // The context we use for OpenGL rendering. + scoped_ptr< ::gpu::GLInProcessContext> context_; + // The GLES2Implementation we use for OpenGL rendering. + ::gpu::gles2::GLES2Implementation* real_gl_; +}; + +} // namespace gpu_blink + +#endif // GPU_BLINK_WEBGRAPHICSCONTEXT3D_IN_PROCESS_COMMAND_BUFFER_IMPL_H_ diff --git a/ui/compositor/BUILD.gn b/ui/compositor/BUILD.gn index 8461f75..047aa16 100644 --- a/ui/compositor/BUILD.gn +++ b/ui/compositor/BUILD.gn @@ -112,6 +112,7 @@ source_set("test_support") { "//cc", "//cc/surfaces", "//cc:test_support", + "//gpu/blink", "//skia", "//testing/gtest", "//third_party/WebKit/public:blink_minimal", diff --git a/ui/compositor/compositor.gyp b/ui/compositor/compositor.gyp index 76cb687..6959709 100644 --- a/ui/compositor/compositor.gyp +++ b/ui/compositor/compositor.gyp @@ -90,6 +90,7 @@ '<(DEPTH)/cc/cc.gyp:cc', '<(DEPTH)/cc/cc.gyp:cc_surfaces', '<(DEPTH)/cc/cc_tests.gyp:cc_test_support', + '<(DEPTH)/gpu/blink/gpu_blink.gyp:gpu_blink', '<(DEPTH)/skia/skia.gyp:skia', '<(DEPTH)/testing/gtest.gyp:gtest', '<(DEPTH)/third_party/WebKit/public/blink.gyp:blink_minimal', diff --git a/ui/compositor/test/DEPS b/ui/compositor/test/DEPS index c337a49..7f9b273 100644 --- a/ui/compositor/test/DEPS +++ b/ui/compositor/test/DEPS @@ -1,4 +1,5 @@ include_rules = [ + "+gpu/blink", "+gpu/command_buffer/client", "+webkit/common/gpu", ] diff --git a/ui/compositor/test/in_process_context_factory.cc b/ui/compositor/test/in_process_context_factory.cc index 819f9e8..7dc5a4f 100644 --- a/ui/compositor/test/in_process_context_factory.cc +++ b/ui/compositor/test/in_process_context_factory.cc @@ -13,6 +13,7 @@ #include "cc/surfaces/surface_id_allocator.h" #include "cc/test/pixel_test_output_surface.h" #include "cc/test/test_shared_bitmap_manager.h" +#include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h" #include "gpu/command_buffer/client/context_support.h" #include "gpu/command_buffer/client/gles2_interface.h" #include "ui/compositor/compositor_switches.h" @@ -21,7 +22,6 @@ #include "ui/gl/gl_surface.h" #include "webkit/common/gpu/context_provider_in_process.h" #include "webkit/common/gpu/grcontext_for_webgraphicscontext3d.h" -#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" namespace ui { namespace { @@ -94,7 +94,7 @@ void InProcessContextFactory::CreateOutputSurface( attrs.shareResources = true; bool lose_context_when_out_of_memory = true; - using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; + using gpu_blink::WebGraphicsContext3DInProcessCommandBufferImpl; scoped_ptr context3d( WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext( attrs, lose_context_when_out_of_memory, compositor->widget())); diff --git a/webkit/common/gpu/BUILD.gn b/webkit/common/gpu/BUILD.gn index d8a7e18..43e0a64 100644 --- a/webkit/common/gpu/BUILD.gn +++ b/webkit/common/gpu/BUILD.gn @@ -12,8 +12,6 @@ component("gpu") { "context_provider_web_context.h", "grcontext_for_webgraphicscontext3d.cc", "grcontext_for_webgraphicscontext3d.h", - "webgraphicscontext3d_in_process_command_buffer_impl.cc", - "webgraphicscontext3d_in_process_command_buffer_impl.h", ] defines = [ "WEBKIT_GPU_IMPLEMENTATION" ] diff --git a/webkit/common/gpu/context_provider_in_process.cc b/webkit/common/gpu/context_provider_in_process.cc index 9eb6e41..23fc066 100644 --- a/webkit/common/gpu/context_provider_in_process.cc +++ b/webkit/common/gpu/context_provider_in_process.cc @@ -14,6 +14,8 @@ #include "gpu/command_buffer/client/gles2_implementation.h" #include "webkit/common/gpu/grcontext_for_webgraphicscontext3d.h" +using gpu_blink::WebGraphicsContext3DInProcessCommandBufferImpl; + namespace webkit { namespace gpu { @@ -152,8 +154,7 @@ class GrContext* ContextProviderInProcess::GrContext() { if (gr_context_) return gr_context_->get(); - gr_context_.reset( - new webkit::gpu::GrContextForWebGraphicsContext3D(context3d_.get())); + gr_context_.reset(new GrContextForWebGraphicsContext3D(context3d_.get())); return gr_context_->get(); } diff --git a/webkit/common/gpu/context_provider_in_process.h b/webkit/common/gpu/context_provider_in_process.h index 2867309..0e38083 100644 --- a/webkit/common/gpu/context_provider_in_process.h +++ b/webkit/common/gpu/context_provider_in_process.h @@ -9,8 +9,8 @@ #include "base/memory/scoped_ptr.h" #include "base/synchronization/lock.h" #include "base/threading/thread_checker.h" +#include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h" #include "webkit/common/gpu/context_provider_web_context.h" -#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" #include "webkit/common/gpu/webkit_gpu_export.h" namespace blink { class WebGraphicsContext3D; } @@ -23,7 +23,8 @@ class WEBKIT_GPU_EXPORT ContextProviderInProcess : NON_EXPORTED_BASE(public ContextProviderWebContext) { public: static scoped_refptr Create( - scoped_ptr context3d, + scoped_ptr + context3d, const std::string& debug_name); // Uses default attributes for creating an offscreen context. @@ -49,7 +50,8 @@ class WEBKIT_GPU_EXPORT ContextProviderInProcess protected: ContextProviderInProcess( - scoped_ptr context3d, + scoped_ptr + context3d, const std::string& debug_name); ~ContextProviderInProcess() override; @@ -61,7 +63,7 @@ class WEBKIT_GPU_EXPORT ContextProviderInProcess base::ThreadChecker main_thread_checker_; base::ThreadChecker context_thread_checker_; - scoped_ptr + scoped_ptr context3d_; scoped_ptr gr_context_; diff --git a/webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc b/webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc deleted file mode 100644 index 3bf38f8..0000000 --- a/webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc +++ /dev/null @@ -1,180 +0,0 @@ -// Copyright (c) 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 "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" - -#include -#ifndef GL_GLEXT_PROTOTYPES -#define GL_GLEXT_PROTOTYPES 1 -#endif -#include -#include - -#include - -#include "base/atomicops.h" -#include "base/bind.h" -#include "base/bind_helpers.h" -#include "base/callback.h" -#include "base/logging.h" -#include "gpu/command_buffer/client/gles2_implementation.h" -#include "gpu/command_buffer/common/gles2_cmd_utils.h" -#include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" -#include "ui/gfx/geometry/size.h" -#include "ui/gl/gl_implementation.h" - -using gpu::gles2::GLES2Implementation; -using gpu::GLInProcessContext; - -namespace webkit { -namespace gpu { - -// static -scoped_ptr -WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext( - const blink::WebGraphicsContext3D::Attributes& attributes, - bool lose_context_when_out_of_memory, - gfx::AcceleratedWidget window) { - DCHECK_NE(gfx::GetGLImplementation(), gfx::kGLImplementationNone); - bool is_offscreen = false; - return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl( - scoped_ptr< ::gpu::GLInProcessContext>(), - attributes, - lose_context_when_out_of_memory, - is_offscreen, - window)); -} - -// static -scoped_ptr -WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext( - const blink::WebGraphicsContext3D::Attributes& attributes, - bool lose_context_when_out_of_memory) { - bool is_offscreen = true; - return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl( - scoped_ptr< ::gpu::GLInProcessContext>(), - attributes, - lose_context_when_out_of_memory, - is_offscreen, - gfx::kNullAcceleratedWidget)); -} - -scoped_ptr -WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext( - scoped_ptr< ::gpu::GLInProcessContext> context, - const blink::WebGraphicsContext3D::Attributes& attributes) { - bool lose_context_when_out_of_memory = false; // Not used. - bool is_offscreen = true; // Not used. - return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl( - context.Pass(), - attributes, - lose_context_when_out_of_memory, - is_offscreen, - gfx::kNullAcceleratedWidget /* window. Not used. */)); -} - -WebGraphicsContext3DInProcessCommandBufferImpl:: - WebGraphicsContext3DInProcessCommandBufferImpl( - scoped_ptr< ::gpu::GLInProcessContext> context, - const blink::WebGraphicsContext3D::Attributes& attributes, - bool lose_context_when_out_of_memory, - bool is_offscreen, - gfx::AcceleratedWidget window) - : share_resources_(attributes.shareResources), - webgl_context_(attributes.webGL), - is_offscreen_(is_offscreen), - window_(window), - context_(context.Pass()) { - ConvertAttributes(attributes, &attribs_); - attribs_.lose_context_when_out_of_memory = lose_context_when_out_of_memory; -} - -WebGraphicsContext3DInProcessCommandBufferImpl:: - ~WebGraphicsContext3DInProcessCommandBufferImpl() { -} - -size_t WebGraphicsContext3DInProcessCommandBufferImpl::GetMappedMemoryLimit() { - return context_->GetMappedMemoryLimit(); -} - -bool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() { - if (initialized_) - return true; - - if (initialize_failed_) - return false; - - if (!context_) { - // TODO(kbr): More work will be needed in this implementation to - // properly support GPU switching. Like in the out-of-process - // command buffer implementation, all previously created contexts - // will need to be lost either when the first context requesting the - // discrete GPU is created, or the last one is destroyed. - gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; - context_.reset(GLInProcessContext::Create( - NULL, /* service */ - NULL, /* surface */ - is_offscreen_, - window_, - gfx::Size(1, 1), - NULL, /* share_context */ - share_resources_, - attribs_, - gpu_preference, - ::gpu::GLInProcessContextSharedMemoryLimits(), - nullptr, - nullptr)); - } - - if (context_) { - base::Closure context_lost_callback = base::Bind( - &WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost, - base::Unretained(this)); - context_->SetContextLostCallback(context_lost_callback); - } else { - initialize_failed_ = true; - return false; - } - - real_gl_ = context_->GetImplementation(); - setGLInterface(real_gl_); - - if (real_gl_ && webgl_context_) - real_gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation"); - - initialized_ = true; - return true; -} - -bool -WebGraphicsContext3DInProcessCommandBufferImpl::InitializeOnCurrentThread() { - if (!MaybeInitializeGL()) - return false; - return context_ && !isContextLost(); -} - -bool WebGraphicsContext3DInProcessCommandBufferImpl::isContextLost() { - return context_lost_reason_ != GL_NO_ERROR; -} - -WGC3Denum WebGraphicsContext3DInProcessCommandBufferImpl:: - getGraphicsResetStatusARB() { - return context_lost_reason_; -} - -::gpu::ContextSupport* -WebGraphicsContext3DInProcessCommandBufferImpl::GetContextSupport() { - return real_gl_; -} - -void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() { - // TODO(kbr): improve the precision here. - context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB; - if (context_lost_callback_) { - context_lost_callback_->onContextLost(); - } -} - -} // namespace gpu -} // namespace webkit diff --git a/webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h b/webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h deleted file mode 100644 index 1779a5b..0000000 --- a/webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright (c) 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. - -#ifndef WEBKIT_COMMON_GPU_WEBGRAPHICSCONTEXT3D_IN_PROCESS_COMMAND_BUFFER_IMPL_H_ -#define WEBKIT_COMMON_GPU_WEBGRAPHICSCONTEXT3D_IN_PROCESS_COMMAND_BUFFER_IMPL_H_ - -#include - -#include "base/compiler_specific.h" -#include "base/memory/scoped_ptr.h" -#include "gpu/blink/webgraphicscontext3d_impl.h" -#include "gpu/command_buffer/client/gl_in_process_context.h" -#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" -#include "third_party/WebKit/public/platform/WebString.h" -#include "ui/gfx/native_widget_types.h" -#include "webkit/common/gpu/webkit_gpu_export.h" - -namespace gpu { -class ContextSupport; - -namespace gles2 { -class GLES2Interface; -class GLES2Implementation; -struct ContextCreationAttribHelper; -} -} - -namespace gpu { -class GLInProcessContext; -} - -namespace webkit { -namespace gpu { - -class WEBKIT_GPU_EXPORT WebGraphicsContext3DInProcessCommandBufferImpl - : public gpu_blink::WebGraphicsContext3DImpl { - public: - enum MappedMemoryReclaimLimit { - kNoLimit = 0, - }; - - static scoped_ptr - CreateViewContext( - const blink::WebGraphicsContext3D::Attributes& attributes, - bool lose_context_when_out_of_memory, - gfx::AcceleratedWidget window); - - static scoped_ptr - CreateOffscreenContext( - const blink::WebGraphicsContext3D::Attributes& attributes, - bool lose_context_when_out_of_memory); - - static scoped_ptr - WrapContext( - scoped_ptr< ::gpu::GLInProcessContext> context, - const blink::WebGraphicsContext3D::Attributes& attributes); - - virtual ~WebGraphicsContext3DInProcessCommandBufferImpl(); - - size_t GetMappedMemoryLimit(); - - bool InitializeOnCurrentThread(); - - //---------------------------------------------------------------------- - // WebGraphicsContext3D methods - virtual bool isContextLost(); - - virtual WGC3Denum getGraphicsResetStatusARB(); - - ::gpu::ContextSupport* GetContextSupport(); - - ::gpu::gles2::GLES2Implementation* GetImplementation() { - return real_gl_; - } - - private: - WebGraphicsContext3DInProcessCommandBufferImpl( - scoped_ptr< ::gpu::GLInProcessContext> context, - const blink::WebGraphicsContext3D::Attributes& attributes, - bool lose_context_when_out_of_memory, - bool is_offscreen, - gfx::AcceleratedWidget window); - - void OnContextLost(); - - bool MaybeInitializeGL(); - - // Used to try to find bugs in code that calls gl directly through the gl api - // instead of going through WebGraphicsContext3D. - void ClearContext(); - - ::gpu::gles2::ContextCreationAttribHelper attribs_; - bool share_resources_; - bool webgl_context_; - - bool is_offscreen_; - // Only used when not offscreen. - gfx::AcceleratedWidget window_; - - // The context we use for OpenGL rendering. - scoped_ptr< ::gpu::GLInProcessContext> context_; - // The GLES2Implementation we use for OpenGL rendering. - ::gpu::gles2::GLES2Implementation* real_gl_; -}; - -} // namespace gpu -} // namespace webkit - -#endif // WEBKIT_COMMON_GPU_WEBGRAPHICSCONTEXT3D_IN_PROCESS_COMMAND_BUFFER_IMPL_H_ diff --git a/webkit/common/gpu/webkit_gpu.gyp b/webkit/common/gpu/webkit_gpu.gyp index 7a289ff..390aacc 100644 --- a/webkit/common/gpu/webkit_gpu.gyp +++ b/webkit/common/gpu/webkit_gpu.gyp @@ -42,8 +42,6 @@ 'context_provider_web_context.h', 'grcontext_for_webgraphicscontext3d.cc', 'grcontext_for_webgraphicscontext3d.h', - 'webgraphicscontext3d_in_process_command_buffer_impl.cc', - 'webgraphicscontext3d_in_process_command_buffer_impl.h', ], 'defines': [ 'WEBKIT_GPU_IMPLEMENTATION', -- cgit v1.1