提交 827e6212 编写于 作者: E Eric Seidel

Teach sky_viewer about the new main.dart hotness

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/1147413003
上级 045620e0
......@@ -23,6 +23,7 @@ source_set("libraries") {
"//mojo/public/interfaces/application",
"//mojo/services/keyboard/public/interfaces",
"//mojo/services/navigation/public/interfaces",
"//mojo/services/network/public/interfaces",
"//mojo/services/view_manager/public/cpp",
"//skia",
"//sky/engine/tonic:tonic",
......
......@@ -120,10 +120,10 @@ void DartController::DidLoadMainLibrary(KURL url) {
DartInvokeAppField(library, ToDart("main"), 0, nullptr);
}
void DartController::LoadMainLibrary(const KURL& url) {
void DartController::LoadMainLibrary(const KURL& url, mojo::URLResponsePtr response) {
DartLoader& loader = dart_state()->loader();
DartDependencyCatcher dependency_catcher(loader);
loader.LoadLibrary(url);
loader.LoadLibrary(url, response.Pass());
loader.WaitForDependencies(dependency_catcher.dependencies(),
base::Bind(&DartController::DidLoadMainLibrary, weak_factory_.GetWeakPtr(), url));
}
......
......@@ -9,6 +9,7 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "dart/runtime/include/dart_api.h"
#include "mojo/services/network/public/interfaces/url_loader.mojom.h"
#include "sky/engine/wtf/OwnPtr.h"
#include "sky/engine/wtf/text/AtomicString.h"
#include "sky/engine/wtf/text/TextPosition.h"
......@@ -32,7 +33,8 @@ class DartController {
typedef base::Callback<void(RefPtr<AbstractModule>, RefPtr<DartValue>)>
LoadFinishedCallback;
void LoadMainLibrary(const KURL& url);
// Can either issue the url load ourselves or take an existing response:
void LoadMainLibrary(const KURL& url, mojo::URLResponsePtr response = nullptr);
void LoadScriptInModule(AbstractModule* module,
const String& source,
......
......@@ -47,8 +47,15 @@ class DartLoader::Job : public DartDependency,
public MojoFetcher::Client,
public DataPipeDrainer::Client {
public:
Job(DartLoader* loader, const KURL& url)
: loader_(loader), url_(url), fetcher_(this, url) {}
Job(DartLoader* loader, const KURL& url, mojo::URLResponsePtr response)
: loader_(loader), url_(url)
{
if (!response) {
fetcher_ = adoptPtr(new MojoFetcher(this, url));
} else {
OnReceivedResponse(response.Pass());
}
}
const KURL& url() const { return url_; }
......@@ -74,14 +81,14 @@ class DartLoader::Job : public DartDependency,
// Subclasses must implement OnDataComplete.
KURL url_;
MojoFetcher fetcher_;
OwnPtr<MojoFetcher> fetcher_;
OwnPtr<DataPipeDrainer> drainer_;
};
class DartLoader::ImportJob : public Job {
public:
ImportJob(DartLoader* loader, const KURL& url)
: Job(loader, url) {
ImportJob(DartLoader* loader, const KURL& url, mojo::URLResponsePtr response = nullptr)
: Job(loader, url, response.Pass()) {
TRACE_EVENT_ASYNC_BEGIN1("sky", "DartLoader::ImportJob", this,
"url", url.string().ascii().toStdString());
}
......@@ -97,7 +104,7 @@ class DartLoader::ImportJob : public Job {
class DartLoader::SourceJob : public Job {
public:
SourceJob(DartLoader* loader, const KURL& url, Dart_Handle library)
: Job(loader, url), library_(loader->dart_state(), library) {
: Job(loader, url, nullptr), library_(loader->dart_state(), library) {
TRACE_EVENT_ASYNC_BEGIN1("sky", "DartLoader::SourceJob", this,
"url", url.string().ascii().toStdString());
}
......@@ -231,7 +238,7 @@ void DartLoader::WaitForDependencies(
adoptPtr(new DependencyWatcher(dependencies, callback)));
}
void DartLoader::LoadLibrary(const KURL& url) {
void DartLoader::LoadLibrary(const KURL& url, mojo::URLResponsePtr response) {
const auto& result = pending_libraries_.add(url.string(), nullptr);
if (result.isNewEntry) {
OwnPtr<Job> job = adoptPtr(new ImportJob(this, url));
......
......@@ -9,6 +9,7 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "dart/runtime/include/dart_api.h"
#include "mojo/services/network/public/interfaces/url_loader.mojom.h"
#include "sky/engine/wtf/HashMap.h"
#include "sky/engine/wtf/HashSet.h"
#include "sky/engine/wtf/OwnPtr.h"
......@@ -35,7 +36,7 @@ class DartLoader {
Dart_Handle library,
Dart_Handle url);
void LoadLibrary(const KURL& url);
void LoadLibrary(const KURL& url, mojo::URLResponsePtr response = nullptr);
void WaitForDependencies(const HashSet<DartDependency*>& dependencies,
const base::Closure& callback);
......
......@@ -8,6 +8,7 @@ source_set("sky") {
"//skia",
"//sky/engine/core",
"//sky/engine/platform",
"//mojo/services/network/public/interfaces",
]
configs += [
......
......@@ -47,7 +47,7 @@ void SkyView::SetDisplayMetrics(const SkyDisplayMetrics& metrics) {
data_->view_->setDisplayMetrics(display_metrics_);
}
void SkyView::Load(const WebURL& url) {
void SkyView::Load(const WebURL& url, mojo::URLResponsePtr response) {
data_->view_ = View::create(base::Bind(
&SkyView::ScheduleFrame, weak_factory_.GetWeakPtr()));
data_->view_->setDisplayMetrics(display_metrics_);
......@@ -55,7 +55,7 @@ void SkyView::Load(const WebURL& url) {
dart_controller_.reset(new DartController);
dart_controller_->CreateIsolateFor(adoptPtr(new DOMDartState(nullptr)), url);
dart_controller_->InstallView(data_->view_.get());
dart_controller_->LoadMainLibrary(url);
dart_controller_->LoadMainLibrary(url, response.Pass());
}
void SkyView::BeginFrame(base::TimeTicks frame_time) {
......
......@@ -6,8 +6,10 @@
#define SKY_ENGINE_PUBLIC_SKY_SKY_VIEW_H_
#include <memory>
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "mojo/services/network/public/interfaces/url_loader.mojom.h"
#include "skia/ext/refptr.h"
#include "sky/engine/public/platform/WebCommon.h"
#include "sky/engine/public/platform/WebURL.h"
......@@ -24,10 +26,13 @@ class SkyView {
static std::unique_ptr<SkyView> Create(SkyViewClient* client);
~SkyView();
const SkyDisplayMetrics& display_metrics() const { return display_metrics_; }
void SetDisplayMetrics(const SkyDisplayMetrics& metrics);
void Load(const WebURL& url);
void BeginFrame(base::TimeTicks frame_time);
// Sky can either issue the load itself or use an existing response pipe.
void Load(const WebURL& url, mojo::URLResponsePtr response = nullptr);
skia::RefPtr<SkPicture> Paint();
bool HandleInputEvent(const WebInputEvent& event);
......
......@@ -150,7 +150,8 @@ void DocumentView::OnEmbed(
// TODO(abarth): We should ask the view whether it is focused instead of
// assuming that we're focused.
web_view_->setFocus(true);
if (web_view_)
web_view_->setFocus(true);
root_->AddObserver(this);
}
......@@ -159,6 +160,14 @@ void DocumentView::OnViewManagerDisconnected(mojo::ViewManager* view_manager) {
}
void DocumentView::Load(mojo::URLResponsePtr response) {
// Enable SkyView here.
if (false) {
sky_view_ = blink::SkyView::Create(this);
initializeLayerTreeView();
sky_view_->Load(GURL(response->url), response.Pass());
return;
}
web_view_ = blink::WebView::create(this);
ConfigureSettings(web_view_->settings());
web_view_->setMainFrame(blink::WebLocalFrame::create(this));
......@@ -210,17 +219,25 @@ mojo::Shell* DocumentView::GetShell() {
}
void DocumentView::BeginFrame(base::TimeTicks frame_time) {
double frame_time_sec = (frame_time - base::TimeTicks()).InSecondsF();
double deadline_sec = frame_time_sec;
double interval_sec = 1.0/60;
blink::WebBeginFrameArgs web_begin_frame_args(
frame_time_sec, deadline_sec, interval_sec);
web_view_->beginFrame(web_begin_frame_args);
web_view_->layout();
blink::WebSize size = web_view_->size();
float device_pixel_ratio = GetDevicePixelRatio();
root_layer_->SetSize(gfx::Size(size.width * device_pixel_ratio,
size.height * device_pixel_ratio));
if (sky_view_) {
sky_view_->BeginFrame(frame_time);
root_layer_->SetSize(sky_view_->display_metrics().physical_size);
}
if (web_view_) {
double frame_time_sec = (frame_time - base::TimeTicks()).InSecondsF();
double deadline_sec = frame_time_sec;
double interval_sec = 1.0/60;
blink::WebBeginFrameArgs web_begin_frame_args(
frame_time_sec, deadline_sec, interval_sec);
web_view_->beginFrame(web_begin_frame_args);
web_view_->layout();
blink::WebSize size = web_view_->size();
float device_pixel_ratio = GetDevicePixelRatio();
root_layer_->SetSize(gfx::Size(size.width * device_pixel_ratio,
size.height * device_pixel_ratio));
}
}
void DocumentView::OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) {
......@@ -230,11 +247,20 @@ void DocumentView::OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) {
void DocumentView::PaintContents(SkCanvas* canvas, const gfx::Rect& clip) {
blink::WebRect rect(clip.x(), clip.y(), clip.width(), clip.height());
web_view_->paint(canvas, rect);
if (sky_view_) {
skia::RefPtr<SkPicture> picture = sky_view_->Paint();
canvas->clear(SK_ColorBLACK);
canvas->scale(GetDevicePixelRatio(), GetDevicePixelRatio());
if (picture)
canvas->drawPicture(picture.get());
}
if (web_view_)
web_view_->paint(canvas, rect);
}
void DocumentView::scheduleVisualUpdate() {
DCHECK(web_view_);
layer_host_->SetNeedsAnimate();
}
......@@ -313,19 +339,34 @@ void DocumentView::OnViewViewportMetricsChanged(
const mojo::ViewportMetrics& old_metrics,
const mojo::ViewportMetrics& new_metrics) {
DCHECK_EQ(view, root_);
web_view_->setDeviceScaleFactor(GetDevicePixelRatio());
if (web_view_) {
web_view_->setDeviceScaleFactor(GetDevicePixelRatio());
}
UpdateRootSizeAndViewportMetrics(root_->bounds());
}
void DocumentView::UpdateRootSizeAndViewportMetrics(
const mojo::Rect& new_bounds) {
float device_pixel_ratio = GetDevicePixelRatio();
if (sky_view_) {
blink::SkyDisplayMetrics metrics;
mojo::Rect bounds = root_->bounds();
metrics.physical_size = blink::WebSize(bounds.width, bounds.height);
metrics.device_pixel_ratio = device_pixel_ratio;
sky_view_->SetDisplayMetrics(metrics);
return;
}
web_view_->resize(blink::WebSize(new_bounds.width / device_pixel_ratio,
new_bounds.height / device_pixel_ratio));
}
void DocumentView::OnViewFocusChanged(mojo::View* gained_focus,
mojo::View* lost_focus) {
if (sky_view_)
return;
if (root_ == lost_focus) {
web_view_->setFocus(false);
} else if (root_ == gained_focus) {
......@@ -347,6 +388,11 @@ void DocumentView::OnViewInputEvent(
if (!web_event)
return;
if (sky_view_) {
sky_view_->HandleInputEvent(*web_event);
return;
}
ui::GestureRecognizer* recognizer = ui::GestureRecognizer::Get();
scoped_ptr<ui::TouchEvent> touch_event =
ConvertToUITouchEvent(*web_event, device_pixel_ratio);
......@@ -385,4 +431,9 @@ void DocumentView::InitServiceRegistry() {
service_registry_->AddServices(interface_names.Pass(), sp.Pass());
}
void DocumentView::ScheduleFrame() {
DCHECK(sky_view_);
layer_host_->SetNeedsAnimate();
}
} // namespace sky
......@@ -22,11 +22,14 @@
#include "sky/compositor/layer_client.h"
#include "sky/compositor/layer_host_client.h"
#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/engine/public/web/WebFrameClient.h"
#include "sky/engine/public/web/WebViewClient.h"
#include "sky/services/testing/test_harness.mojom.h"
#include "ui/events/gestures/gesture_types.h"
namespace mojo {
class ViewManager;
class View;
......@@ -41,6 +44,7 @@ class LayerHost;
class DocumentView : public blink::ServiceProvider,
public blink::WebFrameClient,
public blink::WebViewClient,
public blink::SkyViewClient,
public mojo::ViewManagerDelegate,
public mojo::ViewObserver,
public sky::LayerClient,
......@@ -66,6 +70,9 @@ class DocumentView : public blink::ServiceProvider,
// sky::LayerClient
void PaintContents(SkCanvas* canvas, const gfx::Rect& clip) override;
// SkyViewClient methods:
void ScheduleFrame() override;
void StartDebuggerInspectorBackend();
void GetPixelsForTesting(std::vector<unsigned char>* pixels);
......@@ -135,6 +142,7 @@ class DocumentView : public blink::ServiceProvider,
mojo::Shell* shell_;
TestHarnessPtr test_harness_;
mojo::NavigatorHostPtr navigator_host_;
std::unique_ptr<blink::SkyView> sky_view_;
blink::WebView* web_view_;
mojo::View* root_;
mojo::ViewManagerClientFactory view_manager_client_factory_;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册