OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "sky/shell/ui/engine.h" | 5 #include "sky/shell/ui/engine.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
9 #include "mojo/public/cpp/application/connect.h" | 9 #include "mojo/public/cpp/application/connect.h" |
10 #include "sky/engine/public/platform/WebInputEvent.h" | 10 #include "sky/engine/public/platform/WebInputEvent.h" |
| 11 #include "sky/engine/public/platform/sky_display_metrics.h" |
| 12 #include "sky/engine/public/platform/sky_display_metrics.h" |
11 #include "sky/engine/public/web/Sky.h" | 13 #include "sky/engine/public/web/Sky.h" |
12 #include "sky/engine/public/web/WebLocalFrame.h" | 14 #include "sky/engine/public/web/WebLocalFrame.h" |
13 #include "sky/engine/public/web/WebSettings.h" | 15 #include "sky/engine/public/web/WebSettings.h" |
14 #include "sky/engine/public/web/WebView.h" | 16 #include "sky/engine/public/web/WebView.h" |
15 #include "sky/services/platform/platform_impl.h" | 17 #include "sky/services/platform/platform_impl.h" |
16 #include "sky/shell/service_provider.h" | 18 #include "sky/shell/service_provider.h" |
17 #include "sky/shell/ui/animator.h" | 19 #include "sky/shell/ui/animator.h" |
18 #include "sky/shell/ui/input_event_converter.h" | 20 #include "sky/shell/ui/input_event_converter.h" |
19 #include "sky/shell/ui/internals.h" | 21 #include "sky/shell/ui/internals.h" |
20 #include "third_party/skia/include/core/SkCanvas.h" | 22 #include "third_party/skia/include/core/SkCanvas.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 83 |
82 SkRTreeFactory factory; | 84 SkRTreeFactory factory; |
83 SkPictureRecorder recorder; | 85 SkPictureRecorder recorder; |
84 auto canvas = skia::SharePtr(recorder.beginRecording( | 86 auto canvas = skia::SharePtr(recorder.beginRecording( |
85 physical_size_.width(), physical_size_.height(), &factory, | 87 physical_size_.width(), physical_size_.height(), &factory, |
86 SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag)); | 88 SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag)); |
87 | 89 |
88 if (sky_view_) { | 90 if (sky_view_) { |
89 skia::RefPtr<SkPicture> picture = sky_view_->Paint(); | 91 skia::RefPtr<SkPicture> picture = sky_view_->Paint(); |
90 canvas->clear(SK_ColorBLACK); | 92 canvas->clear(SK_ColorBLACK); |
| 93 canvas->scale(device_pixel_ratio_, device_pixel_ratio_); |
91 if (picture) | 94 if (picture) |
92 canvas->drawPicture(picture.get()); | 95 canvas->drawPicture(picture.get()); |
93 } | 96 } |
94 | 97 |
95 if (web_view_) | 98 if (web_view_) |
96 web_view_->paint(canvas.get(), blink::WebRect(gfx::Rect(physical_size_))); | 99 web_view_->paint(canvas.get(), blink::WebRect(gfx::Rect(physical_size_))); |
97 | 100 |
98 return skia::AdoptRef(recorder.endRecordingAsPicture()); | 101 return skia::AdoptRef(recorder.endRecordingAsPicture()); |
99 } | 102 } |
100 | 103 |
(...skipping 13 matching lines...) Expand all Loading... |
114 void Engine::OnOutputSurfaceDestroyed() { | 117 void Engine::OnOutputSurfaceDestroyed() { |
115 config_.gpu_task_runner->PostTask( | 118 config_.gpu_task_runner->PostTask( |
116 FROM_HERE, | 119 FROM_HERE, |
117 base::Bind(&GPUDelegate::OnOutputSurfaceDestroyed, config_.gpu_delegate)); | 120 base::Bind(&GPUDelegate::OnOutputSurfaceDestroyed, config_.gpu_delegate)); |
118 } | 121 } |
119 | 122 |
120 void Engine::OnViewportMetricsChanged(int width, int height, | 123 void Engine::OnViewportMetricsChanged(int width, int height, |
121 float device_pixel_ratio) { | 124 float device_pixel_ratio) { |
122 physical_size_.SetSize(width, height); | 125 physical_size_.SetSize(width, height); |
123 device_pixel_ratio_ = device_pixel_ratio; | 126 device_pixel_ratio_ = device_pixel_ratio; |
| 127 |
| 128 if (sky_view_) { |
| 129 blink::SkyDisplayMetrics metrics; |
| 130 metrics.physical_size = physical_size_; |
| 131 metrics.device_pixel_ratio = device_pixel_ratio_; |
| 132 sky_view_->SetDisplayMetrics(metrics); |
| 133 } |
| 134 |
124 if (web_view_) | 135 if (web_view_) |
125 UpdateWebViewSize(); | 136 UpdateWebViewSize(); |
126 } | 137 } |
127 | 138 |
128 void Engine::UpdateWebViewSize() | 139 void Engine::UpdateWebViewSize() |
129 { | 140 { |
130 CHECK(web_view_); | 141 CHECK(web_view_); |
131 web_view_->setDeviceScaleFactor(device_pixel_ratio_); | 142 web_view_->setDeviceScaleFactor(device_pixel_ratio_); |
132 gfx::SizeF size = gfx::ScaleSize(physical_size_, 1 / device_pixel_ratio_); | 143 gfx::SizeF size = gfx::ScaleSize(physical_size_, 1 / device_pixel_ratio_); |
133 // FIXME: We should be able to set the size of the WebView in floating point | 144 // FIXME: We should be able to set the size of the WebView in floating point |
134 // because its in logical pixels. | 145 // because its in logical pixels. |
135 web_view_->resize(blink::WebSize(size.width(), size.height())); | 146 web_view_->resize(blink::WebSize(size.width(), size.height())); |
136 } | 147 } |
137 | 148 |
138 // TODO(eseidel): This is likely not needed anymore. | 149 // TODO(eseidel): This is likely not needed anymore. |
139 blink::WebScreenInfo Engine::screenInfo() { | 150 blink::WebScreenInfo Engine::screenInfo() { |
140 blink::WebScreenInfo screen; | 151 blink::WebScreenInfo screen; |
141 screen.rect = blink::WebRect(gfx::Rect(physical_size_)); | 152 screen.rect = blink::WebRect(gfx::Rect(physical_size_)); |
142 screen.availableRect = screen.rect; | 153 screen.availableRect = screen.rect; |
143 screen.deviceScaleFactor = device_pixel_ratio_; | 154 screen.deviceScaleFactor = device_pixel_ratio_; |
144 return screen; | 155 return screen; |
145 } | 156 } |
146 | 157 |
147 void Engine::OnInputEvent(InputEventPtr event) { | 158 void Engine::OnInputEvent(InputEventPtr event) { |
148 TRACE_EVENT0("sky", "Engine::OnInputEvent"); | 159 TRACE_EVENT0("sky", "Engine::OnInputEvent"); |
149 scoped_ptr<blink::WebInputEvent> web_event = | 160 scoped_ptr<blink::WebInputEvent> web_event = |
150 ConvertEvent(event, device_pixel_ratio_); | 161 ConvertEvent(event, device_pixel_ratio_); |
151 if (!web_event) | 162 if (!web_event) |
152 return; | 163 return; |
153 web_view_->handleInputEvent(*web_event); | 164 if (web_view_) |
| 165 web_view_->handleInputEvent(*web_event); |
154 } | 166 } |
155 | 167 |
156 void Engine::LoadURL(const mojo::String& url) { | 168 void Engine::LoadURL(const mojo::String& url) { |
157 // Enable SkyView here. | 169 // Enable SkyView here. |
158 if (false) { | 170 if (false) { |
159 sky_view_ = blink::SkyView::Create(this); | 171 sky_view_ = blink::SkyView::Create(this); |
160 sky_view_->Load(GURL(url)); | 172 sky_view_->Load(GURL(url)); |
161 return; | 173 return; |
162 } | 174 } |
163 | 175 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 | 222 |
211 void Engine::DidNavigateLocally(const mojo::String& url) { | 223 void Engine::DidNavigateLocally(const mojo::String& url) { |
212 } | 224 } |
213 | 225 |
214 void Engine::RequestNavigateHistory(int32_t delta) { | 226 void Engine::RequestNavigateHistory(int32_t delta) { |
215 NOTIMPLEMENTED(); | 227 NOTIMPLEMENTED(); |
216 } | 228 } |
217 | 229 |
218 } // namespace shell | 230 } // namespace shell |
219 } // namespace sky | 231 } // namespace sky |
OLD | NEW |