diff --git a/sky/shell/BUILD.gn b/sky/shell/BUILD.gn index f5f2f0e4e916dae670a7a9ef6c74ebec165ddc21..60a8d62bcf63bdb58904d49aa2f453634b95feeb 100644 --- a/sky/shell/BUILD.gn +++ b/sky/shell/BUILD.gn @@ -2,60 +2,12 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -common_deps = [ - "//base", - "//base:i18n", - "//build/config/sanitizers:deps", - "//dart/runtime:libdart", - "//mojo/data_pipe_utils", - "//mojo/message_pump", - "//mojo/public/cpp/application", - "//mojo/public/interfaces/application", - "//mojo/services/asset_bundle/interfaces", - "//mojo/services/keyboard/interfaces", - "//mojo/services/navigation/interfaces", - "//mojo/services/network/interfaces", - "//services/asset_bundle:lib", - "//skia", - "//sky/compositor", - "//sky/engine", - "//sky/engine/tonic", - "//sky/engine/wtf", - "//sky/services/engine:interfaces", - "//sky/services/pointer:interfaces", - "//sky/services/vsync:interfaces", - "//sky/shell/dart", - "//ui/gfx/geometry", - "//ui/gl", - "//url:url", - "//mojo/public/c/gpu", - "//mojo/public/c/gpu:gpu_onscreen", - "//mojo/services/gpu/interfaces", - "//mojo/services/native_viewport/interfaces", - "//mojo/skia:skia_bindings", -] - -if (is_linux || is_mac) { - - testing_sources = [ - "testing/test_runner.cc", - "testing/test_runner.h", - "testing/testing.cc", - "testing/testing.h", - ] - -} - source_set("common") { sources = [ - "gpu/direct/rasterizer_direct.cc", - "gpu/direct/rasterizer_direct.h", - "gpu/mojo/rasterizer_mojo.cc", - "gpu/mojo/rasterizer_mojo.h", "gpu/ganesh_canvas.cc", "gpu/ganesh_canvas.h", - "gpu_delegate.cc", - "gpu_delegate.h", + "rasterizer.cc", + "rasterizer.h", "platform_view.cc", "platform_view.h", "service_provider.cc", @@ -80,7 +32,80 @@ source_set("common") { "ui_delegate.h", ] - deps = common_deps + public_deps = [ + "//base", + "//base:i18n", + "//build/config/sanitizers:deps", + "//dart/runtime:libdart", + "//mojo/common", + "//mojo/data_pipe_utils", + "//mojo/message_pump", + "//mojo/public/cpp/application", + "//mojo/public/interfaces/application", + "//mojo/services/asset_bundle/interfaces", + "//mojo/services/keyboard/interfaces", + "//mojo/services/navigation/interfaces", + "//mojo/services/network/interfaces", + "//services/asset_bundle:lib", + "//skia", + "//sky/compositor", + "//sky/engine", + "//sky/engine/tonic", + "//sky/engine/wtf", + "//sky/services/engine:interfaces", + "//sky/services/pointer:interfaces", + "//sky/services/vsync:interfaces", + "//sky/shell/dart", + "//ui/gfx/geometry", + "//url", + "//ui/gl", + ] +} + +source_set("gpu_direct") { + sources = [ + "gpu/direct/surface_notifications_direct.cc", + "gpu/direct/surface_notifications_direct.h", + "gpu/direct/rasterizer_direct.cc", + "gpu/direct/rasterizer_direct.h", + ] + + deps = [ + ":common", + ] +} + +source_set("gpu_mojo") { + sources = [ + "gpu/mojo/rasterizer_mojo.cc", + "gpu/mojo/rasterizer_mojo.h", + ] + + deps = [ + ":common", + "//mojo/public/c/gpu", + "//mojo/public/c/gpu:gpu_onscreen", + "//mojo/services/gpu/interfaces", + "//mojo/services/native_viewport/interfaces", + "//mojo/skia:skia_bindings", + ] +} + +if (is_linux || is_mac) { + + source_set("testing") { + sources = [ + "testing/test_runner.cc", + "testing/test_runner.h", + "testing/testing.cc", + "testing/testing.h", + ] + + deps = [ + ":common", + ] + } + } if (is_android) { @@ -112,12 +137,14 @@ if (is_android) { "platform/android/update_service_android.cc", ] - deps = common_deps + [ - "//mojo/android:libsystem_java", - "//mojo/edk/system", - ":jni_headers", - ":common", - ] + deps = [ + "//mojo/android:libsystem_java", + "//mojo/edk/system", + ":common", + ":gpu_direct", + ":jni_headers", + ] + ldflags = [ "-lGLESv2", "-lEGL", @@ -186,7 +213,6 @@ if (is_android) { extensions_to_not_compress = ".flx" deps = [ - ":assets", ":assets", ":java", ":sky_shell", @@ -219,14 +245,15 @@ if (is_android) { ] set_sources_assignment_filter(sources_assignment_filter) - deps = common_deps + [ - ":common", - "//mojo/edk/system", - "//sky/services/keyboard", - "//sky/services/media", - "//sky/services/ns_net", - "//sky/services/vsync", - ] + deps = [ + ":common", + ":gpu_direct", + "//mojo/edk/system", + "//sky/services/keyboard", + "//sky/services/media", + "//sky/services/ns_net", + "//sky/services/vsync", + ] } sky_precompilation_sdk("shell") { @@ -240,13 +267,15 @@ if (is_android) { "platform/linux/main_linux.cc", "platform/linux/platform_service_provider_linux.cc", "platform/linux/platform_view_linux.cc", - ] + testing_sources + ] - deps = common_deps + [ - ":common", - "//mojo/edk/system", - "//mojo/common", - ] + deps = [ + "//mojo/common", + "//mojo/edk/system", + ":common", + ":gpu_direct", + ":testing", + ] } } else if (is_mac) { import("//build/config/mac/rules.gni") @@ -265,14 +294,16 @@ if (is_android) { "platform/mac/sky_application.mm", "platform/mac/sky_window.h", "platform/mac/sky_window.mm", - ] + testing_sources - - deps = common_deps + [ - ":common", - "//mojo/common", - "//mojo/edk/system", - "//sky/services/ns_net", - ] + ] + + deps = [ + "//mojo/common", + "//mojo/edk/system", + "//sky/services/ns_net", + ":common", + ":gpu_direct", + ":testing", + ] } mac_app("shell") { diff --git a/sky/shell/gpu/direct/rasterizer_direct.cc b/sky/shell/gpu/direct/rasterizer_direct.cc index b9b8f33004f3376b7522e122e1fee14ab9e8e810..cedb362bd53645803e2b78bad3e2656b53c150d9 100644 --- a/sky/shell/gpu/direct/rasterizer_direct.cc +++ b/sky/shell/gpu/direct/rasterizer_direct.cc @@ -24,6 +24,10 @@ namespace shell { static const double kOneFrameDuration = 1e3 / 60.0; +scoped_ptr Rasterizer::Create() { + return make_scoped_ptr(new RasterizerDirect()); +} + RasterizerDirect::RasterizerDirect() : share_group_(new gfx::GLShareGroup()), weak_factory_(this) { } @@ -35,6 +39,10 @@ base::WeakPtr RasterizerDirect::GetWeakPtr() { return weak_factory_.GetWeakPtr(); } +RasterCallback RasterizerDirect::GetRasterCallback() { + return base::Bind(&RasterizerDirect::Draw, weak_factory_.GetWeakPtr()); +} + void RasterizerDirect::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) { surface_ = gfx::GLSurface::CreateViewGLSurface(widget, gfx::SurfaceConfiguration()); diff --git a/sky/shell/gpu/direct/rasterizer_direct.h b/sky/shell/gpu/direct/rasterizer_direct.h index 69a48cd96fd420c24d9ef3d6f8361a71499097d0..93eea774b027d257041e33f5febc3466bb5d35cd 100644 --- a/sky/shell/gpu/direct/rasterizer_direct.h +++ b/sky/shell/gpu/direct/rasterizer_direct.h @@ -5,12 +5,11 @@ #ifndef SKY_SHELL_GPU_DIRECT_RASTERIZER_H_ #define SKY_SHELL_GPU_DIRECT_RASTERIZER_H_ -#include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "skia/ext/refptr.h" #include "sky/compositor/paint_context.h" #include "sky/shell/gpu/ganesh_canvas.h" -#include "sky/shell/gpu_delegate.h" +#include "sky/shell/rasterizer.h" #include "ui/gfx/geometry/size.h" #include "ui/gfx/native_widget_types.h" @@ -25,18 +24,19 @@ namespace shell { class GaneshContext; class GaneshSurface; -class RasterizerDirect : public GPUDelegate { +class RasterizerDirect : public Rasterizer { public: explicit RasterizerDirect(); ~RasterizerDirect() override; base::WeakPtr GetWeakPtr(); + RasterCallback GetRasterCallback() override; - void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override; - void OnOutputSurfaceDestroyed() override; - void Draw(scoped_ptr layer_tree) override; + void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget); + void OnOutputSurfaceDestroyed(); private: + void Draw(scoped_ptr layer_tree); void EnsureGLContext(); void EnsureGaneshSurface(intptr_t window_fbo, const gfx::Size& size); diff --git a/sky/shell/gpu/direct/surface_notifications_direct.cc b/sky/shell/gpu/direct/surface_notifications_direct.cc new file mode 100644 index 0000000000000000000000000000000000000000..57ff05429317168ac7fa25eeb452a26ef3fb85d4 --- /dev/null +++ b/sky/shell/gpu/direct/surface_notifications_direct.cc @@ -0,0 +1,37 @@ +// Copyright 2015 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 "sky/shell/gpu/direct/surface_notifications_direct.h" + +#include "base/bind.h" +#include "base/location.h" +#include "sky/shell/shell.h" +#include "base/single_thread_task_runner.h" +#include "sky/shell/gpu/direct/rasterizer_direct.h" + +namespace sky { +namespace shell { + +void SurfaceNotificationsDirect::NotifyCreated( + const PlatformView::Config& config, gfx::AcceleratedWidget widget) { + RasterizerDirect* rasterizer = static_cast(config.rasterizer); + config.ui_task_runner->PostTask( + FROM_HERE, base::Bind(&UIDelegate::OnOutputSurfaceCreated, + config.ui_delegate, + base::Bind(&RasterizerDirect::OnAcceleratedWidgetAvailable, + rasterizer->GetWeakPtr(), widget))); +} + +void SurfaceNotificationsDirect::NotifyDestroyed( + const PlatformView::Config& config) { + RasterizerDirect* rasterizer = static_cast(config.rasterizer); + config.ui_task_runner->PostTask( + FROM_HERE, base::Bind(&UIDelegate::OnOutputSurfaceDestroyed, + config.ui_delegate, + base::Bind(&RasterizerDirect::OnOutputSurfaceDestroyed, + rasterizer->GetWeakPtr()))); +} + +} // namespace shell +} // namespace sky diff --git a/sky/shell/gpu/direct/surface_notifications_direct.h b/sky/shell/gpu/direct/surface_notifications_direct.h new file mode 100644 index 0000000000000000000000000000000000000000..1cb94bfa4b5eb6e18ebeb7972aea9b1a41be2395 --- /dev/null +++ b/sky/shell/gpu/direct/surface_notifications_direct.h @@ -0,0 +1,23 @@ +// Copyright 2015 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 SKY_SHELL_GPU_DIRECT_SURFACE_NOTIFICATIONS_DIRECT_H_ +#define SKY_SHELL_GPU_DIRECT_SURFACE_NOTIFICATIONS_DIRECT_H_ + +#include "sky/shell/platform_view.h" + +namespace sky { +namespace shell { + +class SurfaceNotificationsDirect { + public: + static void NotifyCreated(const PlatformView::Config& config, + gfx::AcceleratedWidget widget); + static void NotifyDestroyed(const PlatformView::Config& config); +}; + +} // namespace shell +} // namespace sky + +#endif // SKY_SHELL_GPU_DIRECT_SURFACE_NOTIFICATIONS_DIRECT_H_ diff --git a/sky/shell/gpu/mojo/rasterizer_mojo.cc b/sky/shell/gpu/mojo/rasterizer_mojo.cc index 34f2b674766d2a9f52d2432620d610bbb0bdd9c5..ae2e6166880e5cd4ede9a073c6c702471a663bac 100644 --- a/sky/shell/gpu/mojo/rasterizer_mojo.cc +++ b/sky/shell/gpu/mojo/rasterizer_mojo.cc @@ -20,16 +20,22 @@ void ContextLostThunk(void* closure) { } // namespace -RasterizerMojo::RasterizerMojo() { +scoped_ptr Rasterizer::Create() { + return make_scoped_ptr(new RasterizerMojo()); +} + +RasterizerMojo::RasterizerMojo() : weak_factory_(this) { } RasterizerMojo::~RasterizerMojo() { } -void RasterizerMojo::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) { +base::WeakPtr RasterizerMojo::GetWeakPtr() { + return weak_factory_.GetWeakPtr(); } -void RasterizerMojo::OnOutputSurfaceDestroyed() { +RasterCallback RasterizerMojo::GetRasterCallback() { + return base::Bind(&RasterizerMojo::Draw, weak_factory_.GetWeakPtr()); } void RasterizerMojo::Draw(scoped_ptr layer_tree) { @@ -37,7 +43,10 @@ void RasterizerMojo::Draw(scoped_ptr layer_tree) { MGLResizeSurface(layer_tree->frame_size().width(), layer_tree->frame_size().height()); SkCanvas* canvas = ganesh_canvas_.GetCanvas(0, layer_tree->frame_size()); - canvas->clear(SK_ColorGREEN); + sky::compositor::PaintContext::ScopedFrame frame = + paint_context_.AcquireFrame(*canvas); + canvas->clear(SK_ColorBLACK); + layer_tree->root_layer()->Paint(frame); canvas->flush(); MGLSwapBuffers(); } @@ -47,7 +56,6 @@ void RasterizerMojo::OnContextProviderAvailable( context_provider_ = mojo::MakeProxy(context_provider.Pass()); context_provider_->Create(nullptr, base::Bind(&RasterizerMojo::OnContextCreated, base::Unretained(this))); - gr_gl_interface_ = skia::AdoptRef(skia_bindings::CreateMojoSkiaGLBinding()); } void RasterizerMojo::OnContextCreated(mojo::CommandBufferPtr command_buffer) { @@ -57,6 +65,8 @@ void RasterizerMojo::OnContextCreated(mojo::CommandBufferPtr command_buffer) { MGL_NO_CONTEXT, &ContextLostThunk, this, mojo::Environment::GetDefaultAsyncWaiter()); MGLMakeCurrent(context_); + if (!gr_gl_interface_) + gr_gl_interface_ = skia::AdoptRef(skia_bindings::CreateMojoSkiaGLBinding()); ganesh_canvas_.SetGrGLInterface(gr_gl_interface_.get()); } diff --git a/sky/shell/gpu/mojo/rasterizer_mojo.h b/sky/shell/gpu/mojo/rasterizer_mojo.h index 51c50348a8c925ed0b6f7fa9e0b219e163011bd9..b1c22c609dd47e254c90a135b1775db964173dbc 100644 --- a/sky/shell/gpu/mojo/rasterizer_mojo.h +++ b/sky/shell/gpu/mojo/rasterizer_mojo.h @@ -5,25 +5,25 @@ #ifndef SKY_SHELL_GPU_MOJO_RASTERIZER_MOJO_H_ #define SKY_SHELL_GPU_MOJO_RASTERIZER_MOJO_H_ +#include "base/memory/weak_ptr.h" #include "mojo/public/c/gpu/MGL/mgl.h" #include "mojo/services/native_viewport/interfaces/native_viewport.mojom.h" #include "skia/ext/refptr.h" #include "sky/compositor/paint_context.h" #include "sky/shell/gpu/ganesh_canvas.h" -#include "sky/shell/gpu_delegate.h" -#include "ui/gfx/native_widget_types.h" +#include "sky/shell/rasterizer.h" namespace sky { namespace shell { -class RasterizerMojo : public GPUDelegate { +class RasterizerMojo : public Rasterizer { public: explicit RasterizerMojo(); ~RasterizerMojo() override; - void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override; - void OnOutputSurfaceDestroyed() override; - void Draw(scoped_ptr layer_tree) override; + base::WeakPtr GetWeakPtr(); + + RasterCallback GetRasterCallback() override; void OnContextProviderAvailable( mojo::InterfacePtrInfo context_provder); @@ -31,14 +31,18 @@ class RasterizerMojo : public GPUDelegate { void OnContextLost(); private: - SkCanvas* GetCanvas(const SkISize& size); void OnContextCreated(mojo::CommandBufferPtr command_buffer); + void Draw(scoped_ptr layer_tree); mojo::ContextProviderPtr context_provider_; skia::RefPtr gr_gl_interface_; MGLContext context_; GaneshCanvas ganesh_canvas_; + compositor::PaintContext paint_context_; + + base::WeakPtrFactory weak_factory_; + DISALLOW_COPY_AND_ASSIGN(RasterizerMojo); }; diff --git a/sky/shell/gpu_delegate.h b/sky/shell/gpu_delegate.h deleted file mode 100644 index e0d67ecd5b024160dcd5572d6edb12b0959b34a8..0000000000000000000000000000000000000000 --- a/sky/shell/gpu_delegate.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2015 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 SKY_SHELL_GPU_DELEGATE_H_ -#define SKY_SHELL_GPU_DELEGATE_H_ - -#include - -#include "base/memory/scoped_ptr.h" -#include "sky/compositor/layer_tree.h" -#include "ui/gfx/geometry/size.h" -#include "ui/gfx/native_widget_types.h" - -class SkPicture; - -namespace sky { -namespace shell { - -class GPUDelegate { - public: - virtual void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) = 0; - virtual void OnOutputSurfaceDestroyed() = 0; - virtual void Draw(scoped_ptr layer_tree) = 0; - - protected: - virtual ~GPUDelegate(); -}; - -} // namespace shell -} // namespace sky - -#endif // SKY_SHELL_GPU_DELEGATE_H_ diff --git a/sky/shell/platform/android/platform_view_android.cc b/sky/shell/platform/android/platform_view_android.cc index a0ae895c60f94d5c0e2805761b45ebdb9499d7d9..79a3038bb8afec31dc7e8ee6ab7f93615bf287c6 100644 --- a/sky/shell/platform/android/platform_view_android.cc +++ b/sky/shell/platform/android/platform_view_android.cc @@ -11,6 +11,7 @@ #include "base/bind.h" #include "base/location.h" #include "jni/PlatformViewAndroid_jni.h" +#include "sky/shell/gpu/direct/surface_notifications_direct.h" #include "sky/shell/shell.h" #include "sky/shell/shell_view.h" @@ -37,7 +38,7 @@ PlatformView* PlatformView::Create(const Config& config) { } PlatformViewAndroid::PlatformViewAndroid(const Config& config) - : PlatformView(config) { + : PlatformView(config), window_(nullptr) { } PlatformViewAndroid::~PlatformViewAndroid() { @@ -60,12 +61,12 @@ void PlatformViewAndroid::SurfaceCreated(JNIEnv* env, jobject obj, jobject jsurf base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); window_ = ANativeWindow_fromSurface(env, jsurface); } - SurfaceWasCreated(); + SurfaceNotificationsDirect::NotifyCreated(config_, window_); } void PlatformViewAndroid::SurfaceDestroyed(JNIEnv* env, jobject obj) { DCHECK(window_); - SurfaceWasDestroyed(); + SurfaceNotificationsDirect::NotifyDestroyed(config_); ReleaseWindow(); } diff --git a/sky/shell/platform/android/platform_view_android.h b/sky/shell/platform/android/platform_view_android.h index 4f3f908e6119c1cb91b41d47c650778306aefe2b..fb9ee40dc314a0db8ffdd7e263d937b3204102d0 100644 --- a/sky/shell/platform/android/platform_view_android.h +++ b/sky/shell/platform/android/platform_view_android.h @@ -35,6 +35,7 @@ class PlatformViewAndroid : public PlatformView { // ownership and have the shell_view owned by Java. We reset this pointer in // |Detach|, which will eventually cause |~PlatformViewAndroid|. scoped_ptr shell_view_; + gfx::AcceleratedWidget window_; DISALLOW_COPY_AND_ASSIGN(PlatformViewAndroid); }; diff --git a/sky/shell/platform/mac/platform_view_mac.h b/sky/shell/platform/mac/platform_view_mac.h index d5fe68f731b4059a8674e25a02261bb26c0e2c5c..05e4dfb03882ab36b6bdf311a2fcdda3c9fd886e 100644 --- a/sky/shell/platform/mac/platform_view_mac.h +++ b/sky/shell/platform/mac/platform_view_mac.h @@ -18,6 +18,8 @@ class PlatformViewMac : public PlatformView { void SurfaceDestroyed(void); private: + gfx::AcceleratedWidget window_; + DISALLOW_COPY_AND_ASSIGN(PlatformViewMac); }; diff --git a/sky/shell/platform/mac/platform_view_mac.mm b/sky/shell/platform/mac/platform_view_mac.mm index 3308a4c5223621e4b7e06b566c4c33a7f3e24e90..6de1fb1359dd7a4e9aade1daa5fcaa87c33985d7 100644 --- a/sky/shell/platform/mac/platform_view_mac.mm +++ b/sky/shell/platform/mac/platform_view_mac.mm @@ -4,6 +4,8 @@ #include "sky/shell/platform/mac/platform_view_mac.h" +#include "sky/shell/gpu/direct/surface_notifications_direct.h" + namespace sky { namespace shell { @@ -18,13 +20,13 @@ PlatformViewMac::~PlatformViewMac() {} void PlatformViewMac::SurfaceCreated(gfx::AcceleratedWidget widget) { DCHECK(window_ == 0); window_ = widget; - SurfaceWasCreated(); + SurfaceNotificationsDirect::NotifyCreated(config_, window_); } void PlatformViewMac::SurfaceDestroyed() { DCHECK(window_); window_ = 0; - SurfaceWasDestroyed(); + SurfaceNotificationsDirect::NotifyDestroyed(config_); } } // namespace shell diff --git a/sky/shell/platform/mojo/BUILD.gn b/sky/shell/platform/mojo/BUILD.gn index d616d449c3f1e2c86b439160c81c60db086889db..6578e975274f455863b78127a8511feb9696ad94 100644 --- a/sky/shell/platform/mojo/BUILD.gn +++ b/sky/shell/platform/mojo/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright 2014 The Chromium Authors. All rights reserved. +# Copyright 2015 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. @@ -32,13 +32,8 @@ mojo_native_application("mojo") { "//mojo/services/asset_bundle/interfaces", "//mojo/services/content_handler/interfaces", "//mojo/services/gpu/interfaces", - "//mojo/services/input_events/interfaces", - "//mojo/services/navigation/interfaces", - "//mojo/services/network/interfaces", "//mojo/services/native_viewport/interfaces", "//mojo/services/service_registry/interfaces", - "//mojo/services/surfaces/interfaces", - "//mojo/services/ui/views/interfaces", "//services/asset_bundle:lib", "//services/sky/compositor", "//skia", @@ -46,14 +41,8 @@ mojo_native_application("mojo") { "//sky/engine/tonic", "//sky/engine/web", "//sky/shell:common", + "//sky/shell:gpu_mojo", "//third_party/icu", "//url", ] - - if (is_android) { - ldflags = [ - "-lGLESv2", - "-lEGL", - ] - } } diff --git a/sky/shell/platform/mojo/platform_view_mojo.cc b/sky/shell/platform/mojo/platform_view_mojo.cc index 4adb46d91a29bfa95a40970166228e67dd49e59c..6c91db58706ea18effa64f211b544dd1b06332c2 100644 --- a/sky/shell/platform/mojo/platform_view_mojo.cc +++ b/sky/shell/platform/mojo/platform_view_mojo.cc @@ -4,6 +4,11 @@ #include "sky/shell/platform/mojo/platform_view_mojo.h" +#include "base/bind.h" +#include "base/location.h" +#include "base/single_thread_task_runner.h" +#include "sky/shell/gpu/mojo/rasterizer_mojo.h" + namespace sky { namespace shell { @@ -37,10 +42,17 @@ void PlatformViewMojo::Init(mojo::ApplicationImpl* app) { }); viewport_->Show(); - viewport_->GetContextProvider(GetProxy(&context_provider_)); + mojo::ContextProviderPtr context_provider; + viewport_->GetContextProvider(GetProxy(&context_provider)); + + mojo::InterfacePtrInfo context_provider_info = context_provider.PassInterface(); - // TODO(abarth): Move the to GPU thread. - context_provider_.PassInterface(); + RasterizerMojo* rasterizer = static_cast(config_.rasterizer); + config_.ui_task_runner->PostTask( + FROM_HERE, base::Bind(&UIDelegate::OnOutputSurfaceCreated, + config_.ui_delegate, + base::Bind(&RasterizerMojo::OnContextProviderAvailable, + rasterizer->GetWeakPtr(), base::Passed(&context_provider_info)))); } void PlatformViewMojo::Run(const mojo::String& url, diff --git a/sky/shell/platform/mojo/platform_view_mojo.h b/sky/shell/platform/mojo/platform_view_mojo.h index 87ddf6eb10b11c145c085266c126d3454fae8dab..9f4920fe76f45fb083264cd0b77944af7dc8a76e 100644 --- a/sky/shell/platform/mojo/platform_view_mojo.h +++ b/sky/shell/platform/mojo/platform_view_mojo.h @@ -33,7 +33,6 @@ class PlatformViewMojo : public PlatformView, const mojo::Callback& callback) override; mojo::NativeViewportPtr viewport_; - mojo::ContextProviderPtr context_provider_; mojo::Binding dispatcher_binding_; sky::SkyEnginePtr sky_engine_; diff --git a/sky/shell/platform_view.cc b/sky/shell/platform_view.cc index a22fc5df808437e5decc2a016bb322141a59a5b2..296b51e7849abec5ca9159f0976b7d95e222c247 100644 --- a/sky/shell/platform_view.cc +++ b/sky/shell/platform_view.cc @@ -3,9 +3,9 @@ // found in the LICENSE file. #include "sky/shell/platform_view.h" + #include "base/bind.h" #include "base/location.h" -#include "sky/shell/shell.h" #include "base/single_thread_task_runner.h" namespace sky { @@ -18,7 +18,7 @@ PlatformView::Config::~Config() { } PlatformView::PlatformView(const PlatformView::Config& config) - : config_(config), window_(0) { + : config_(config) { } PlatformView::~PlatformView() { @@ -31,17 +31,5 @@ void PlatformView::ConnectToEngine( config_.ui_delegate, base::Passed(&request))); } -void PlatformView::SurfaceWasCreated() { - config_.ui_task_runner->PostTask( - FROM_HERE, base::Bind(&UIDelegate::OnAcceleratedWidgetAvailable, - config_.ui_delegate, window_)); -} - -void PlatformView::SurfaceWasDestroyed() { - config_.ui_task_runner->PostTask( - FROM_HERE, - base::Bind(&UIDelegate::OnOutputSurfaceDestroyed, config_.ui_delegate)); -} - } // namespace shell } // namespace sky diff --git a/sky/shell/platform_view.h b/sky/shell/platform_view.h index 7b221af296c1608b17f3ac9c5e19a858bfa9d61f..11a4ce9ca829f4730edf94b30faa11c79fffbcc2 100644 --- a/sky/shell/platform_view.h +++ b/sky/shell/platform_view.h @@ -8,6 +8,7 @@ #include "base/macros.h" #include "base/memory/weak_ptr.h" #include "sky/shell/ui_delegate.h" +#include "sky/shell/rasterizer.h" namespace sky { namespace shell { @@ -19,9 +20,11 @@ class PlatformView { ~Config(); base::WeakPtr ui_delegate; + Rasterizer* rasterizer; scoped_refptr ui_task_runner; }; + // Implemented by each platform. static PlatformView* Create(const Config& config); virtual ~PlatformView(); @@ -31,11 +34,7 @@ class PlatformView { protected: explicit PlatformView(const Config& config); - void SurfaceWasCreated(); - void SurfaceWasDestroyed(); - Config config_; - gfx::AcceleratedWidget window_; private: DISALLOW_COPY_AND_ASSIGN(PlatformView); diff --git a/sky/shell/gpu_delegate.cc b/sky/shell/rasterizer.cc similarity index 78% rename from sky/shell/gpu_delegate.cc rename to sky/shell/rasterizer.cc index 62fe84c40bc9274136ef867093f5f6a7e872588f..222514d94be2a1efdc1fe0587df44f67b5ce0a2d 100644 --- a/sky/shell/gpu_delegate.cc +++ b/sky/shell/rasterizer.cc @@ -2,12 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sky/shell/gpu_delegate.h" +#include "sky/shell/rasterizer.h" namespace sky { namespace shell { -GPUDelegate::~GPUDelegate() { +Rasterizer::~Rasterizer() { } } // namespace shell diff --git a/sky/shell/rasterizer.h b/sky/shell/rasterizer.h new file mode 100644 index 0000000000000000000000000000000000000000..b2f199014939fd415a58abec63af91db73f25ff2 --- /dev/null +++ b/sky/shell/rasterizer.h @@ -0,0 +1,31 @@ +// Copyright 2015 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 SKY_SHELL_RASTERIZER_H_ +#define SKY_SHELL_RASTERIZER_H_ + +#include + +#include "base/callback.h" +#include "base/memory/scoped_ptr.h" +#include "sky/compositor/layer_tree.h" + +namespace sky { +namespace shell { + +typedef base::Callback)> RasterCallback; + +class Rasterizer { + public: + virtual ~Rasterizer(); + virtual RasterCallback GetRasterCallback() = 0; + + // Implemented by each GPU backend. + static scoped_ptr Create(); +}; + +} // namespace shell +} // namespace sky + +#endif // SKY_SHELL_RASTERIZER_H_ diff --git a/sky/shell/shell_view.cc b/sky/shell/shell_view.cc index 9e9582b661b460966b9fd1ba217d38b070635b57..cdc5de297f4749003f828736daa1f66dd6292bb3 100644 --- a/sky/shell/shell_view.cc +++ b/sky/shell/shell_view.cc @@ -6,8 +6,8 @@ #include "base/bind.h" #include "base/single_thread_task_runner.h" -#include "sky/shell/gpu/direct/rasterizer_direct.h" #include "sky/shell/platform_view.h" +#include "sky/shell/rasterizer.h" #include "sky/shell/shell.h" #include "sky/shell/ui/engine.h" @@ -23,15 +23,16 @@ void Drop(scoped_ptr ptr) { } ShellView::ShellView(Shell& shell) : shell_(shell) { shell_.tracing_controller().RegisterShellView(this); - rasterizer_.reset(new RasterizerDirect()); + rasterizer_ = Rasterizer::Create(); CreateEngine(); CreatePlatformView(); } ShellView::~ShellView() { shell_.tracing_controller().UnregisterShellView(this); + view_ = nullptr; shell_.gpu_task_runner()->PostTask(FROM_HERE, - base::Bind(&Drop, base::Passed(&rasterizer_))); + base::Bind(&Drop, base::Passed(&rasterizer_))); shell_.ui_task_runner()->PostTask(FROM_HERE, base::Bind(&Drop, base::Passed(&engine_))); } @@ -40,7 +41,7 @@ void ShellView::CreateEngine() { Engine::Config config; config.service_provider_context = shell_.service_provider_context(); config.gpu_task_runner = shell_.gpu_task_runner(); - config.gpu_delegate = rasterizer_->GetWeakPtr(); + config.raster_callback = rasterizer_->GetRasterCallback(); engine_.reset(new Engine(config)); } @@ -48,6 +49,7 @@ void ShellView::CreatePlatformView() { PlatformView::Config config; config.ui_task_runner = shell_.ui_task_runner(); config.ui_delegate = engine_->GetWeakPtr(); + config.rasterizer = rasterizer_.get(); view_.reset(PlatformView::Create(config)); } diff --git a/sky/shell/shell_view.h b/sky/shell/shell_view.h index 4a804e884af0f49995ea6a9c3d25b32aa2e1c0e6..4231cf79d54fbbacc0fd098bfbfff735c4726db0 100644 --- a/sky/shell/shell_view.h +++ b/sky/shell/shell_view.h @@ -14,7 +14,7 @@ namespace sky { namespace shell { class Engine; class PlatformView; -class RasterizerDirect; +class Rasterizer; class Shell; class ShellView { @@ -33,7 +33,7 @@ class ShellView { Shell& shell_; scoped_ptr view_; - scoped_ptr rasterizer_; + scoped_ptr rasterizer_; scoped_ptr engine_; DISALLOW_COPY_AND_ASSIGN(ShellView); diff --git a/sky/shell/ui/animator.cc b/sky/shell/ui/animator.cc index f639f1d255f2696fb99ff80999225348f7285ca1..bad4b2458d1db2bc716446625dad516ad1355935 100644 --- a/sky/shell/ui/animator.cc +++ b/sky/shell/ui/animator.cc @@ -81,8 +81,7 @@ void Animator::BeginFrame(int64_t time_stamp) { config_.gpu_task_runner->PostTaskAndReply( FROM_HERE, - base::Bind(&GPUDelegate::Draw, config_.gpu_delegate, - base::Passed(&layer_tree)), + base::Bind(config_.raster_callback, base::Passed(&layer_tree)), base::Bind(&Animator::OnFrameComplete, weak_factory_.GetWeakPtr())); } diff --git a/sky/shell/ui/engine.cc b/sky/shell/ui/engine.cc index 78f2099b65e0cf4a7304744a79f7d26c2316b3da..b3df847709368326fe97590ea75625df26fa2daf 100644 --- a/sky/shell/ui/engine.cc +++ b/sky/shell/ui/engine.cc @@ -117,22 +117,18 @@ void Engine::ConnectToEngine(mojo::InterfaceRequest request) { binding_.Bind(request.Pass()); } -void Engine::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) { - config_.gpu_task_runner->PostTask( - FROM_HERE, base::Bind(&GPUDelegate::OnAcceleratedWidgetAvailable, - config_.gpu_delegate, widget)); +void Engine::OnOutputSurfaceCreated(const base::Closure& gpu_continuation) { + config_.gpu_task_runner->PostTask(FROM_HERE, gpu_continuation); have_surface_ = true; StartAnimatorIfPossible(); if (sky_view_) ScheduleFrame(); } -void Engine::OnOutputSurfaceDestroyed() { +void Engine::OnOutputSurfaceDestroyed(const base::Closure& gpu_continuation) { have_surface_ = false; StopAnimator(); - config_.gpu_task_runner->PostTask( - FROM_HERE, - base::Bind(&GPUDelegate::OnOutputSurfaceDestroyed, config_.gpu_delegate)); + config_.gpu_task_runner->PostTask(FROM_HERE, gpu_continuation); } void Engine::OnViewportMetricsChanged(ViewportMetricsPtr metrics) { diff --git a/sky/shell/ui/engine.h b/sky/shell/ui/engine.h index 7c7488a35b38587806bc0b032c95cc9b85dca665..d03fd8e6e0f54fcd30ce9309bd92097ee69a7a2f 100644 --- a/sky/shell/ui/engine.h +++ b/sky/shell/ui/engine.h @@ -21,7 +21,7 @@ #include "sky/engine/public/platform/ServiceProvider.h" #include "sky/engine/public/sky/sky_view.h" #include "sky/engine/public/sky/sky_view_client.h" -#include "sky/shell/gpu_delegate.h" +#include "sky/shell/rasterizer.h" #include "sky/shell/service_provider.h" #include "sky/shell/ui_delegate.h" #include "third_party/skia/include/core/SkPicture.h" @@ -44,7 +44,7 @@ class Engine : public UIDelegate, ServiceProviderContext* service_provider_context; - base::WeakPtr gpu_delegate; + RasterCallback raster_callback; scoped_refptr gpu_task_runner; }; @@ -63,8 +63,8 @@ class Engine : public UIDelegate, private: // UIDelegate implementation: void ConnectToEngine(mojo::InterfaceRequest request) override; - void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override; - void OnOutputSurfaceDestroyed() override; + void OnOutputSurfaceCreated(const base::Closure& gpu_continuation) override; + void OnOutputSurfaceDestroyed(const base::Closure& gpu_continuation) override; // SkyEngine implementation: void OnViewportMetricsChanged(ViewportMetricsPtr metrics) override; diff --git a/sky/shell/ui_delegate.h b/sky/shell/ui_delegate.h index a32d2e4eafdc43cbea2d6eaf94c61194ae317653..f432459e4f0ed38b2b923e0647542bd35b439794 100644 --- a/sky/shell/ui_delegate.h +++ b/sky/shell/ui_delegate.h @@ -9,6 +9,7 @@ #include "sky/services/engine/sky_engine.mojom.h" #include "ui/gfx/geometry/size.h" #include "ui/gfx/native_widget_types.h" +#include "base/callback.h" namespace sky { namespace shell { @@ -16,8 +17,8 @@ namespace shell { class UIDelegate { public: virtual void ConnectToEngine(mojo::InterfaceRequest request) = 0; - virtual void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) = 0; - virtual void OnOutputSurfaceDestroyed() = 0; + virtual void OnOutputSurfaceCreated(const base::Closure& gpu_continuation) = 0; + virtual void OnOutputSurfaceDestroyed(const base::Closure& gpu_continuation) = 0; protected: virtual ~UIDelegate();