提交 96b847cd 编写于 作者: A Adam Barth

Wire sky_shell.mojo up to native_viewport

After this patch, we can execute Dart code an create an X window. There's a
sketch of some graphics code, but it's not wired up yet.
上级 1db56166
...@@ -11,6 +11,7 @@ mojom("interfaces") { ...@@ -11,6 +11,7 @@ mojom("interfaces") {
] ]
deps = [ deps = [
"//sky/services/pointer:interfaces" "//mojo/services/asset_bundle/interfaces",
"//sky/services/pointer:interfaces",
] ]
} }
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
module sky; module sky;
import "mojo/services/asset_bundle/interfaces/asset_bundle.mojom";
import "sky/services/engine/input_event.mojom"; import "sky/services/engine/input_event.mojom";
import "sky/services/pointer/pointer.mojom"; import "sky/services/pointer/pointer.mojom";
...@@ -30,4 +31,6 @@ interface SkyEngine { ...@@ -30,4 +31,6 @@ interface SkyEngine {
RunFromPrecompiledSnapshot(string path); RunFromPrecompiledSnapshot(string path);
RunFromSnapshot(string path); RunFromSnapshot(string path);
RunFromBundle(string path); RunFromBundle(string path);
RunFromAssetBundle(string url, mojo.asset_bundle.AssetBundle bundle);
}; };
...@@ -28,6 +28,11 @@ common_deps = [ ...@@ -28,6 +28,11 @@ common_deps = [
"//ui/gfx/geometry", "//ui/gfx/geometry",
"//ui/gl", "//ui/gl",
"//url:url", "//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) { if (is_linux || is_mac) {
...@@ -43,12 +48,12 @@ if (is_linux || is_mac) { ...@@ -43,12 +48,12 @@ if (is_linux || is_mac) {
source_set("common") { source_set("common") {
sources = [ sources = [
"gpu/direct/ganesh_context.cc", "gpu/direct/rasterizer_direct.cc",
"gpu/direct/ganesh_context.h", "gpu/direct/rasterizer_direct.h",
"gpu/direct/ganesh_surface.cc", "gpu/mojo/rasterizer_mojo.cc",
"gpu/direct/ganesh_surface.h", "gpu/mojo/rasterizer_mojo.h",
"gpu/direct/rasterizer.cc", "gpu/ganesh_canvas.cc",
"gpu/direct/rasterizer.h", "gpu/ganesh_canvas.h",
"gpu_delegate.cc", "gpu_delegate.cc",
"gpu_delegate.h", "gpu_delegate.h",
"platform_view.cc", "platform_view.cc",
......
// 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/ganesh_surface.h"
#include "base/logging.h"
#include "third_party/skia/include/gpu/GrContext.h"
namespace sky {
namespace shell {
GaneshSurface::GaneshSurface(intptr_t window_fbo,
GaneshContext* context,
const gfx::Size& size) {
GrBackendRenderTargetDesc desc;
desc.fWidth = size.width();
desc.fHeight = size.height();
desc.fConfig = kSkia8888_GrPixelConfig;
desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
desc.fRenderTargetHandle = window_fbo;
skia::RefPtr<GrRenderTarget> target = skia::AdoptRef(
context->gr()->textureProvider()->wrapBackendRenderTarget(desc));
DCHECK(target);
surface_ = skia::AdoptRef(SkSurface::NewRenderTargetDirect(target.get()));
DCHECK(surface_);
}
GaneshSurface::~GaneshSurface() {
}
} // 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_GANESH_SURFACE_H_
#define SKY_SHELL_GPU_DIRECT_GANESH_SURFACE_H_
#include "base/memory/scoped_ptr.h"
#include "sky/engine/wtf/RefPtr.h"
#include "sky/shell/gpu/direct/ganesh_context.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "ui/gfx/geometry/size.h"
namespace sky {
namespace shell {
// GaneshSurface holds an SkSurface configured to render with Ganesh. Using the
// provided GaneshContext, GaneshSurface wraps an SkSurface around the window
// bound FBO so that you can use |canvas()| to draw to that window bound FBO.
class GaneshSurface {
public:
GaneshSurface(intptr_t window_fbo,
GaneshContext* context,
const gfx::Size& size);
~GaneshSurface();
SkCanvas* canvas() const { return surface_->getCanvas(); }
gfx::Size size() const {
return gfx::Size(surface_->width(), surface_->height());
}
private:
skia::RefPtr<SkSurface> surface_;
DISALLOW_COPY_AND_ASSIGN(GaneshSurface);
};
} // namespace shell
} // namespace sky
#endif // SKY_SHELL_GPU_DIRECT_GANESH_SURFACE_H_
...@@ -2,48 +2,47 @@ ...@@ -2,48 +2,47 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "sky/shell/gpu/direct/rasterizer.h" #include "sky/shell/gpu/direct/rasterizer_direct.h"
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
#include "mojo/public/cpp/system/data_pipe.h"
#include "sky/compositor/container_layer.h" #include "sky/compositor/container_layer.h"
#include "sky/compositor/layer.h" #include "sky/compositor/layer.h"
#include "sky/compositor/paint_context.h" #include "sky/compositor/paint_context.h"
#include "sky/compositor/picture_layer.h" #include "sky/compositor/picture_layer.h"
#include "sky/shell/gpu/direct/ganesh_context.h"
#include "sky/shell/gpu/direct/ganesh_surface.h"
#include "sky/shell/shell.h" #include "sky/shell/shell.h"
#include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkPicture.h" #include "third_party/skia/include/core/SkPicture.h"
#include "ui/gl/gl_bindings.h" #include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_bindings_skia_in_process.h"
#include "ui/gl/gl_context.h" #include "ui/gl/gl_context.h"
#include "ui/gl/gl_share_group.h" #include "ui/gl/gl_share_group.h"
#include "ui/gl/gl_surface.h" #include "ui/gl/gl_surface.h"
#include "mojo/public/cpp/system/data_pipe.h"
namespace sky { namespace sky {
namespace shell { namespace shell {
static const double kOneFrameDuration = 1e3 / 60.0; static const double kOneFrameDuration = 1e3 / 60.0;
Rasterizer::Rasterizer() RasterizerDirect::RasterizerDirect()
: share_group_(new gfx::GLShareGroup()), weak_factory_(this) { : share_group_(new gfx::GLShareGroup()), weak_factory_(this) {
} }
Rasterizer::~Rasterizer() { RasterizerDirect::~RasterizerDirect() {
} }
base::WeakPtr<Rasterizer> Rasterizer::GetWeakPtr() { base::WeakPtr<RasterizerDirect> RasterizerDirect::GetWeakPtr() {
return weak_factory_.GetWeakPtr(); return weak_factory_.GetWeakPtr();
} }
void Rasterizer::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) { void RasterizerDirect::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) {
surface_ = surface_ =
gfx::GLSurface::CreateViewGLSurface(widget, gfx::SurfaceConfiguration()); gfx::GLSurface::CreateViewGLSurface(widget, gfx::SurfaceConfiguration());
CHECK(surface_) << "GLSurface required."; CHECK(surface_) << "GLSurface required.";
} }
void Rasterizer::Draw(scoped_ptr<compositor::LayerTree> layer_tree) { void RasterizerDirect::Draw(scoped_ptr<compositor::LayerTree> layer_tree) {
TRACE_EVENT0("sky", "Rasterizer::Draw"); TRACE_EVENT0("sky", "RasterizerDirect::Draw");
if (!surface_) if (!surface_)
return; return;
...@@ -59,12 +58,11 @@ void Rasterizer::Draw(scoped_ptr<compositor::LayerTree> layer_tree) { ...@@ -59,12 +58,11 @@ void Rasterizer::Draw(scoped_ptr<compositor::LayerTree> layer_tree) {
// for instrumentation. // for instrumentation.
paint_context_.engine_time().setLapTime(layer_tree->construction_time()); paint_context_.engine_time().setLapTime(layer_tree->construction_time());
// Use the canvas from the Ganesh Surface to render the current frame into
{ {
EnsureGLContext(); EnsureGLContext();
CHECK(context_->MakeCurrent(surface_.get())); CHECK(context_->MakeCurrent(surface_.get()));
EnsureGaneshSurface(surface_->GetBackingFrameBufferObject(), size); SkCanvas* canvas = ganesh_canvas_.GetCanvas(
SkCanvas* canvas = ganesh_surface_->canvas(); surface_->GetBackingFrameBufferObject(), layer_tree->frame_size());
sky::compositor::PaintContext::ScopedFrame frame = sky::compositor::PaintContext::ScopedFrame frame =
paint_context_.AcquireFrame(*canvas); paint_context_.AcquireFrame(*canvas);
canvas->clear(SK_ColorBLACK); canvas->clear(SK_ColorBLACK);
...@@ -94,34 +92,26 @@ void Rasterizer::Draw(scoped_ptr<compositor::LayerTree> layer_tree) { ...@@ -94,34 +92,26 @@ void Rasterizer::Draw(scoped_ptr<compositor::LayerTree> layer_tree) {
} }
} }
void Rasterizer::OnOutputSurfaceDestroyed() { void RasterizerDirect::OnOutputSurfaceDestroyed() {
if (context_) { if (context_) {
CHECK(context_->MakeCurrent(surface_.get())); CHECK(context_->MakeCurrent(surface_.get()));
ganesh_surface_.reset(); ganesh_canvas_.SetGrGLInterface(nullptr);
ganesh_context_.reset();
context_ = nullptr; context_ = nullptr;
} }
CHECK(!ganesh_surface_); CHECK(!ganesh_canvas_.IsValid());
CHECK(!ganesh_context_);
CHECK(!context_); CHECK(!context_);
surface_ = nullptr; surface_ = nullptr;
} }
void Rasterizer::EnsureGLContext() { void RasterizerDirect::EnsureGLContext() {
if (context_) if (context_)
return; return;
context_ = gfx::GLContext::CreateGLContext(share_group_.get(), surface_.get(), context_ = gfx::GLContext::CreateGLContext(share_group_.get(), surface_.get(),
gfx::PreferIntegratedGpu); gfx::PreferIntegratedGpu);
CHECK(context_) << "GLContext required."; CHECK(context_) << "GLContext required.";
CHECK(context_->MakeCurrent(surface_.get())); CHECK(context_->MakeCurrent(surface_.get()));
ganesh_context_.reset(new GaneshContext(context_.get())); gr_gl_interface_ = skia::AdoptRef(gfx::CreateInProcessSkiaGLBinding());
} ganesh_canvas_.SetGrGLInterface(gr_gl_interface_.get());
void Rasterizer::EnsureGaneshSurface(intptr_t window_fbo,
const gfx::Size& size) {
if (!ganesh_surface_ || ganesh_surface_->size() != size)
ganesh_surface_.reset(
new GaneshSurface(window_fbo, ganesh_context_.get(), size));
} }
} // namespace shell } // namespace shell
......
...@@ -8,12 +8,11 @@ ...@@ -8,12 +8,11 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "skia/ext/refptr.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/gpu_delegate.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "sky/compositor/paint_context.h"
class SkPicture;
namespace gfx { namespace gfx {
class GLContext; class GLContext;
...@@ -26,12 +25,12 @@ namespace shell { ...@@ -26,12 +25,12 @@ namespace shell {
class GaneshContext; class GaneshContext;
class GaneshSurface; class GaneshSurface;
class Rasterizer : public GPUDelegate { class RasterizerDirect : public GPUDelegate {
public: public:
explicit Rasterizer(); explicit RasterizerDirect();
~Rasterizer() override; ~RasterizerDirect() override;
base::WeakPtr<Rasterizer> GetWeakPtr(); base::WeakPtr<RasterizerDirect> GetWeakPtr();
void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override; void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override;
void OnOutputSurfaceDestroyed() override; void OnOutputSurfaceDestroyed() override;
...@@ -45,14 +44,14 @@ class Rasterizer : public GPUDelegate { ...@@ -45,14 +44,14 @@ class Rasterizer : public GPUDelegate {
scoped_refptr<gfx::GLSurface> surface_; scoped_refptr<gfx::GLSurface> surface_;
scoped_refptr<gfx::GLContext> context_; scoped_refptr<gfx::GLContext> context_;
scoped_ptr<GaneshContext> ganesh_context_; skia::RefPtr<const GrGLInterface> gr_gl_interface_;
scoped_ptr<GaneshSurface> ganesh_surface_; GaneshCanvas ganesh_canvas_;
compositor::PaintContext paint_context_; compositor::PaintContext paint_context_;
base::WeakPtrFactory<Rasterizer> weak_factory_; base::WeakPtrFactory<RasterizerDirect> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(Rasterizer); DISALLOW_COPY_AND_ASSIGN(RasterizerDirect);
}; };
} // namespace shell } // namespace shell
......
...@@ -2,11 +2,10 @@ ...@@ -2,11 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "sky/shell/gpu/direct/ganesh_context.h" #include "sky/shell/gpu/ganesh_canvas.h"
#include "base/logging.h" #include "base/logging.h"
#include "third_party/skia/include/gpu/gl/GrGLInterface.h" #include "third_party/skia/include/gpu/gl/GrGLInterface.h"
#include "ui/gl/gl_bindings_skia_in_process.h"
namespace sky { namespace sky {
namespace shell { namespace shell {
...@@ -22,21 +21,50 @@ const size_t kMaxGaneshResourceCacheBytes = 96 * 1024 * 1024; ...@@ -22,21 +21,50 @@ const size_t kMaxGaneshResourceCacheBytes = 96 * 1024 * 1024;
} // namespace } // namespace
GaneshContext::GaneshContext(scoped_refptr<gfx::GLContext> gl_context) GaneshCanvas::GaneshCanvas() {
: gl_context_(gl_context) {
skia::RefPtr<const GrGLInterface> interface =
skia::AdoptRef(gfx::CreateInProcessSkiaGLBinding());
DCHECK(interface);
gr_context_ = skia::AdoptRef(GrContext::Create(
kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(interface.get())));
DCHECK(gr_context_) << "Failed to create GrContext.";
gr_context_->setResourceCacheLimits(kMaxGaneshResourceCacheCount,
kMaxGaneshResourceCacheBytes);
} }
GaneshContext::~GaneshContext() { GaneshCanvas::~GaneshCanvas() {
gr_context_->abandonContext(); }
void GaneshCanvas::SetGrGLInterface(const GrGLInterface* interface) {
sk_surface_.clear();
if (interface) {
gr_context_ = skia::AdoptRef(GrContext::Create(kOpenGL_GrBackend,
reinterpret_cast<GrBackendContext>(interface)));
DCHECK(gr_context_);
gr_context_->setResourceCacheLimits(kMaxGaneshResourceCacheCount,
kMaxGaneshResourceCacheBytes);
} else if (gr_context_) {
gr_context_->abandonContext();
gr_context_.clear();
}
}
SkCanvas* GaneshCanvas::GetCanvas(int32_t fbo, const SkISize& size) {
DCHECK(IsValid());
if (sk_surface_ && sk_surface_->width() == size.width()
&& sk_surface_->height() == size.height())
return sk_surface_->getCanvas();
GrBackendRenderTargetDesc desc;
desc.fWidth = size.width();
desc.fHeight = size.height();
desc.fConfig = kSkia8888_GrPixelConfig;
desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
desc.fRenderTargetHandle = fbo;
skia::RefPtr<GrRenderTarget> target = skia::AdoptRef(
gr_context_->textureProvider()->wrapBackendRenderTarget(desc));
DCHECK(target);
sk_surface_ = skia::AdoptRef(SkSurface::NewRenderTargetDirect(target.get()));
DCHECK(sk_surface_);
return sk_surface_->getCanvas();
}
bool GaneshCanvas::IsValid() {
return gr_context_;
} }
} // namespace shell } // namespace shell
......
...@@ -2,36 +2,38 @@ ...@@ -2,36 +2,38 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef SKY_SHELL_GPU_DIRECT_GANESH_CONTEXT_H_ #ifndef SKY_SHELL_GPU_GANESH_CANVAS_H_
#define SKY_SHELL_GPU_DIRECT_GANESH_CONTEXT_H_ #define SKY_SHELL_GPU_GANESH_CANVAS_H_
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "skia/ext/refptr.h" #include "skia/ext/refptr.h"
#include "third_party/skia/include/core/SkSize.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/gl/GrGLInterface.h"
#include "third_party/skia/include/gpu/gl/GrGLInterface.h"
#include "third_party/skia/include/gpu/GrContext.h" #include "third_party/skia/include/gpu/GrContext.h"
#include "ui/gl/gl_context.h"
namespace sky { namespace sky {
namespace shell { namespace shell {
// GaneshContext holds the top-level context object for Ganesh (known as class GaneshCanvas {
// GrContext). We construct the GrContext using the OpenGL interface provided by
// gfx::GLContext.
class GaneshContext {
public: public:
explicit GaneshContext(scoped_refptr<gfx::GLContext> gl_context); GaneshCanvas();
~GaneshContext(); ~GaneshCanvas();
GrContext* gr() const { return gr_context_.get(); } void SetGrGLInterface(const GrGLInterface* interface);
SkCanvas* GetCanvas(int32_t fbo, const SkISize& size);
bool IsValid();
private: private:
scoped_refptr<gfx::GLContext> gl_context_;
skia::RefPtr<GrContext> gr_context_; skia::RefPtr<GrContext> gr_context_;
skia::RefPtr<SkSurface> sk_surface_;
DISALLOW_COPY_AND_ASSIGN(GaneshContext); DISALLOW_COPY_AND_ASSIGN(GaneshCanvas);
}; };
} // namespace shell } // namespace shell
} // namespace sky } // namespace sky
#endif // SKY_SHELL_GPU_DIRECT_GANESH_CONTEXT_H_ #endif // SKY_SHELL_GPU_GANESH_CANVAS_H_
// 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/mojo/rasterizer_mojo.h"
#include "base/trace_event/trace_event.h"
#include "mojo/public/c/gpu/MGL/mgl.h"
#include "mojo/public/c/gpu/MGL/mgl_onscreen.h"
#include "mojo/skia/gl_bindings_skia.h"
#include "third_party/skia/include/core/SkCanvas.h"
namespace sky {
namespace shell {
namespace {
void ContextLostThunk(void* closure) {
static_cast<RasterizerMojo*>(closure)->OnContextLost();
}
} // namespace
RasterizerMojo::RasterizerMojo() {
}
RasterizerMojo::~RasterizerMojo() {
}
void RasterizerMojo::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) {
}
void RasterizerMojo::OnOutputSurfaceDestroyed() {
}
void RasterizerMojo::Draw(scoped_ptr<compositor::LayerTree> layer_tree) {
TRACE_EVENT0("sky", "RasterizerMojo::Draw");
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);
canvas->flush();
MGLSwapBuffers();
}
void RasterizerMojo::OnContextProviderAvailable(
mojo::InterfacePtrInfo<mojo::ContextProvider> context_provider) {
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) {
context_ = MGLCreateContext(
MGL_API_VERSION_GLES2,
command_buffer.PassInterface().PassHandle().release().value(),
MGL_NO_CONTEXT, &ContextLostThunk, this,
mojo::Environment::GetDefaultAsyncWaiter());
MGLMakeCurrent(context_);
ganesh_canvas_.SetGrGLInterface(gr_gl_interface_.get());
}
void RasterizerMojo::OnContextLost() {
ganesh_canvas_.SetGrGLInterface(nullptr);
MGLDestroyContext(context_);
context_ = nullptr;
context_provider_->Create(nullptr,
base::Bind(&RasterizerMojo::OnContextCreated, base::Unretained(this)));
}
} // 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_MOJO_RASTERIZER_MOJO_H_
#define SKY_SHELL_GPU_MOJO_RASTERIZER_MOJO_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"
namespace sky {
namespace shell {
class RasterizerMojo : public GPUDelegate {
public:
explicit RasterizerMojo();
~RasterizerMojo() override;
void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override;
void OnOutputSurfaceDestroyed() override;
void Draw(scoped_ptr<compositor::LayerTree> layer_tree) override;
void OnContextProviderAvailable(
mojo::InterfacePtrInfo<mojo::ContextProvider> context_provder);
void OnContextLost();
private:
SkCanvas* GetCanvas(const SkISize& size);
void OnContextCreated(mojo::CommandBufferPtr command_buffer);
mojo::ContextProviderPtr context_provider_;
skia::RefPtr<GrGLInterface> gr_gl_interface_;
MGLContext context_;
GaneshCanvas ganesh_canvas_;
DISALLOW_COPY_AND_ASSIGN(RasterizerMojo);
};
} // namespace shell
} // namespace sky
#endif // SKY_SHELL_GPU_MOJO_RASTERIZER_MOJO_H_
...@@ -78,7 +78,7 @@ static void Init(JNIEnv* env, ...@@ -78,7 +78,7 @@ static void Init(JNIEnv* env,
mojo::embedder::Init(std::unique_ptr<mojo::embedder::PlatformSupport>( mojo::embedder::Init(std::unique_ptr<mojo::embedder::PlatformSupport>(
new mojo::embedder::SimplePlatformSupport())); new mojo::embedder::SimplePlatformSupport()));
Shell::Init(make_scoped_ptr(new ServiceProviderContext( Shell::InitStandalone(make_scoped_ptr(new ServiceProviderContext(
g_java_message_loop.Get()->task_runner()))); g_java_message_loop.Get()->task_runner())));
InitializeTracing(); InitializeTracing();
......
...@@ -31,7 +31,7 @@ int main(int argc, const char* argv[]) { ...@@ -31,7 +31,7 @@ int main(int argc, const char* argv[]) {
mojo::embedder::Init(std::unique_ptr<mojo::embedder::PlatformSupport>( mojo::embedder::Init(std::unique_ptr<mojo::embedder::PlatformSupport>(
new mojo::embedder::SimplePlatformSupport())); new mojo::embedder::SimplePlatformSupport()));
sky::shell::Shell::Init(make_scoped_ptr( sky::shell::Shell::InitStandalone(make_scoped_ptr(
new sky::shell::ServiceProviderContext(message_loop.task_runner()))); new sky::shell::ServiceProviderContext(message_loop.task_runner())));
if (!sky::shell::InitForTesting()) { if (!sky::shell::InitForTesting()) {
......
...@@ -65,7 +65,7 @@ int PlatformMacMain(int argc, ...@@ -65,7 +65,7 @@ int PlatformMacMain(int argc,
mojo::embedder::Init(std::unique_ptr<mojo::embedder::PlatformSupport>( mojo::embedder::Init(std::unique_ptr<mojo::embedder::PlatformSupport>(
new mojo::embedder::SimplePlatformSupport())); new mojo::embedder::SimplePlatformSupport()));
sky::shell::Shell::Init(make_scoped_ptr( sky::shell::Shell::InitStandalone(make_scoped_ptr(
new sky::shell::ServiceProviderContext(message_loop->task_runner()))); new sky::shell::ServiceProviderContext(message_loop->task_runner())));
result = callback(); result = callback();
......
...@@ -9,10 +9,14 @@ mojo_native_application("mojo") { ...@@ -9,10 +9,14 @@ mojo_native_application("mojo") {
output_name = "sky_shell" output_name = "sky_shell"
sources = [ sources = [
"content_handler_impl.cc",
"content_handler_impl.h",
"main_mojo.cc", "main_mojo.cc",
"platform_service_provider_mojo.cc", "platform_service_provider_mojo.cc",
"platform_view_mojo.cc", "platform_view_mojo.cc",
"platform_view_mojo.h", "platform_view_mojo.h",
"sky_application_impl.cc",
"sky_application_impl.h",
] ]
deps = [ deps = [
...@@ -25,15 +29,16 @@ mojo_native_application("mojo") { ...@@ -25,15 +29,16 @@ mojo_native_application("mojo") {
"//mojo/public/cpp/system", "//mojo/public/cpp/system",
"//mojo/public/cpp/utility", "//mojo/public/cpp/utility",
"//mojo/public/interfaces/application", "//mojo/public/interfaces/application",
"//mojo/services/asset_bundle/interfaces",
"//mojo/services/content_handler/interfaces", "//mojo/services/content_handler/interfaces",
"//mojo/services/gpu/interfaces", "//mojo/services/gpu/interfaces",
"//mojo/services/input_events/interfaces", "//mojo/services/input_events/interfaces",
"//mojo/services/navigation/interfaces", "//mojo/services/navigation/interfaces",
"//mojo/services/network/interfaces", "//mojo/services/network/interfaces",
"//mojo/services/native_viewport/interfaces",
"//mojo/services/service_registry/interfaces", "//mojo/services/service_registry/interfaces",
"//mojo/services/surfaces/interfaces", "//mojo/services/surfaces/interfaces",
"//mojo/services/view_manager/cpp", "//mojo/services/ui/views/interfaces",
"//mojo/services/view_manager/interfaces",
"//services/asset_bundle:lib", "//services/asset_bundle:lib",
"//services/sky/compositor", "//services/sky/compositor",
"//skia", "//skia",
...@@ -44,4 +49,11 @@ mojo_native_application("mojo") { ...@@ -44,4 +49,11 @@ mojo_native_application("mojo") {
"//third_party/icu", "//third_party/icu",
"//url", "//url",
] ]
if (is_android) {
ldflags = [
"-lGLESv2",
"-lEGL",
]
}
} }
// 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/platform/mojo/content_handler_impl.h"
#include "sky/shell/platform/mojo/sky_application_impl.h"
namespace sky {
namespace shell {
ContentHandlerImpl::ContentHandlerImpl(
mojo::InterfaceRequest<mojo::ContentHandler> request)
: binding_(this, request.Pass()) {
}
ContentHandlerImpl::~ContentHandlerImpl() {
}
void ContentHandlerImpl::StartApplication(
mojo::InterfaceRequest<mojo::Application> application,
mojo::URLResponsePtr response) {
new SkyApplicationImpl(application.Pass(), response.Pass());
}
} // 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_PLATFORM_MOJO_CONTENT_HANDLER_IMPL_H_
#define SKY_SHELL_PLATFORM_MOJO_CONTENT_HANDLER_IMPL_H_
#include "base/message_loop/message_loop.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/interfaces/application/shell.mojom.h"
#include "mojo/services/content_handler/interfaces/content_handler.mojom.h"
namespace sky {
namespace shell {
class ContentHandlerImpl : public mojo::ContentHandler {
public:
explicit ContentHandlerImpl(
mojo::InterfaceRequest<mojo::ContentHandler> request);
~ContentHandlerImpl() override;
private:
// Overridden from ContentHandler:
void StartApplication(mojo::InterfaceRequest<mojo::Application> application,
mojo::URLResponsePtr response) override;
mojo::StrongBinding<mojo::ContentHandler> binding_;
DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl);
};
} // namespace shell
} // namespace sky
#endif // SKY_SHELL_PLATFORM_MOJO_CONTENT_HANDLER_IMPL_H_
// 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 // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "mojo/services/content_handler/interfaces/content_handler.mojom.h" #include "mojo/services/content_handler/interfaces/content_handler.mojom.h"
#include "sky/shell/shell.h" #include "sky/shell/shell.h"
#include "sky/shell/service_provider.h" #include "sky/shell/service_provider.h"
#include "sky/shell/platform/mojo/content_handler_impl.h"
namespace sky { namespace sky {
namespace shell { namespace shell {
...@@ -45,6 +46,7 @@ class MojoApp : public mojo::ApplicationDelegate, ...@@ -45,6 +46,7 @@ class MojoApp : public mojo::ApplicationDelegate,
// Overridden from InterfaceFactory<ContentHandler> // Overridden from InterfaceFactory<ContentHandler>
void Create(mojo::ApplicationConnection* connection, void Create(mojo::ApplicationConnection* connection,
mojo::InterfaceRequest<mojo::ContentHandler> request) override { mojo::InterfaceRequest<mojo::ContentHandler> request) override {
new ContentHandlerImpl(request.Pass());
} }
mojo::TracingImpl tracing_; mojo::TracingImpl tracing_;
......
...@@ -11,9 +11,63 @@ PlatformView* PlatformView::Create(const Config& config) { ...@@ -11,9 +11,63 @@ PlatformView* PlatformView::Create(const Config& config) {
return new PlatformViewMojo(config); return new PlatformViewMojo(config);
} }
PlatformViewMojo::PlatformViewMojo(const Config& config) : PlatformView(config) {} PlatformViewMojo::PlatformViewMojo(const Config& config)
: PlatformView(config), dispatcher_binding_(this) {
}
PlatformViewMojo::~PlatformViewMojo() {
}
void PlatformViewMojo::Init(mojo::ApplicationImpl* app) {
app->ConnectToService("mojo:native_viewport_service", &viewport_);
mojo::NativeViewportEventDispatcherPtr ptr;
dispatcher_binding_.Bind(GetProxy(&ptr));
viewport_->SetEventDispatcher(ptr.Pass());
mojo::SizePtr size = mojo::Size::New();
size->width = 800;
size->height = 600;
viewport_->Create(
size.Clone(),
mojo::SurfaceConfiguration::New(),
[this](mojo::ViewportMetricsPtr metrics) {
OnMetricsChanged(metrics.Pass());
});
viewport_->Show();
viewport_->GetContextProvider(GetProxy(&context_provider_));
PlatformViewMojo::~PlatformViewMojo() {} // TODO(abarth): Move the to GPU thread.
context_provider_.PassInterface();
}
void PlatformViewMojo::Run(const mojo::String& url,
mojo::asset_bundle::AssetBundlePtr bundle) {
ConnectToEngine(mojo::GetProxy(&sky_engine_));
sky_engine_->RunFromAssetBundle(url, bundle.Pass());
}
void PlatformViewMojo::OnMetricsChanged(mojo::ViewportMetricsPtr metrics) {
DCHECK(metrics);
viewport_->RequestMetrics(
[this](mojo::ViewportMetricsPtr metrics) {
OnMetricsChanged(metrics.Pass());
});
sky::ViewportMetricsPtr sky_metrics = sky::ViewportMetrics::New();
sky_metrics->physical_width = metrics->size->width;
sky_metrics->physical_height = metrics->size->height;
sky_metrics->device_pixel_ratio = metrics->device_pixel_ratio;
sky_engine_->OnViewportMetricsChanged(sky_metrics.Pass());
}
void PlatformViewMojo::OnEvent(mojo::EventPtr event,
const mojo::Callback<void()>& callback) {
DCHECK(event);
callback.Run();
}
} // namespace shell } // namespace shell
} // namespace sky } // namespace sky
...@@ -5,17 +5,39 @@ ...@@ -5,17 +5,39 @@
#ifndef SKY_SHELL_PLATFORM_MOJO_PLATFORM_VIEW_MOJO_H_ #ifndef SKY_SHELL_PLATFORM_MOJO_PLATFORM_VIEW_MOJO_H_
#define SKY_SHELL_PLATFORM_MOJO_PLATFORM_VIEW_MOJO_H_ #define SKY_SHELL_PLATFORM_MOJO_PLATFORM_VIEW_MOJO_H_
#include "mojo/public/cpp/application/application_impl.h"
#include "mojo/public/interfaces/application/service_provider.mojom.h"
#include "mojo/services/asset_bundle/interfaces/asset_bundle.mojom.h"
#include "mojo/services/native_viewport/interfaces/native_viewport.mojom.h"
#include "sky/shell/platform_view.h" #include "sky/shell/platform_view.h"
namespace sky { namespace sky {
namespace shell { namespace shell {
class PlatformViewMojo : public PlatformView { class PlatformViewMojo : public PlatformView,
public mojo::NativeViewportEventDispatcher {
public: public:
explicit PlatformViewMojo(const Config& config); explicit PlatformViewMojo(const Config& config);
~PlatformViewMojo() override; ~PlatformViewMojo() override;
void Init(mojo::ApplicationImpl* app);
void Run(const mojo::String& url,
mojo::asset_bundle::AssetBundlePtr bundle);
private: private:
void OnMetricsChanged(mojo::ViewportMetricsPtr metrics);
// mojo::NativeViewportEventDispatcher
void OnEvent(mojo::EventPtr event,
const mojo::Callback<void()>& callback) override;
mojo::NativeViewportPtr viewport_;
mojo::ContextProviderPtr context_provider_;
mojo::Binding<NativeViewportEventDispatcher> dispatcher_binding_;
sky::SkyEnginePtr sky_engine_;
DISALLOW_COPY_AND_ASSIGN(PlatformViewMojo); DISALLOW_COPY_AND_ASSIGN(PlatformViewMojo);
}; };
......
// 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/platform/mojo/sky_application_impl.h"
#include "mojo/public/cpp/application/connect.h"
#include "mojo/public/cpp/utility/run_loop.h"
#include "sky/shell/shell.h"
namespace sky {
namespace shell {
SkyApplicationImpl::SkyApplicationImpl(
mojo::InterfaceRequest<mojo::Application> application,
mojo::URLResponsePtr response)
: app_(this, application.Pass()),
initial_response_(response.Pass()) {
}
SkyApplicationImpl::~SkyApplicationImpl() {
}
void SkyApplicationImpl::Initialize(mojo::ApplicationImpl* app) {
DCHECK(initial_response_);
UnpackInitialResponse();
shell_view_.reset(new ShellView(Shell::Shared()));
PlatformViewMojo* view = platform_view();
view->Init(app);
view->Run(app_.url(), bundle_.Pass());
}
bool SkyApplicationImpl::ConfigureIncomingConnection(
mojo::ApplicationConnection* connection) {
return true;
}
void SkyApplicationImpl::UnpackInitialResponse() {
DCHECK(initial_response_);
DCHECK(!bundle_);
mojo::asset_bundle::AssetUnpackerPtr unpacker;
app_.ConnectToService("mojo:asset_bundle", &unpacker);
unpacker->UnpackZipStream(initial_response_->body.Pass(),
mojo::GetProxy(&bundle_));
initial_response_ = nullptr;
}
} // 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_PLATFORM_MOJO_SKY_APPLICATION_IMPL_H_
#define SKY_SHELL_PLATFORM_MOJO_SKY_APPLICATION_IMPL_H_
#include "base/message_loop/message_loop.h"
#include "mojo/public/cpp/application/application_impl.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/interfaces/application/shell.mojom.h"
#include "mojo/services/asset_bundle/interfaces/asset_bundle.mojom.h"
#include "mojo/services/content_handler/interfaces/content_handler.mojom.h"
#include "sky/shell/platform/mojo/platform_view_mojo.h"
#include "sky/shell/shell_view.h"
namespace sky {
namespace shell {
class SkyApplicationImpl : public mojo::ApplicationDelegate {
public:
SkyApplicationImpl(mojo::InterfaceRequest<mojo::Application> application,
mojo::URLResponsePtr response);
~SkyApplicationImpl() override;
private:
// mojo::ApplicationDelegate
void Initialize(mojo::ApplicationImpl* app) override;
bool ConfigureIncomingConnection(
mojo::ApplicationConnection* connection) override;
PlatformViewMojo* platform_view() {
return static_cast<PlatformViewMojo*>(shell_view_->view());
}
void UnpackInitialResponse();
mojo::ApplicationImpl app_;
mojo::URLResponsePtr initial_response_;
mojo::asset_bundle::AssetBundlePtr bundle_;
scoped_ptr<ShellView> shell_view_;
};
} // namespace shell
} // namespace sky
#endif // SKY_SHELL_PLATFORM_MOJO_SKY_APPLICATION_IMPL_H_
...@@ -74,11 +74,16 @@ Shell::Shell(scoped_ptr<ServiceProviderContext> service_provider_context) ...@@ -74,11 +74,16 @@ Shell::Shell(scoped_ptr<ServiceProviderContext> service_provider_context)
Shell::~Shell() { Shell::~Shell() {
} }
void Shell::Init(scoped_ptr<ServiceProviderContext> service_provider_context) { void Shell::InitStandalone(
scoped_ptr<ServiceProviderContext> service_provider_context) {
CHECK(base::i18n::InitializeICU()); CHECK(base::i18n::InitializeICU());
#if !defined(OS_LINUX) #if !defined(OS_LINUX)
CHECK(gfx::GLSurface::InitializeOneOff()); CHECK(gfx::GLSurface::InitializeOneOff());
#endif #endif
Init(service_provider_context.Pass());
}
void Shell::Init(scoped_ptr<ServiceProviderContext> service_provider_context) {
base::DiscardableMemoryAllocator::SetInstance(&g_discardable.Get()); base::DiscardableMemoryAllocator::SetInstance(&g_discardable.Get());
g_shell = new Shell(service_provider_context.Pass()); g_shell = new Shell(service_provider_context.Pass());
......
...@@ -21,8 +21,13 @@ class Shell { ...@@ -21,8 +21,13 @@ class Shell {
public: public:
~Shell(); ~Shell();
// Init the shell to stand alone from MojoShell.
static void InitStandalone(
scoped_ptr<ServiceProviderContext> service_provider_context);
// Init the shell to run inside MojoShell.
static void Init( static void Init(
scoped_ptr<ServiceProviderContext> service_provider_context); scoped_ptr<ServiceProviderContext> service_provider_context);
static Shell& Shared(); static Shell& Shared();
base::SingleThreadTaskRunner* gpu_task_runner() const { base::SingleThreadTaskRunner* gpu_task_runner() const {
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "sky/shell/gpu/direct/rasterizer.h" #include "sky/shell/gpu/direct/rasterizer_direct.h"
#include "sky/shell/platform_view.h" #include "sky/shell/platform_view.h"
#include "sky/shell/shell.h" #include "sky/shell/shell.h"
#include "sky/shell/ui/engine.h" #include "sky/shell/ui/engine.h"
...@@ -23,7 +23,7 @@ void Drop(scoped_ptr<T> ptr) { } ...@@ -23,7 +23,7 @@ void Drop(scoped_ptr<T> ptr) { }
ShellView::ShellView(Shell& shell) ShellView::ShellView(Shell& shell)
: shell_(shell) { : shell_(shell) {
shell_.tracing_controller().RegisterShellView(this); shell_.tracing_controller().RegisterShellView(this);
rasterizer_.reset(new Rasterizer()); rasterizer_.reset(new RasterizerDirect());
CreateEngine(); CreateEngine();
CreatePlatformView(); CreatePlatformView();
} }
...@@ -31,7 +31,7 @@ ShellView::ShellView(Shell& shell) ...@@ -31,7 +31,7 @@ ShellView::ShellView(Shell& shell)
ShellView::~ShellView() { ShellView::~ShellView() {
shell_.tracing_controller().UnregisterShellView(this); shell_.tracing_controller().UnregisterShellView(this);
shell_.gpu_task_runner()->PostTask(FROM_HERE, shell_.gpu_task_runner()->PostTask(FROM_HERE,
base::Bind(&Drop<Rasterizer>, base::Passed(&rasterizer_))); base::Bind(&Drop<RasterizerDirect>, base::Passed(&rasterizer_)));
shell_.ui_task_runner()->PostTask(FROM_HERE, shell_.ui_task_runner()->PostTask(FROM_HERE,
base::Bind(&Drop<Engine>, base::Passed(&engine_))); base::Bind(&Drop<Engine>, base::Passed(&engine_)));
} }
......
...@@ -14,7 +14,7 @@ namespace sky { ...@@ -14,7 +14,7 @@ namespace sky {
namespace shell { namespace shell {
class Engine; class Engine;
class PlatformView; class PlatformView;
class Rasterizer; class RasterizerDirect;
class Shell; class Shell;
class ShellView { class ShellView {
...@@ -33,7 +33,7 @@ class ShellView { ...@@ -33,7 +33,7 @@ class ShellView {
Shell& shell_; Shell& shell_;
scoped_ptr<PlatformView> view_; scoped_ptr<PlatformView> view_;
scoped_ptr<Rasterizer> rasterizer_; scoped_ptr<RasterizerDirect> rasterizer_;
scoped_ptr<Engine> engine_; scoped_ptr<Engine> engine_;
DISALLOW_COPY_AND_ASSIGN(ShellView); DISALLOW_COPY_AND_ASSIGN(ShellView);
......
...@@ -233,6 +233,15 @@ void Engine::RunFromBundle(const mojo::String& path) { ...@@ -233,6 +233,15 @@ void Engine::RunFromBundle(const mojo::String& path) {
weak_factory_.GetWeakPtr(), path_str)); weak_factory_.GetWeakPtr(), path_str));
} }
void Engine::RunFromAssetBundle(const mojo::String& url,
mojo::asset_bundle::AssetBundlePtr bundle) {
std::string url_str = url;
root_bundle_ = bundle.Pass();
root_bundle_->GetAsStream(kSnapshotKey,
base::Bind(&Engine::RunFromSnapshotStream,
weak_factory_.GetWeakPtr(), url_str));
}
void Engine::OnActivityPaused() { void Engine::OnActivityPaused() {
activity_running_ = false; activity_running_ = false;
StopAnimator(); StopAnimator();
......
...@@ -77,6 +77,8 @@ class Engine : public UIDelegate, ...@@ -77,6 +77,8 @@ class Engine : public UIDelegate,
void RunFromPrecompiledSnapshot(const mojo::String& bundle_path) override; void RunFromPrecompiledSnapshot(const mojo::String& bundle_path) override;
void RunFromSnapshot(const mojo::String& path) override; void RunFromSnapshot(const mojo::String& path) override;
void RunFromBundle(const mojo::String& path) override; void RunFromBundle(const mojo::String& path) override;
void RunFromAssetBundle(const mojo::String& url,
mojo::asset_bundle::AssetBundlePtr bundle) override;
void OnActivityPaused() override; void OnActivityPaused() override;
void OnActivityResumed() override; void OnActivityResumed() override;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册