boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "content/browser/android/synchronous_compositor_host.h" |
| 6 | |
boliu | cafb1bf | 2015-12-29 01:40:19 | [diff] [blame] | 7 | #include <utility> |
| 8 | |
boliu | c99f26c1 | 2016-04-21 21:58:59 | [diff] [blame] | 9 | #include "base/command_line.h" |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 10 | #include "base/containers/hash_tables.h" |
boliu | c99f26c1 | 2016-04-21 21:58:59 | [diff] [blame] | 11 | #include "base/memory/ptr_util.h" |
boliu | f6d263e | 2015-11-25 03:53:58 | [diff] [blame] | 12 | #include "base/memory/shared_memory.h" |
| 13 | #include "base/trace_event/trace_event_argument.h" |
boliu | 3dd3ca7 | 2016-07-29 00:18:37 | [diff] [blame] | 14 | #include "content/browser/android/synchronous_compositor_observer.h" |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 15 | #include "content/browser/renderer_host/render_widget_host_view_android.h" |
boliu | c99f26c1 | 2016-04-21 21:58:59 | [diff] [blame] | 16 | #include "content/browser/web_contents/web_contents_android.h" |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 17 | #include "content/browser/web_contents/web_contents_impl.h" |
| 18 | #include "content/common/android/sync_compositor_messages.h" |
jbroman | 801dd27 | 2016-04-22 18:54:02 | [diff] [blame] | 19 | #include "content/common/android/sync_compositor_statics.h" |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 20 | #include "content/public/browser/android/synchronous_compositor_client.h" |
hush | 92bd35e7 | 2015-11-13 22:57:37 | [diff] [blame] | 21 | #include "content/public/browser/browser_thread.h" |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 22 | #include "content/public/browser/render_view_host.h" |
boliu | c99f26c1 | 2016-04-21 21:58:59 | [diff] [blame] | 23 | #include "content/public/common/content_switches.h" |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 24 | #include "ipc/ipc_sender.h" |
boliu | f6d263e | 2015-11-25 03:53:58 | [diff] [blame] | 25 | #include "third_party/skia/include/core/SkBitmap.h" |
| 26 | #include "third_party/skia/include/core/SkCanvas.h" |
| 27 | #include "third_party/skia/include/core/SkImageInfo.h" |
| 28 | #include "third_party/skia/include/core/SkRect.h" |
| 29 | #include "ui/gfx/skia_util.h" |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 30 | |
| 31 | namespace content { |
| 32 | |
boliu | c99f26c1 | 2016-04-21 21:58:59 | [diff] [blame] | 33 | // static |
| 34 | void SynchronousCompositor::SetClientForWebContents( |
| 35 | WebContents* contents, |
| 36 | SynchronousCompositorClient* client) { |
| 37 | DCHECK(contents); |
| 38 | DCHECK(client); |
| 39 | WebContentsAndroid* web_contents_android = |
| 40 | static_cast<WebContentsImpl*>(contents)->GetWebContentsAndroid(); |
| 41 | DCHECK(!web_contents_android->synchronous_compositor_client()); |
| 42 | web_contents_android->set_synchronous_compositor_client(client); |
| 43 | } |
| 44 | |
| 45 | // static |
| 46 | std::unique_ptr<SynchronousCompositorHost> SynchronousCompositorHost::Create( |
| 47 | RenderWidgetHostViewAndroid* rwhva, |
| 48 | WebContents* web_contents) { |
| 49 | DCHECK(web_contents); |
| 50 | WebContentsAndroid* web_contents_android = |
| 51 | static_cast<WebContentsImpl*>(web_contents)->GetWebContentsAndroid(); |
| 52 | if (!web_contents_android->synchronous_compositor_client()) |
| 53 | return nullptr; // Not using sync compositing. |
| 54 | |
| 55 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
boliu | c99f26c1 | 2016-04-21 21:58:59 | [diff] [blame] | 56 | bool use_in_proc_software_draw = |
| 57 | command_line->HasSwitch(switches::kSingleProcess); |
| 58 | return base::WrapUnique(new SynchronousCompositorHost( |
boliu | b2768db | 2016-06-03 23:35:16 | [diff] [blame] | 59 | rwhva, web_contents_android->synchronous_compositor_client(), |
boliu | c99f26c1 | 2016-04-21 21:58:59 | [diff] [blame] | 60 | use_in_proc_software_draw)); |
| 61 | } |
| 62 | |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 63 | SynchronousCompositorHost::SynchronousCompositorHost( |
| 64 | RenderWidgetHostViewAndroid* rwhva, |
boliu | 4d4b5a8 | 2016-02-17 01:55:21 | [diff] [blame] | 65 | SynchronousCompositorClient* client, |
boliu | 4d4b5a8 | 2016-02-17 01:55:21 | [diff] [blame] | 66 | bool use_in_proc_software_draw) |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 67 | : rwhva_(rwhva), |
| 68 | client_(client), |
thestig | 529ad8a | 2016-07-08 20:30:12 | [diff] [blame] | 69 | ui_task_runner_(BrowserThread::GetTaskRunnerForThread(BrowserThread::UI)), |
hush | 284add6 | 2016-06-17 20:47:33 | [diff] [blame] | 70 | process_id_(rwhva_->GetRenderWidgetHost()->GetProcess()->GetID()), |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 71 | routing_id_(rwhva_->GetRenderWidgetHost()->GetRoutingID()), |
boliu | 3dd3ca7 | 2016-07-29 00:18:37 | [diff] [blame] | 72 | rph_observer_(SynchronousCompositorObserver::GetOrCreateFor(process_id_)), |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 73 | sender_(rwhva_->GetRenderWidgetHost()), |
boliu | 4d4b5a8 | 2016-02-17 01:55:21 | [diff] [blame] | 74 | use_in_process_zero_copy_software_draw_(use_in_proc_software_draw), |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 75 | bytes_limit_(0u), |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 76 | renderer_param_version_(0u), |
| 77 | need_animate_scroll_(false), |
boliu | 17bc31f | 2016-02-23 18:46:28 | [diff] [blame] | 78 | need_invalidate_count_(0u), |
boliu | 8f3016e | 2016-06-04 00:59:18 | [diff] [blame] | 79 | did_activate_pending_tree_count_(0u) { |
hush | 284add6 | 2016-06-17 20:47:33 | [diff] [blame] | 80 | client_->DidInitializeCompositor(this, process_id_, routing_id_); |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | SynchronousCompositorHost::~SynchronousCompositorHost() { |
hush | 284add6 | 2016-06-17 20:47:33 | [diff] [blame] | 84 | client_->DidDestroyCompositor(this, process_id_, routing_id_); |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | bool SynchronousCompositorHost::OnMessageReceived(const IPC::Message& message) { |
| 88 | bool handled = true; |
| 89 | IPC_BEGIN_MESSAGE_MAP(SynchronousCompositorHost, message) |
boliu | 42e0131 | 2016-05-12 21:47:52 | [diff] [blame] | 90 | IPC_MESSAGE_HANDLER(SyncCompositorHostMsg_OutputSurfaceCreated, |
| 91 | OutputSurfaceCreated) |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 92 | IPC_MESSAGE_HANDLER(SyncCompositorHostMsg_UpdateState, ProcessCommonParams) |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 93 | IPC_MESSAGE_UNHANDLED(handled = false) |
| 94 | IPC_END_MESSAGE_MAP() |
| 95 | return handled; |
| 96 | } |
| 97 | |
boliu | f4e57485 | 2016-03-22 19:33:17 | [diff] [blame] | 98 | SynchronousCompositor::Frame SynchronousCompositorHost::DemandDrawHw( |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame^] | 99 | const gfx::Size& viewport_size, |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 100 | const gfx::Rect& viewport_rect_for_tile_priority, |
| 101 | const gfx::Transform& transform_for_tile_priority) { |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame^] | 102 | SyncCompositorDemandDrawHwParams params(viewport_size, |
| 103 | viewport_rect_for_tile_priority, |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 104 | transform_for_tile_priority); |
boliu | f4e57485 | 2016-03-22 19:33:17 | [diff] [blame] | 105 | SynchronousCompositor::Frame frame; |
| 106 | frame.frame.reset(new cc::CompositorFrame); |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 107 | SyncCompositorCommonRendererParams common_renderer_params; |
| 108 | if (!sender_->Send(new SyncCompositorMsg_DemandDrawHw( |
boliu | 8f3016e | 2016-06-04 00:59:18 | [diff] [blame] | 109 | routing_id_, params, &common_renderer_params, |
boliu | f4e57485 | 2016-03-22 19:33:17 | [diff] [blame] | 110 | &frame.output_surface_id, frame.frame.get()))) { |
| 111 | return SynchronousCompositor::Frame(); |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 112 | } |
| 113 | ProcessCommonParams(common_renderer_params); |
boliu | f4e57485 | 2016-03-22 19:33:17 | [diff] [blame] | 114 | if (!frame.frame->delegated_frame_data) { |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 115 | // This can happen if compositor did not swap in this draw. |
boliu | f4e57485 | 2016-03-22 19:33:17 | [diff] [blame] | 116 | frame.frame.reset(); |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 117 | } |
boliu | f4e57485 | 2016-03-22 19:33:17 | [diff] [blame] | 118 | if (frame.frame) { |
fsamuel | d63137a | 2016-06-24 23:39:51 | [diff] [blame] | 119 | UpdateFrameMetaData(frame.frame->metadata.Clone()); |
boliu | f4e57485 | 2016-03-22 19:33:17 | [diff] [blame] | 120 | } |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 121 | return frame; |
| 122 | } |
| 123 | |
| 124 | void SynchronousCompositorHost::UpdateFrameMetaData( |
fsamuel | d63137a | 2016-06-24 23:39:51 | [diff] [blame] | 125 | cc::CompositorFrameMetadata frame_metadata) { |
| 126 | rwhva_->SynchronousFrameMetadata(std::move(frame_metadata)); |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 127 | } |
| 128 | |
boliu | 4d4b5a8 | 2016-02-17 01:55:21 | [diff] [blame] | 129 | namespace { |
| 130 | |
| 131 | class ScopedSetSkCanvas { |
| 132 | public: |
| 133 | explicit ScopedSetSkCanvas(SkCanvas* canvas) { |
| 134 | SynchronousCompositorSetSkCanvas(canvas); |
| 135 | } |
| 136 | |
| 137 | ~ScopedSetSkCanvas() { |
| 138 | SynchronousCompositorSetSkCanvas(nullptr); |
| 139 | } |
| 140 | |
| 141 | private: |
| 142 | DISALLOW_COPY_AND_ASSIGN(ScopedSetSkCanvas); |
| 143 | }; |
| 144 | |
| 145 | } |
| 146 | |
| 147 | bool SynchronousCompositorHost::DemandDrawSwInProc(SkCanvas* canvas) { |
boliu | 4d4b5a8 | 2016-02-17 01:55:21 | [diff] [blame] | 148 | SyncCompositorCommonRendererParams common_renderer_params; |
| 149 | bool success = false; |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 150 | std::unique_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); |
boliu | 4d4b5a8 | 2016-02-17 01:55:21 | [diff] [blame] | 151 | ScopedSetSkCanvas set_sk_canvas(canvas); |
| 152 | SyncCompositorDemandDrawSwParams params; // Unused. |
| 153 | if (!sender_->Send(new SyncCompositorMsg_DemandDrawSw( |
boliu | 8f3016e | 2016-06-04 00:59:18 | [diff] [blame] | 154 | routing_id_, params, &success, &common_renderer_params, |
| 155 | frame.get()))) { |
boliu | 4d4b5a8 | 2016-02-17 01:55:21 | [diff] [blame] | 156 | return false; |
| 157 | } |
| 158 | if (!success) |
| 159 | return false; |
| 160 | ProcessCommonParams(common_renderer_params); |
fsamuel | d63137a | 2016-06-24 23:39:51 | [diff] [blame] | 161 | UpdateFrameMetaData(std::move(frame->metadata)); |
boliu | 4d4b5a8 | 2016-02-17 01:55:21 | [diff] [blame] | 162 | return true; |
| 163 | } |
| 164 | |
boliu | cafb1bf | 2015-12-29 01:40:19 | [diff] [blame] | 165 | class SynchronousCompositorHost::ScopedSendZeroMemory { |
| 166 | public: |
| 167 | ScopedSendZeroMemory(SynchronousCompositorHost* host) : host_(host) {} |
| 168 | ~ScopedSendZeroMemory() { host_->SendZeroMemory(); } |
| 169 | |
| 170 | private: |
| 171 | SynchronousCompositorHost* const host_; |
| 172 | |
| 173 | DISALLOW_COPY_AND_ASSIGN(ScopedSendZeroMemory); |
| 174 | }; |
| 175 | |
| 176 | struct SynchronousCompositorHost::SharedMemoryWithSize { |
| 177 | base::SharedMemory shm; |
| 178 | const size_t stride; |
| 179 | const size_t buffer_size; |
| 180 | |
| 181 | SharedMemoryWithSize(size_t stride, size_t buffer_size) |
| 182 | : stride(stride), buffer_size(buffer_size) {} |
| 183 | |
| 184 | private: |
| 185 | DISALLOW_COPY_AND_ASSIGN(SharedMemoryWithSize); |
| 186 | }; |
| 187 | |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 188 | bool SynchronousCompositorHost::DemandDrawSw(SkCanvas* canvas) { |
boliu | 4d4b5a8 | 2016-02-17 01:55:21 | [diff] [blame] | 189 | if (use_in_process_zero_copy_software_draw_) |
| 190 | return DemandDrawSwInProc(canvas); |
| 191 | |
boliu | f6d263e | 2015-11-25 03:53:58 | [diff] [blame] | 192 | SyncCompositorDemandDrawSwParams params; |
| 193 | params.size = gfx::Size(canvas->getBaseLayerSize().width(), |
| 194 | canvas->getBaseLayerSize().height()); |
| 195 | SkIRect canvas_clip; |
| 196 | canvas->getClipDeviceBounds(&canvas_clip); |
| 197 | params.clip = gfx::SkIRectToRect(canvas_clip); |
| 198 | params.transform.matrix() = canvas->getTotalMatrix(); |
| 199 | if (params.size.IsEmpty()) |
| 200 | return true; |
| 201 | |
| 202 | SkImageInfo info = |
| 203 | SkImageInfo::MakeN32Premul(params.size.width(), params.size.height()); |
| 204 | DCHECK_EQ(kRGBA_8888_SkColorType, info.colorType()); |
| 205 | size_t stride = info.minRowBytes(); |
| 206 | size_t buffer_size = info.getSafeSize(stride); |
| 207 | if (!buffer_size) |
| 208 | return false; // Overflow. |
| 209 | |
boliu | cafb1bf | 2015-12-29 01:40:19 | [diff] [blame] | 210 | SetSoftwareDrawSharedMemoryIfNeeded(stride, buffer_size); |
| 211 | if (!software_draw_shm_) |
boliu | f6d263e | 2015-11-25 03:53:58 | [diff] [blame] | 212 | return false; |
| 213 | |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 214 | std::unique_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); |
boliu | f6d263e | 2015-11-25 03:53:58 | [diff] [blame] | 215 | SyncCompositorCommonRendererParams common_renderer_params; |
| 216 | bool success = false; |
| 217 | if (!sender_->Send(new SyncCompositorMsg_DemandDrawSw( |
boliu | 8f3016e | 2016-06-04 00:59:18 | [diff] [blame] | 218 | routing_id_, params, &success, &common_renderer_params, |
| 219 | frame.get()))) { |
boliu | f6d263e | 2015-11-25 03:53:58 | [diff] [blame] | 220 | return false; |
| 221 | } |
boliu | cafb1bf | 2015-12-29 01:40:19 | [diff] [blame] | 222 | ScopedSendZeroMemory send_zero_memory(this); |
boliu | f6d263e | 2015-11-25 03:53:58 | [diff] [blame] | 223 | if (!success) |
| 224 | return false; |
| 225 | |
| 226 | ProcessCommonParams(common_renderer_params); |
fsamuel | d63137a | 2016-06-24 23:39:51 | [diff] [blame] | 227 | UpdateFrameMetaData(std::move(frame->metadata)); |
boliu | f6d263e | 2015-11-25 03:53:58 | [diff] [blame] | 228 | |
| 229 | SkBitmap bitmap; |
boliu | cafb1bf | 2015-12-29 01:40:19 | [diff] [blame] | 230 | if (!bitmap.installPixels(info, software_draw_shm_->shm.memory(), stride)) |
boliu | f6d263e | 2015-11-25 03:53:58 | [diff] [blame] | 231 | return false; |
| 232 | |
| 233 | { |
| 234 | TRACE_EVENT0("browser", "DrawBitmap"); |
| 235 | canvas->save(); |
| 236 | canvas->resetMatrix(); |
| 237 | canvas->drawBitmap(bitmap, 0, 0); |
| 238 | canvas->restore(); |
| 239 | } |
| 240 | |
| 241 | return true; |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 242 | } |
| 243 | |
boliu | cafb1bf | 2015-12-29 01:40:19 | [diff] [blame] | 244 | void SynchronousCompositorHost::SetSoftwareDrawSharedMemoryIfNeeded( |
| 245 | size_t stride, |
| 246 | size_t buffer_size) { |
| 247 | if (software_draw_shm_ && software_draw_shm_->stride == stride && |
| 248 | software_draw_shm_->buffer_size == buffer_size) |
| 249 | return; |
| 250 | software_draw_shm_.reset(); |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 251 | std::unique_ptr<SharedMemoryWithSize> software_draw_shm( |
boliu | cafb1bf | 2015-12-29 01:40:19 | [diff] [blame] | 252 | new SharedMemoryWithSize(stride, buffer_size)); |
| 253 | { |
| 254 | TRACE_EVENT1("browser", "AllocateSharedMemory", "buffer_size", buffer_size); |
| 255 | if (!software_draw_shm->shm.CreateAndMapAnonymous(buffer_size)) |
| 256 | return; |
| 257 | } |
| 258 | |
| 259 | SyncCompositorSetSharedMemoryParams set_shm_params; |
| 260 | set_shm_params.buffer_size = buffer_size; |
| 261 | base::ProcessHandle renderer_process_handle = |
| 262 | rwhva_->GetRenderWidgetHost()->GetProcess()->GetHandle(); |
| 263 | if (!software_draw_shm->shm.ShareToProcess(renderer_process_handle, |
| 264 | &set_shm_params.shm_handle)) { |
| 265 | return; |
| 266 | } |
| 267 | |
boliu | cafb1bf | 2015-12-29 01:40:19 | [diff] [blame] | 268 | bool success = false; |
| 269 | SyncCompositorCommonRendererParams common_renderer_params; |
| 270 | if (!sender_->Send(new SyncCompositorMsg_SetSharedMemory( |
boliu | 8f3016e | 2016-06-04 00:59:18 | [diff] [blame] | 271 | routing_id_, set_shm_params, &success, &common_renderer_params)) || |
boliu | cafb1bf | 2015-12-29 01:40:19 | [diff] [blame] | 272 | !success) { |
| 273 | return; |
| 274 | } |
| 275 | software_draw_shm_ = std::move(software_draw_shm); |
| 276 | ProcessCommonParams(common_renderer_params); |
| 277 | } |
| 278 | |
| 279 | void SynchronousCompositorHost::SendZeroMemory() { |
| 280 | // No need to check return value. |
| 281 | sender_->Send(new SyncCompositorMsg_ZeroSharedMemory(routing_id_)); |
| 282 | } |
| 283 | |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 284 | void SynchronousCompositorHost::ReturnResources( |
boliu | f4e57485 | 2016-03-22 19:33:17 | [diff] [blame] | 285 | uint32_t output_surface_id, |
fsamuel | b62b7822 | 2016-07-15 01:14:14 | [diff] [blame] | 286 | const cc::ReturnedResourceArray& resources) { |
| 287 | DCHECK(!resources.empty()); |
boliu | ec72a2ed | 2016-05-10 00:51:56 | [diff] [blame] | 288 | sender_->Send(new SyncCompositorMsg_ReclaimResources( |
fsamuel | b62b7822 | 2016-07-15 01:14:14 | [diff] [blame] | 289 | routing_id_, output_surface_id, resources)); |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | void SynchronousCompositorHost::SetMemoryPolicy(size_t bytes_limit) { |
| 293 | if (bytes_limit_ == bytes_limit) |
| 294 | return; |
boliu | 42e0131 | 2016-05-12 21:47:52 | [diff] [blame] | 295 | |
| 296 | if (sender_->Send( |
| 297 | new SyncCompositorMsg_SetMemoryPolicy(routing_id_, bytes_limit))) { |
| 298 | bytes_limit_ = bytes_limit; |
| 299 | } |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | void SynchronousCompositorHost::DidChangeRootLayerScrollOffset( |
| 303 | const gfx::ScrollOffset& root_offset) { |
| 304 | if (root_scroll_offset_ == root_offset) |
| 305 | return; |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 306 | root_scroll_offset_ = root_offset; |
boliu | 22cdc6d | 2016-05-13 19:43:09 | [diff] [blame] | 307 | sender_->Send( |
| 308 | new SyncCompositorMsg_SetScroll(routing_id_, root_scroll_offset_)); |
hush | 92bd35e7 | 2015-11-13 22:57:37 | [diff] [blame] | 309 | } |
| 310 | |
boliu | 21d8ab14 | 2016-04-07 23:33:52 | [diff] [blame] | 311 | void SynchronousCompositorHost::SynchronouslyZoomBy(float zoom_delta, |
| 312 | const gfx::Point& anchor) { |
boliu | 21d8ab14 | 2016-04-07 23:33:52 | [diff] [blame] | 313 | SyncCompositorCommonRendererParams common_renderer_params; |
| 314 | if (!sender_->Send(new SyncCompositorMsg_ZoomBy( |
boliu | 8f3016e | 2016-06-04 00:59:18 | [diff] [blame] | 315 | routing_id_, zoom_delta, anchor, &common_renderer_params))) { |
boliu | 21d8ab14 | 2016-04-07 23:33:52 | [diff] [blame] | 316 | return; |
| 317 | } |
| 318 | ProcessCommonParams(common_renderer_params); |
| 319 | } |
| 320 | |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 321 | void SynchronousCompositorHost::OnComputeScroll( |
| 322 | base::TimeTicks animation_time) { |
| 323 | if (!need_animate_scroll_) |
| 324 | return; |
| 325 | need_animate_scroll_ = false; |
| 326 | |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 327 | SyncCompositorCommonRendererParams common_renderer_params; |
boliu | 8f3016e | 2016-06-04 00:59:18 | [diff] [blame] | 328 | sender_->Send( |
| 329 | new SyncCompositorMsg_ComputeScroll(routing_id_, animation_time)); |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 330 | } |
| 331 | |
boliu | de5b75b | 2016-03-11 07:02:14 | [diff] [blame] | 332 | void SynchronousCompositorHost::DidOverscroll( |
| 333 | const DidOverscrollParams& over_scroll_params) { |
hush | 83e367c | 2016-06-18 02:37:54 | [diff] [blame] | 334 | client_->DidOverscroll(this, over_scroll_params.accumulated_overscroll, |
boliu | de5b75b | 2016-03-11 07:02:14 | [diff] [blame] | 335 | over_scroll_params.latest_overscroll_delta, |
| 336 | over_scroll_params.current_fling_velocity); |
| 337 | } |
| 338 | |
boliu | 3dd3ca7 | 2016-07-29 00:18:37 | [diff] [blame] | 339 | void SynchronousCompositorHost::DidSendBeginFrame( |
| 340 | ui::WindowAndroid* window_android) { |
| 341 | rph_observer_->SyncStateAfterVSync(window_android, this); |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 342 | } |
| 343 | |
boliu | 42e0131 | 2016-05-12 21:47:52 | [diff] [blame] | 344 | void SynchronousCompositorHost::OutputSurfaceCreated() { |
| 345 | // New output surface is not aware of state from Browser side. So need to |
| 346 | // re-send all browser side state here. |
| 347 | sender_->Send( |
| 348 | new SyncCompositorMsg_SetMemoryPolicy(routing_id_, bytes_limit_)); |
| 349 | } |
| 350 | |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 351 | void SynchronousCompositorHost::ProcessCommonParams( |
| 352 | const SyncCompositorCommonRendererParams& params) { |
| 353 | // Ignore if |renderer_param_version_| is newer than |params.version|. This |
| 354 | // comparison takes into account when the unsigned int wraps. |
| 355 | if ((renderer_param_version_ - params.version) < 0x80000000) { |
| 356 | return; |
| 357 | } |
| 358 | renderer_param_version_ = params.version; |
| 359 | need_animate_scroll_ = params.need_animate_scroll; |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 360 | root_scroll_offset_ = params.total_scroll_offset; |
| 361 | |
boliu | 17bc31f | 2016-02-23 18:46:28 | [diff] [blame] | 362 | if (need_invalidate_count_ != params.need_invalidate_count) { |
| 363 | need_invalidate_count_ = params.need_invalidate_count; |
hush | 83e367c | 2016-06-18 02:37:54 | [diff] [blame] | 364 | client_->PostInvalidate(this); |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 365 | } |
| 366 | |
boliu | 17bc31f | 2016-02-23 18:46:28 | [diff] [blame] | 367 | if (did_activate_pending_tree_count_ != |
| 368 | params.did_activate_pending_tree_count) { |
| 369 | did_activate_pending_tree_count_ = params.did_activate_pending_tree_count; |
hush | 83e367c | 2016-06-18 02:37:54 | [diff] [blame] | 370 | client_->DidUpdateContent(this); |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | // Ensure only valid values from compositor are sent to client. |
| 374 | // Compositor has page_scale_factor set to 0 before initialization, so check |
| 375 | // for that case here. |
| 376 | if (params.page_scale_factor) { |
| 377 | client_->UpdateRootLayerState( |
hush | 83e367c | 2016-06-18 02:37:54 | [diff] [blame] | 378 | this, gfx::ScrollOffsetToVector2dF(params.total_scroll_offset), |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 379 | gfx::ScrollOffsetToVector2dF(params.max_scroll_offset), |
| 380 | params.scrollable_size, params.page_scale_factor, |
| 381 | params.min_page_scale_factor, params.max_page_scale_factor); |
| 382 | } |
| 383 | } |
| 384 | |
boliu | bee541f4 | 2015-11-05 00:52:53 | [diff] [blame] | 385 | } // namespace content |