| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "mojo/services/html_viewer/weblayertreeview_impl.h" | |
| 6 | |
| 7 #include "base/message_loop/message_loop_proxy.h" | |
| 8 #include "cc/blink/web_layer_impl.h" | |
| 9 #include "cc/layers/layer.h" | |
| 10 #include "cc/output/begin_frame_args.h" | |
| 11 #include "cc/trees/layer_tree_host.h" | |
| 12 #include "mojo/cc/context_provider_mojo.h" | |
| 13 #include "mojo/cc/output_surface_mojo.h" | |
| 14 #include "mojo/services/public/cpp/surfaces/surfaces_type_converters.h" | |
| 15 #include "mojo/services/public/cpp/view_manager/view.h" | |
| 16 #include "third_party/WebKit/public/web/WebWidget.h" | |
| 17 | |
| 18 namespace mojo { | |
| 19 | |
| 20 WebLayerTreeViewImpl::WebLayerTreeViewImpl( | |
| 21 scoped_refptr<base::MessageLoopProxy> compositor_message_loop_proxy, | |
| 22 SurfacesServicePtr surfaces_service, | |
| 23 GpuPtr gpu_service) | |
| 24 : widget_(NULL), | |
| 25 view_(NULL), | |
| 26 surfaces_service_(surfaces_service.Pass()), | |
| 27 gpu_service_(gpu_service.Pass()), | |
| 28 main_thread_compositor_task_runner_(base::MessageLoopProxy::current()), | |
| 29 weak_factory_(this) { | |
| 30 main_thread_bound_weak_ptr_ = weak_factory_.GetWeakPtr(); | |
| 31 surfaces_service_->CreateSurfaceConnection( | |
| 32 base::Bind(&WebLayerTreeViewImpl::OnSurfaceConnectionCreated, | |
| 33 main_thread_bound_weak_ptr_)); | |
| 34 | |
| 35 cc::LayerTreeSettings settings; | |
| 36 | |
| 37 // For web contents, layer transforms should scale up the contents of layers | |
| 38 // to keep content always crisp when possible. | |
| 39 settings.layer_transforms_should_scale_layer_contents = true; | |
| 40 | |
| 41 cc::SharedBitmapManager* shared_bitmap_manager = NULL; | |
| 42 | |
| 43 layer_tree_host_ = | |
| 44 cc::LayerTreeHost::CreateThreaded(this, | |
| 45 shared_bitmap_manager, | |
| 46 settings, | |
| 47 base::MessageLoopProxy::current(), | |
| 48 compositor_message_loop_proxy); | |
| 49 DCHECK(layer_tree_host_); | |
| 50 } | |
| 51 | |
| 52 WebLayerTreeViewImpl::~WebLayerTreeViewImpl() { | |
| 53 } | |
| 54 | |
| 55 void WebLayerTreeViewImpl::WillBeginMainFrame(int frame_id) { | |
| 56 } | |
| 57 | |
| 58 void WebLayerTreeViewImpl::DidBeginMainFrame() { | |
| 59 } | |
| 60 | |
| 61 void WebLayerTreeViewImpl::BeginMainFrame(const cc::BeginFrameArgs& args) { | |
| 62 VLOG(2) << "WebLayerTreeViewImpl::BeginMainFrame"; | |
| 63 double frame_time_sec = (args.frame_time - base::TimeTicks()).InSecondsF(); | |
| 64 double deadline_sec = (args.deadline - base::TimeTicks()).InSecondsF(); | |
| 65 double interval_sec = args.interval.InSecondsF(); | |
| 66 blink::WebBeginFrameArgs web_begin_frame_args( | |
| 67 frame_time_sec, deadline_sec, interval_sec); | |
| 68 widget_->beginFrame(web_begin_frame_args); | |
| 69 } | |
| 70 | |
| 71 void WebLayerTreeViewImpl::Layout() { | |
| 72 widget_->layout(); | |
| 73 } | |
| 74 | |
| 75 void WebLayerTreeViewImpl::ApplyViewportDeltas( | |
| 76 const gfx::Vector2d& scroll_delta, | |
| 77 float page_scale, | |
| 78 float top_controls_delta) { | |
| 79 widget_->applyViewportDeltas(scroll_delta, page_scale, top_controls_delta); | |
| 80 } | |
| 81 | |
| 82 scoped_ptr<cc::OutputSurface> WebLayerTreeViewImpl::CreateOutputSurface( | |
| 83 bool fallback) { | |
| 84 return output_surface_.Pass(); | |
| 85 } | |
| 86 | |
| 87 void WebLayerTreeViewImpl::DidInitializeOutputSurface() { | |
| 88 } | |
| 89 | |
| 90 void WebLayerTreeViewImpl::WillCommit() { | |
| 91 } | |
| 92 | |
| 93 void WebLayerTreeViewImpl::DidCommit() { | |
| 94 widget_->didCommitFrameToCompositor(); | |
| 95 } | |
| 96 | |
| 97 void WebLayerTreeViewImpl::DidCommitAndDrawFrame() { | |
| 98 } | |
| 99 | |
| 100 void WebLayerTreeViewImpl::DidCompleteSwapBuffers() { | |
| 101 } | |
| 102 | |
| 103 void WebLayerTreeViewImpl::setSurfaceReady() { | |
| 104 } | |
| 105 | |
| 106 void WebLayerTreeViewImpl::setRootLayer(const blink::WebLayer& layer) { | |
| 107 layer_tree_host_->SetRootLayer( | |
| 108 static_cast<const cc_blink::WebLayerImpl*>(&layer)->layer()); | |
| 109 } | |
| 110 | |
| 111 void WebLayerTreeViewImpl::clearRootLayer() { | |
| 112 layer_tree_host_->SetRootLayer(scoped_refptr<cc::Layer>()); | |
| 113 } | |
| 114 | |
| 115 void WebLayerTreeViewImpl::setViewportSize( | |
| 116 const blink::WebSize& device_viewport_size) { | |
| 117 layer_tree_host_->SetViewportSize(device_viewport_size); | |
| 118 } | |
| 119 | |
| 120 blink::WebSize WebLayerTreeViewImpl::deviceViewportSize() const { | |
| 121 return layer_tree_host_->device_viewport_size(); | |
| 122 } | |
| 123 | |
| 124 void WebLayerTreeViewImpl::setDeviceScaleFactor(float device_scale_factor) { | |
| 125 layer_tree_host_->SetDeviceScaleFactor(device_scale_factor); | |
| 126 } | |
| 127 | |
| 128 float WebLayerTreeViewImpl::deviceScaleFactor() const { | |
| 129 return layer_tree_host_->device_scale_factor(); | |
| 130 } | |
| 131 | |
| 132 void WebLayerTreeViewImpl::setBackgroundColor(blink::WebColor color) { | |
| 133 layer_tree_host_->set_background_color(color); | |
| 134 } | |
| 135 | |
| 136 void WebLayerTreeViewImpl::setHasTransparentBackground( | |
| 137 bool has_transparent_background) { | |
| 138 layer_tree_host_->set_has_transparent_background(has_transparent_background); | |
| 139 } | |
| 140 | |
| 141 void WebLayerTreeViewImpl::setOverhangBitmap(const SkBitmap& bitmap) { | |
| 142 layer_tree_host_->SetOverhangBitmap(bitmap); | |
| 143 } | |
| 144 | |
| 145 void WebLayerTreeViewImpl::setVisible(bool visible) { | |
| 146 layer_tree_host_->SetVisible(visible); | |
| 147 } | |
| 148 | |
| 149 void WebLayerTreeViewImpl::setPageScaleFactorAndLimits(float page_scale_factor, | |
| 150 float minimum, | |
| 151 float maximum) { | |
| 152 layer_tree_host_->SetPageScaleFactorAndLimits( | |
| 153 page_scale_factor, minimum, maximum); | |
| 154 } | |
| 155 | |
| 156 void WebLayerTreeViewImpl::registerForAnimations(blink::WebLayer* layer) { | |
| 157 cc::Layer* cc_layer = static_cast<cc_blink::WebLayerImpl*>(layer)->layer(); | |
| 158 cc_layer->layer_animation_controller()->SetAnimationRegistrar( | |
| 159 layer_tree_host_->animation_registrar()); | |
| 160 } | |
| 161 | |
| 162 void WebLayerTreeViewImpl::registerViewportLayers( | |
| 163 const blink::WebLayer* pageScaleLayer, | |
| 164 const blink::WebLayer* innerViewportScrollLayer, | |
| 165 const blink::WebLayer* outerViewportScrollLayer) { | |
| 166 layer_tree_host_->RegisterViewportLayers( | |
| 167 static_cast<const cc_blink::WebLayerImpl*>(pageScaleLayer)->layer(), | |
| 168 static_cast<const cc_blink::WebLayerImpl*>(innerViewportScrollLayer) | |
| 169 ->layer(), | |
| 170 // The outer viewport layer will only exist when using pinch virtual | |
| 171 // viewports. | |
| 172 outerViewportScrollLayer ? static_cast<const cc_blink::WebLayerImpl*>( | |
| 173 outerViewportScrollLayer)->layer() | |
| 174 : NULL); | |
| 175 } | |
| 176 | |
| 177 void WebLayerTreeViewImpl::clearViewportLayers() { | |
| 178 layer_tree_host_->RegisterViewportLayers(scoped_refptr<cc::Layer>(), | |
| 179 scoped_refptr<cc::Layer>(), | |
| 180 scoped_refptr<cc::Layer>()); | |
| 181 } | |
| 182 | |
| 183 void WebLayerTreeViewImpl::startPageScaleAnimation( | |
| 184 const blink::WebPoint& destination, | |
| 185 bool use_anchor, | |
| 186 float new_page_scale, | |
| 187 double duration_sec) { | |
| 188 base::TimeDelta duration = base::TimeDelta::FromMicroseconds( | |
| 189 duration_sec * base::Time::kMicrosecondsPerSecond); | |
| 190 layer_tree_host_->StartPageScaleAnimation( | |
| 191 gfx::Vector2d(destination.x, destination.y), | |
| 192 use_anchor, | |
| 193 new_page_scale, | |
| 194 duration); | |
| 195 } | |
| 196 | |
| 197 void WebLayerTreeViewImpl::setNeedsAnimate() { | |
| 198 layer_tree_host_->SetNeedsAnimate(); | |
| 199 } | |
| 200 | |
| 201 bool WebLayerTreeViewImpl::commitRequested() const { | |
| 202 return layer_tree_host_->CommitRequested(); | |
| 203 } | |
| 204 | |
| 205 void WebLayerTreeViewImpl::finishAllRendering() { | |
| 206 layer_tree_host_->FinishAllRendering(); | |
| 207 } | |
| 208 | |
| 209 void WebLayerTreeViewImpl::OnSurfaceConnectionCreated(SurfacePtr surface, | |
| 210 uint32_t id_namespace) { | |
| 211 CommandBufferPtr cb; | |
| 212 gpu_service_->CreateOffscreenGLES2Context(Get(&cb)); | |
| 213 scoped_refptr<cc::ContextProvider> context_provider( | |
| 214 new ContextProviderMojo(cb.PassMessagePipe())); | |
| 215 output_surface_.reset(new OutputSurfaceMojo( | |
| 216 this, context_provider, surface.Pass(), id_namespace)); | |
| 217 layer_tree_host_->SetLayerTreeHostClientReady(); | |
| 218 } | |
| 219 | |
| 220 void WebLayerTreeViewImpl::DidCreateSurface(cc::SurfaceId id) { | |
| 221 main_thread_compositor_task_runner_->PostTask( | |
| 222 FROM_HERE, | |
| 223 base::Bind(&WebLayerTreeViewImpl::DidCreateSurfaceOnMainThread, | |
| 224 main_thread_bound_weak_ptr_, | |
| 225 id)); | |
| 226 } | |
| 227 | |
| 228 void WebLayerTreeViewImpl::DidCreateSurfaceOnMainThread(cc::SurfaceId id) { | |
| 229 view_->SetSurfaceId(SurfaceId::From(id)); | |
| 230 } | |
| 231 | |
| 232 } // namespace mojo | |
| OLD | NEW |