提交 56601fcf 编写于 作者: A Adam Barth

Wire sky_shell.mojo to draw via MGL

After this patch, we can execute Dart code and draw the result via MGL. We
still need to plumb in services.
上级 33e56114
......@@ -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") {
......
......@@ -24,6 +24,10 @@ namespace shell {
static const double kOneFrameDuration = 1e3 / 60.0;
scoped_ptr<Rasterizer> 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> 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());
......
......@@ -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<RasterizerDirect> GetWeakPtr();
RasterCallback GetRasterCallback() override;
void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override;
void OnOutputSurfaceDestroyed() override;
void Draw(scoped_ptr<compositor::LayerTree> layer_tree) override;
void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget);
void OnOutputSurfaceDestroyed();
private:
void Draw(scoped_ptr<compositor::LayerTree> layer_tree);
void EnsureGLContext();
void EnsureGaneshSurface(intptr_t window_fbo, const gfx::Size& size);
......
// 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<RasterizerDirect*>(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<RasterizerDirect*>(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
// 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_
......@@ -20,16 +20,22 @@ void ContextLostThunk(void* closure) {
} // namespace
RasterizerMojo::RasterizerMojo() {
scoped_ptr<Rasterizer> Rasterizer::Create() {
return make_scoped_ptr(new RasterizerMojo());
}
RasterizerMojo::RasterizerMojo() : weak_factory_(this) {
}
RasterizerMojo::~RasterizerMojo() {
}
void RasterizerMojo::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) {
base::WeakPtr<RasterizerMojo> 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<compositor::LayerTree> layer_tree) {
......@@ -37,7 +43,10 @@ void RasterizerMojo::Draw(scoped_ptr<compositor::LayerTree> 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());
}
......
......@@ -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<compositor::LayerTree> layer_tree) override;
base::WeakPtr<RasterizerMojo> GetWeakPtr();
RasterCallback GetRasterCallback() override;
void OnContextProviderAvailable(
mojo::InterfacePtrInfo<mojo::ContextProvider> 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<compositor::LayerTree> layer_tree);
mojo::ContextProviderPtr context_provider_;
skia::RefPtr<GrGLInterface> gr_gl_interface_;
MGLContext context_;
GaneshCanvas ganesh_canvas_;
compositor::PaintContext paint_context_;
base::WeakPtrFactory<RasterizerMojo> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(RasterizerMojo);
};
......
......@@ -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();
}
......
......@@ -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<ShellView> shell_view_;
gfx::AcceleratedWidget window_;
DISALLOW_COPY_AND_ASSIGN(PlatformViewAndroid);
};
......
......@@ -18,6 +18,8 @@ class PlatformViewMac : public PlatformView {
void SurfaceDestroyed(void);
private:
gfx::AcceleratedWidget window_;
DISALLOW_COPY_AND_ASSIGN(PlatformViewMac);
};
......
......@@ -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
......
# 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",
]
}
}
......@@ -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<mojo::ContextProvider> context_provider_info = context_provider.PassInterface();
// TODO(abarth): Move the to GPU thread.
context_provider_.PassInterface();
RasterizerMojo* rasterizer = static_cast<RasterizerMojo*>(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,
......
......@@ -33,7 +33,6 @@ class PlatformViewMojo : public PlatformView,
const mojo::Callback<void()>& callback) override;
mojo::NativeViewportPtr viewport_;
mojo::ContextProviderPtr context_provider_;
mojo::Binding<NativeViewportEventDispatcher> dispatcher_binding_;
sky::SkyEnginePtr sky_engine_;
......
......@@ -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
......@@ -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<UIDelegate> ui_delegate;
Rasterizer* rasterizer;
scoped_refptr<base::SingleThreadTaskRunner> 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);
......
......@@ -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
......
......@@ -2,32 +2,30 @@
// 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_
#ifndef SKY_SHELL_RASTERIZER_H_
#define SKY_SHELL_RASTERIZER_H_
#include <memory>
#include "base/callback.h"
#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 {
typedef base::Callback<void(scoped_ptr<compositor::LayerTree>)> RasterCallback;
class Rasterizer {
public:
virtual void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) = 0;
virtual void OnOutputSurfaceDestroyed() = 0;
virtual void Draw(scoped_ptr<compositor::LayerTree> layer_tree) = 0;
virtual ~Rasterizer();
virtual RasterCallback GetRasterCallback() = 0;
protected:
virtual ~GPUDelegate();
// Implemented by each GPU backend.
static scoped_ptr<Rasterizer> Create();
};
} // namespace shell
} // namespace sky
#endif // SKY_SHELL_GPU_DELEGATE_H_
#endif // SKY_SHELL_RASTERIZER_H_
......@@ -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<T> 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<RasterizerDirect>, base::Passed(&rasterizer_)));
base::Bind(&Drop<Rasterizer>, base::Passed(&rasterizer_)));
shell_.ui_task_runner()->PostTask(FROM_HERE,
base::Bind(&Drop<Engine>, 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));
}
......
......@@ -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<PlatformView> view_;
scoped_ptr<RasterizerDirect> rasterizer_;
scoped_ptr<Rasterizer> rasterizer_;
scoped_ptr<Engine> engine_;
DISALLOW_COPY_AND_ASSIGN(ShellView);
......
......@@ -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()));
}
......
......@@ -117,22 +117,18 @@ void Engine::ConnectToEngine(mojo::InterfaceRequest<SkyEngine> 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) {
......
......@@ -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<GPUDelegate> gpu_delegate;
RasterCallback raster_callback;
scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner;
};
......@@ -63,8 +63,8 @@ class Engine : public UIDelegate,
private:
// UIDelegate implementation:
void ConnectToEngine(mojo::InterfaceRequest<SkyEngine> 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;
......
......@@ -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<SkyEngine> 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();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册