| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/renderer_host/render_widget_host_view_aura.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 | 302 |
| 303 if (event.type() == ui::ET_GESTURE_BEGIN) { | 303 if (event.type() == ui::ET_GESTURE_BEGIN) { |
| 304 const ui::GestureEvent& gesture = | 304 const ui::GestureEvent& gesture = |
| 305 static_cast<const ui::GestureEvent&>(event); | 305 static_cast<const ui::GestureEvent&>(event); |
| 306 return gesture.details().touch_points() == 1; | 306 return gesture.details().touch_points() == 1; |
| 307 } | 307 } |
| 308 | 308 |
| 309 return false; | 309 return false; |
| 310 } | 310 } |
| 311 | 311 |
| 312 // Swap ack for the renderer when kCompositeToMailbox is enabled. | |
| 313 void SendCompositorFrameAck( | |
| 314 int32 route_id, | |
| 315 uint32 output_surface_id, | |
| 316 int renderer_host_id, | |
| 317 const gpu::Mailbox& received_mailbox, | |
| 318 const gfx::Size& received_size, | |
| 319 bool skip_frame, | |
| 320 const scoped_refptr<ui::Texture>& texture_to_produce) { | |
| 321 cc::CompositorFrameAck ack; | |
| 322 ack.gl_frame_data.reset(new cc::GLFrameData()); | |
| 323 DCHECK(!texture_to_produce.get() || !skip_frame); | |
| 324 if (texture_to_produce.get()) { | |
| 325 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); | |
| 326 std::string mailbox_name = texture_to_produce->Produce(); | |
| 327 std::copy(mailbox_name.data(), | |
| 328 mailbox_name.data() + mailbox_name.length(), | |
| 329 reinterpret_cast<char*>(ack.gl_frame_data->mailbox.name)); | |
| 330 ack.gl_frame_data->size = texture_to_produce->size(); | |
| 331 ack.gl_frame_data->sync_point = | |
| 332 gl_helper ? gl_helper->InsertSyncPoint() : 0; | |
| 333 } else if (skip_frame) { | |
| 334 // Skip the frame, i.e. tell the producer to reuse the same buffer that | |
| 335 // we just received. | |
| 336 ack.gl_frame_data->size = received_size; | |
| 337 ack.gl_frame_data->mailbox = received_mailbox; | |
| 338 } | |
| 339 | |
| 340 RenderWidgetHostImpl::SendSwapCompositorFrameAck( | |
| 341 route_id, output_surface_id, renderer_host_id, ack); | |
| 342 } | |
| 343 | |
| 344 void AcknowledgeBufferForGpu( | |
| 345 int32 route_id, | |
| 346 int gpu_host_id, | |
| 347 const std::string& received_mailbox, | |
| 348 bool skip_frame, | |
| 349 const scoped_refptr<ui::Texture>& texture_to_produce) { | |
| 350 AcceleratedSurfaceMsg_BufferPresented_Params ack; | |
| 351 uint32 sync_point = 0; | |
| 352 DCHECK(!texture_to_produce.get() || !skip_frame); | |
| 353 if (texture_to_produce.get()) { | |
| 354 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); | |
| 355 ack.mailbox_name = texture_to_produce->Produce(); | |
| 356 sync_point = gl_helper ? gl_helper->InsertSyncPoint() : 0; | |
| 357 } else if (skip_frame) { | |
| 358 ack.mailbox_name = received_mailbox; | |
| 359 ack.sync_point = 0; | |
| 360 } | |
| 361 | |
| 362 ack.sync_point = sync_point; | |
| 363 RenderWidgetHostImpl::AcknowledgeBufferPresent( | |
| 364 route_id, gpu_host_id, ack); | |
| 365 } | |
| 366 | |
| 367 } // namespace | 312 } // namespace |
| 368 | 313 |
| 369 // We need to watch for mouse events outside a Web Popup or its parent | 314 // We need to watch for mouse events outside a Web Popup or its parent |
| 370 // and dismiss the popup for certain events. | 315 // and dismiss the popup for certain events. |
| 371 class RenderWidgetHostViewAura::EventFilterForPopupExit : | 316 class RenderWidgetHostViewAura::EventFilterForPopupExit : |
| 372 public ui::EventHandler { | 317 public ui::EventHandler { |
| 373 public: | 318 public: |
| 374 explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva) | 319 explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva) |
| 375 : rwhva_(rwhva) { | 320 : rwhva_(rwhva) { |
| 376 DCHECK(rwhva_); | 321 DCHECK(rwhva_); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 popup_child_host_view_(NULL), | 407 popup_child_host_view_(NULL), |
| 463 is_loading_(false), | 408 is_loading_(false), |
| 464 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 409 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
| 465 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), | 410 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), |
| 466 can_compose_inline_(true), | 411 can_compose_inline_(true), |
| 467 has_composition_text_(false), | 412 has_composition_text_(false), |
| 468 accept_return_character_(false), | 413 accept_return_character_(false), |
| 469 last_output_surface_id_(0), | 414 last_output_surface_id_(0), |
| 470 pending_delegated_ack_count_(0), | 415 pending_delegated_ack_count_(0), |
| 471 skipped_frames_(false), | 416 skipped_frames_(false), |
| 472 last_swapped_surface_scale_factor_(1.f), | 417 last_swapped_software_frame_scale_factor_(1.f), |
| 473 paint_canvas_(NULL), | 418 paint_canvas_(NULL), |
| 474 synthetic_move_sent_(false), | 419 synthetic_move_sent_(false), |
| 475 accelerated_compositing_state_changed_(false), | |
| 476 can_lock_compositor_(YES), | 420 can_lock_compositor_(YES), |
| 477 cursor_visibility_state_in_renderer_(UNKNOWN), | 421 cursor_visibility_state_in_renderer_(UNKNOWN), |
| 478 touch_editing_client_(NULL), | 422 touch_editing_client_(NULL), |
| 479 delegated_frame_evictor_(new DelegatedFrameEvictor(this)), | 423 delegated_frame_evictor_(new DelegatedFrameEvictor(this)), |
| 480 weak_ptr_factory_(this) { | 424 weak_ptr_factory_(this) { |
| 481 host_->SetView(this); | 425 host_->SetView(this); |
| 482 window_observer_.reset(new WindowObserver(this)); | 426 window_observer_.reset(new WindowObserver(this)); |
| 483 aura::client::SetTooltipText(window_, &tooltip_); | 427 aura::client::SetTooltipText(window_, &tooltip_); |
| 484 aura::client::SetActivationDelegate(window_, this); | 428 aura::client::SetActivationDelegate(window_, this); |
| 485 aura::client::SetActivationChangeObserver(window_, this); | 429 aura::client::SetActivationChangeObserver(window_, this); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 delegated_frame_evictor_->SetVisible(true); | 545 delegated_frame_evictor_->SetVisible(true); |
| 602 | 546 |
| 603 aura::Window* root = window_->GetRootWindow(); | 547 aura::Window* root = window_->GetRootWindow(); |
| 604 if (root) { | 548 if (root) { |
| 605 aura::client::CursorClient* cursor_client = | 549 aura::client::CursorClient* cursor_client = |
| 606 aura::client::GetCursorClient(root); | 550 aura::client::GetCursorClient(root); |
| 607 if (cursor_client) | 551 if (cursor_client) |
| 608 NotifyRendererOfCursorVisibilityState(cursor_client->IsCursorVisible()); | 552 NotifyRendererOfCursorVisibilityState(cursor_client->IsCursorVisible()); |
| 609 } | 553 } |
| 610 | 554 |
| 611 if (!current_surface_.get() && host_->is_accelerated_compositing_active() && | 555 if (host_->is_accelerated_compositing_active() && |
| 612 !released_front_lock_.get()) { | 556 !released_front_lock_.get()) { |
| 613 ui::Compositor* compositor = GetCompositor(); | 557 ui::Compositor* compositor = GetCompositor(); |
| 614 if (compositor) | 558 if (compositor) |
| 615 released_front_lock_ = compositor->GetCompositorLock(); | 559 released_front_lock_ = compositor->GetCompositorLock(); |
| 616 } | 560 } |
| 617 | 561 |
| 618 #if defined(OS_WIN) | 562 #if defined(OS_WIN) |
| 619 if (legacy_render_widget_host_HWND_) { | 563 if (legacy_render_widget_host_HWND_) { |
| 620 // Reparent the legacy Chrome_RenderWidgetHostHWND window to the parent | 564 // Reparent the legacy Chrome_RenderWidgetHostHWND window to the parent |
| 621 // window before reparenting any plugins. This ensures that the plugin | 565 // window before reparenting any plugins. This ensures that the plugin |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 | 658 |
| 715 if (resize_lock_) | 659 if (resize_lock_) |
| 716 return false; | 660 return false; |
| 717 | 661 |
| 718 if (host_->should_auto_resize()) | 662 if (host_->should_auto_resize()) |
| 719 return false; | 663 return false; |
| 720 if (!host_->is_accelerated_compositing_active()) | 664 if (!host_->is_accelerated_compositing_active()) |
| 721 return false; | 665 return false; |
| 722 | 666 |
| 723 gfx::Size desired_size = window_->bounds().size(); | 667 gfx::Size desired_size = window_->bounds().size(); |
| 724 if (desired_size == current_frame_size_) | 668 if (desired_size == current_frame_size_in_dip_) |
| 725 return false; | 669 return false; |
| 726 | 670 |
| 727 aura::WindowEventDispatcher* dispatcher = window_->GetDispatcher(); | 671 aura::WindowEventDispatcher* dispatcher = window_->GetDispatcher(); |
| 728 if (!dispatcher) | 672 if (!dispatcher) |
| 729 return false; | 673 return false; |
| 730 | 674 |
| 731 ui::Compositor* compositor = dispatcher->host()->compositor(); | 675 ui::Compositor* compositor = dispatcher->host()->compositor(); |
| 732 if (!compositor) | 676 if (!compositor) |
| 733 return false; | 677 return false; |
| 734 | 678 |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 953 const gfx::Range& range, | 897 const gfx::Range& range, |
| 954 const std::vector<gfx::Rect>& character_bounds) { | 898 const std::vector<gfx::Rect>& character_bounds) { |
| 955 composition_character_bounds_ = character_bounds; | 899 composition_character_bounds_ = character_bounds; |
| 956 } | 900 } |
| 957 | 901 |
| 958 void RenderWidgetHostViewAura::DidUpdateBackingStore( | 902 void RenderWidgetHostViewAura::DidUpdateBackingStore( |
| 959 const gfx::Rect& scroll_rect, | 903 const gfx::Rect& scroll_rect, |
| 960 const gfx::Vector2d& scroll_delta, | 904 const gfx::Vector2d& scroll_delta, |
| 961 const std::vector<gfx::Rect>& copy_rects, | 905 const std::vector<gfx::Rect>& copy_rects, |
| 962 const std::vector<ui::LatencyInfo>& latency_info) { | 906 const std::vector<ui::LatencyInfo>& latency_info) { |
| 963 if (accelerated_compositing_state_changed_) | |
| 964 UpdateExternalTexture(); | |
| 965 | |
| 966 for (size_t i = 0; i < latency_info.size(); i++) | 907 for (size_t i = 0; i < latency_info.size(); i++) |
| 967 software_latency_info_.push_back(latency_info[i]); | 908 software_latency_info_.push_back(latency_info[i]); |
| 968 | 909 |
| 969 // Use the state of the RenderWidgetHost and not the window as the two may | 910 // Use the state of the RenderWidgetHost and not the window as the two may |
| 970 // differ. In particular if the window is hidden but the renderer isn't and we | 911 // differ. In particular if the window is hidden but the renderer isn't and we |
| 971 // ignore the update and the window is made visible again the layer isn't | 912 // ignore the update and the window is made visible again the layer isn't |
| 972 // marked as dirty and we show the wrong thing. | 913 // marked as dirty and we show the wrong thing. |
| 973 // We do this after UpdateExternalTexture() so that when we become visible | |
| 974 // we're not drawing a stale texture. | |
| 975 if (host_->is_hidden()) | 914 if (host_->is_hidden()) |
| 976 return; | 915 return; |
| 977 | 916 |
| 978 gfx::Rect clip_rect; | 917 gfx::Rect clip_rect; |
| 979 if (paint_canvas_) { | 918 if (paint_canvas_) { |
| 980 SkRect sk_clip_rect; | 919 SkRect sk_clip_rect; |
| 981 if (paint_canvas_->sk_canvas()->getClipBounds(&sk_clip_rect)) | 920 if (paint_canvas_->sk_canvas()->getClipBounds(&sk_clip_rect)) |
| 982 clip_rect = gfx::ToEnclosingRect(gfx::SkRectToRectF(sk_clip_rect)); | 921 clip_rect = gfx::ToEnclosingRect(gfx::SkRectToRectF(sk_clip_rect)); |
| 983 } | 922 } |
| 984 | 923 |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1177 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) { | 1116 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) { |
| 1178 frame_subscriber_ = subscriber.Pass(); | 1117 frame_subscriber_ = subscriber.Pass(); |
| 1179 } | 1118 } |
| 1180 | 1119 |
| 1181 void RenderWidgetHostViewAura::EndFrameSubscription() { | 1120 void RenderWidgetHostViewAura::EndFrameSubscription() { |
| 1182 idle_frame_subscriber_textures_.clear(); | 1121 idle_frame_subscriber_textures_.clear(); |
| 1183 frame_subscriber_.reset(); | 1122 frame_subscriber_.reset(); |
| 1184 } | 1123 } |
| 1185 | 1124 |
| 1186 void RenderWidgetHostViewAura::OnAcceleratedCompositingStateChange() { | 1125 void RenderWidgetHostViewAura::OnAcceleratedCompositingStateChange() { |
| 1187 // Delay processing the state change until we either get a software frame if | |
| 1188 // switching to software mode or receive a buffers swapped notification | |
| 1189 // if switching to accelerated mode. | |
| 1190 // Sometimes (e.g. on a page load) the renderer will spuriously disable then | |
| 1191 // re-enable accelerated compositing, causing us to flash. | |
| 1192 // TODO(piman): factor the enable/disable accelerated compositing message into | |
| 1193 // the UpdateRect/AcceleratedSurfaceBuffersSwapped messages so that we have | |
| 1194 // fewer inconsistent temporary states. | |
| 1195 accelerated_compositing_state_changed_ = true; | |
| 1196 } | 1126 } |
| 1197 | 1127 |
| 1198 void RenderWidgetHostViewAura::AcceleratedSurfaceInitialized(int host_id, | 1128 void RenderWidgetHostViewAura::AcceleratedSurfaceInitialized(int host_id, |
| 1199 int route_id) { | 1129 int route_id) { |
| 1200 } | 1130 } |
| 1201 | 1131 |
| 1202 bool RenderWidgetHostViewAura::ShouldSkipFrame(gfx::Size size_in_dip) const { | 1132 bool RenderWidgetHostViewAura::ShouldSkipFrame(gfx::Size size_in_dip) const { |
| 1203 if (can_lock_compositor_ == NO_PENDING_RENDERER_FRAME || | 1133 if (can_lock_compositor_ == NO_PENDING_RENDERER_FRAME || |
| 1204 can_lock_compositor_ == NO_PENDING_COMMIT || | 1134 can_lock_compositor_ == NO_PENDING_COMMIT || |
| 1205 !resize_lock_.get()) | 1135 !resize_lock_.get()) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1240 } | 1170 } |
| 1241 if (legacy_render_widget_host_HWND_) { | 1171 if (legacy_render_widget_host_HWND_) { |
| 1242 legacy_render_widget_host_HWND_->SetBounds( | 1172 legacy_render_widget_host_HWND_->SetBounds( |
| 1243 window_->GetBoundsInRootWindow()); | 1173 window_->GetBoundsInRootWindow()); |
| 1244 } | 1174 } |
| 1245 } | 1175 } |
| 1246 #endif | 1176 #endif |
| 1247 } | 1177 } |
| 1248 | 1178 |
| 1249 void RenderWidgetHostViewAura::CheckResizeLock() { | 1179 void RenderWidgetHostViewAura::CheckResizeLock() { |
| 1250 if (!resize_lock_ || resize_lock_->expected_size() != current_frame_size_) | 1180 if (!resize_lock_ || |
| 1181 resize_lock_->expected_size() != current_frame_size_in_dip_) |
| 1251 return; | 1182 return; |
| 1252 | 1183 |
| 1253 // Since we got the size we were looking for, unlock the compositor. But delay | 1184 // Since we got the size we were looking for, unlock the compositor. But delay |
| 1254 // the release of the lock until we've kicked a frame with the new texture, to | 1185 // the release of the lock until we've kicked a frame with the new texture, to |
| 1255 // avoid resizing the UI before we have a chance to draw a "good" frame. | 1186 // avoid resizing the UI before we have a chance to draw a "good" frame. |
| 1256 resize_lock_->UnlockCompositor(); | 1187 resize_lock_->UnlockCompositor(); |
| 1257 ui::Compositor* compositor = GetCompositor(); | 1188 ui::Compositor* compositor = GetCompositor(); |
| 1258 if (compositor) { | 1189 if (compositor) { |
| 1259 if (!compositor->HasObserver(this)) | 1190 if (!compositor->HasObserver(this)) |
| 1260 compositor->AddObserver(this); | 1191 compositor->AddObserver(this); |
| 1261 } | 1192 } |
| 1262 } | 1193 } |
| 1263 | 1194 |
| 1264 void RenderWidgetHostViewAura::UpdateExternalTexture() { | |
| 1265 // Delay processing accelerated compositing state change till here where we | |
| 1266 // act upon the state change. (Clear the external texture if switching to | |
| 1267 // software mode or set the external texture if going to accelerated mode). | |
| 1268 if (accelerated_compositing_state_changed_) | |
| 1269 accelerated_compositing_state_changed_ = false; | |
| 1270 | |
| 1271 bool is_compositing_active = host_->is_accelerated_compositing_active(); | |
| 1272 if (is_compositing_active && current_surface_.get()) { | |
| 1273 window_->layer()->SetExternalTexture(current_surface_.get()); | |
| 1274 current_frame_size_ = ConvertSizeToDIP( | |
| 1275 current_surface_->device_scale_factor(), current_surface_->size()); | |
| 1276 CheckResizeLock(); | |
| 1277 software_frame_manager_->DiscardCurrentFrame(); | |
| 1278 } else if (is_compositing_active && | |
| 1279 software_frame_manager_->HasCurrentFrame()) { | |
| 1280 cc::TextureMailbox mailbox; | |
| 1281 scoped_ptr<cc::SingleReleaseCallback> callback; | |
| 1282 software_frame_manager_->GetCurrentFrameMailbox(&mailbox, &callback); | |
| 1283 window_->layer()->SetTextureMailbox(mailbox, | |
| 1284 callback.Pass(), | |
| 1285 last_swapped_surface_scale_factor_); | |
| 1286 current_frame_size_ = ConvertSizeToDIP(last_swapped_surface_scale_factor_, | |
| 1287 mailbox.shared_memory_size()); | |
| 1288 CheckResizeLock(); | |
| 1289 } else { | |
| 1290 window_->layer()->SetShowPaintedContent(); | |
| 1291 resize_lock_.reset(); | |
| 1292 host_->WasResized(); | |
| 1293 software_frame_manager_->DiscardCurrentFrame(); | |
| 1294 } | |
| 1295 } | |
| 1296 | |
| 1297 bool RenderWidgetHostViewAura::SwapBuffersPrepare( | |
| 1298 const gfx::Rect& surface_rect, | |
| 1299 float surface_scale_factor, | |
| 1300 const gfx::Rect& damage_rect, | |
| 1301 const std::string& mailbox_name, | |
| 1302 const BufferPresentedCallback& ack_callback) { | |
| 1303 if (last_swapped_surface_size_ != surface_rect.size()) { | |
| 1304 // The surface could have shrunk since we skipped an update, in which | |
| 1305 // case we can expect a full update. | |
| 1306 DLOG_IF(ERROR, damage_rect != surface_rect) << "Expected full damage rect"; | |
| 1307 skipped_damage_.setEmpty(); | |
| 1308 last_swapped_surface_size_ = surface_rect.size(); | |
| 1309 last_swapped_surface_scale_factor_ = surface_scale_factor; | |
| 1310 } | |
| 1311 | |
| 1312 if (ShouldSkipFrame(ConvertSizeToDIP(surface_scale_factor, | |
| 1313 surface_rect.size())) || | |
| 1314 mailbox_name.empty()) { | |
| 1315 skipped_damage_.op(RectToSkIRect(damage_rect), SkRegion::kUnion_Op); | |
| 1316 ack_callback.Run(true, scoped_refptr<ui::Texture>()); | |
| 1317 return false; | |
| 1318 } | |
| 1319 | |
| 1320 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | |
| 1321 current_surface_ = | |
| 1322 factory->CreateTransportClient(surface_scale_factor); | |
| 1323 if (!current_surface_.get()) { | |
| 1324 LOG(ERROR) << "Failed to create ImageTransport texture"; | |
| 1325 ack_callback.Run(true, scoped_refptr<ui::Texture>()); | |
| 1326 return false; | |
| 1327 } | |
| 1328 | |
| 1329 current_surface_->Consume(mailbox_name, surface_rect.size()); | |
| 1330 released_front_lock_ = NULL; | |
| 1331 UpdateExternalTexture(); | |
| 1332 | |
| 1333 return true; | |
| 1334 } | |
| 1335 | |
| 1336 void RenderWidgetHostViewAura::SwapBuffersCompleted( | |
| 1337 const BufferPresentedCallback& ack_callback, | |
| 1338 const scoped_refptr<ui::Texture>& texture_to_return) { | |
| 1339 ui::Compositor* compositor = GetCompositor(); | |
| 1340 if (!compositor) { | |
| 1341 ack_callback.Run(false, texture_to_return); | |
| 1342 } else { | |
| 1343 AddOnCommitCallbackAndDisableLocks( | |
| 1344 base::Bind(ack_callback, false, texture_to_return)); | |
| 1345 } | |
| 1346 | |
| 1347 DidReceiveFrameFromRenderer(); | |
| 1348 } | |
| 1349 | |
| 1350 void RenderWidgetHostViewAura::DidReceiveFrameFromRenderer() { | 1195 void RenderWidgetHostViewAura::DidReceiveFrameFromRenderer() { |
| 1351 if (frame_subscriber() && CanCopyToVideoFrame()) { | 1196 if (frame_subscriber() && CanCopyToVideoFrame()) { |
| 1352 const base::TimeTicks present_time = base::TimeTicks::Now(); | 1197 const base::TimeTicks present_time = base::TimeTicks::Now(); |
| 1353 scoped_refptr<media::VideoFrame> frame; | 1198 scoped_refptr<media::VideoFrame> frame; |
| 1354 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback; | 1199 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback; |
| 1355 if (frame_subscriber()->ShouldCaptureFrame(present_time, | 1200 if (frame_subscriber()->ShouldCaptureFrame(present_time, |
| 1356 &frame, &callback)) { | 1201 &frame, &callback)) { |
| 1357 CopyFromCompositingSurfaceToVideoFrame( | 1202 CopyFromCompositingSurfaceToVideoFrame( |
| 1358 gfx::Rect(current_frame_size_), | 1203 gfx::Rect(current_frame_size_in_dip_), |
| 1359 frame, | 1204 frame, |
| 1360 base::Bind(callback, present_time)); | 1205 base::Bind(callback, present_time)); |
| 1361 } | 1206 } |
| 1362 } | 1207 } |
| 1363 } | 1208 } |
| 1364 | 1209 |
| 1365 #if defined(OS_WIN) | 1210 #if defined(OS_WIN) |
| 1366 void RenderWidgetHostViewAura::UpdateConstrainedWindowRects( | 1211 void RenderWidgetHostViewAura::UpdateConstrainedWindowRects( |
| 1367 const std::vector<gfx::Rect>& rects) { | 1212 const std::vector<gfx::Rect>& rects) { |
| 1368 // Check this before setting constrained_rects_, so that next time they're set | 1213 // Check this before setting constrained_rects_, so that next time they're set |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1381 params.cutout_rects = constrained_rects_; | 1226 params.cutout_rects = constrained_rects_; |
| 1382 params.geometry = &plugin_window_moves_; | 1227 params.geometry = &plugin_window_moves_; |
| 1383 LPARAM lparam = reinterpret_cast<LPARAM>(¶ms); | 1228 LPARAM lparam = reinterpret_cast<LPARAM>(¶ms); |
| 1384 EnumChildWindows(parent, SetCutoutRectsCallback, lparam); | 1229 EnumChildWindows(parent, SetCutoutRectsCallback, lparam); |
| 1385 } | 1230 } |
| 1386 #endif | 1231 #endif |
| 1387 | 1232 |
| 1388 void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped( | 1233 void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped( |
| 1389 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel, | 1234 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel, |
| 1390 int gpu_host_id) { | 1235 int gpu_host_id) { |
| 1391 BufferPresentedCallback ack_callback = base::Bind( | 1236 // Oldschool composited mode is no longer supported. |
| 1392 &AcknowledgeBufferForGpu, | |
| 1393 params_in_pixel.route_id, | |
| 1394 gpu_host_id, | |
| 1395 params_in_pixel.mailbox_name); | |
| 1396 BuffersSwapped(params_in_pixel.size, | |
| 1397 gfx::Rect(params_in_pixel.size), | |
| 1398 params_in_pixel.scale_factor, | |
| 1399 params_in_pixel.mailbox_name, | |
| 1400 params_in_pixel.latency_info, | |
| 1401 ack_callback); | |
| 1402 } | 1237 } |
| 1403 | 1238 |
| 1404 void RenderWidgetHostViewAura::SwapDelegatedFrame( | 1239 void RenderWidgetHostViewAura::SwapDelegatedFrame( |
| 1405 uint32 output_surface_id, | 1240 uint32 output_surface_id, |
| 1406 scoped_ptr<cc::DelegatedFrameData> frame_data, | 1241 scoped_ptr<cc::DelegatedFrameData> frame_data, |
| 1407 float frame_device_scale_factor, | 1242 float frame_device_scale_factor, |
| 1408 const std::vector<ui::LatencyInfo>& latency_info) { | 1243 const std::vector<ui::LatencyInfo>& latency_info) { |
| 1409 DCHECK_NE(0u, frame_data->render_pass_list.size()); | 1244 DCHECK_NE(0u, frame_data->render_pass_list.size()); |
| 1410 | 1245 |
| 1411 cc::RenderPass* root_pass = frame_data->render_pass_list.back(); | 1246 cc::RenderPass* root_pass = frame_data->render_pass_list.back(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1471 if (!resource_collection_) { | 1306 if (!resource_collection_) { |
| 1472 resource_collection_ = new cc::DelegatedFrameResourceCollection; | 1307 resource_collection_ = new cc::DelegatedFrameResourceCollection; |
| 1473 resource_collection_->SetClient(this); | 1308 resource_collection_->SetClient(this); |
| 1474 } | 1309 } |
| 1475 // If the physical frame size changes, we need a new |frame_provider_|. If | 1310 // If the physical frame size changes, we need a new |frame_provider_|. If |
| 1476 // the physical frame size is the same, but the size in DIP changed, we | 1311 // the physical frame size is the same, but the size in DIP changed, we |
| 1477 // need to adjust the scale at which the frames will be drawn, and we do | 1312 // need to adjust the scale at which the frames will be drawn, and we do |
| 1478 // this by making a new |frame_provider_| also to ensure the scale change | 1313 // this by making a new |frame_provider_| also to ensure the scale change |
| 1479 // is presented in sync with the new frame content. | 1314 // is presented in sync with the new frame content. |
| 1480 if (!frame_provider_.get() || frame_size != frame_provider_->frame_size() || | 1315 if (!frame_provider_.get() || frame_size != frame_provider_->frame_size() || |
| 1481 frame_size_in_dip != current_frame_size_) { | 1316 frame_size_in_dip != current_frame_size_in_dip_) { |
| 1482 frame_provider_ = new cc::DelegatedFrameProvider( | 1317 frame_provider_ = new cc::DelegatedFrameProvider( |
| 1483 resource_collection_.get(), frame_data.Pass()); | 1318 resource_collection_.get(), frame_data.Pass()); |
| 1484 window_->layer()->SetShowDelegatedContent(frame_provider_.get(), | 1319 window_->layer()->SetShowDelegatedContent(frame_provider_.get(), |
| 1485 frame_size_in_dip); | 1320 frame_size_in_dip); |
| 1486 } else { | 1321 } else { |
| 1487 frame_provider_->SetFrameData(frame_data.Pass()); | 1322 frame_provider_->SetFrameData(frame_data.Pass()); |
| 1488 } | 1323 } |
| 1489 } | 1324 } |
| 1490 released_front_lock_ = NULL; | 1325 released_front_lock_ = NULL; |
| 1491 current_frame_size_ = frame_size_in_dip; | 1326 current_frame_size_in_dip_ = frame_size_in_dip; |
| 1492 CheckResizeLock(); | 1327 CheckResizeLock(); |
| 1493 | 1328 |
| 1494 window_->SchedulePaintInRect(damage_rect_in_dip); | 1329 window_->SchedulePaintInRect(damage_rect_in_dip); |
| 1495 | 1330 |
| 1496 pending_delegated_ack_count_++; | 1331 pending_delegated_ack_count_++; |
| 1497 | 1332 |
| 1498 ui::Compositor* compositor = GetCompositor(); | 1333 ui::Compositor* compositor = GetCompositor(); |
| 1499 if (!compositor) { | 1334 if (!compositor) { |
| 1500 SendDelegatedFrameAck(output_surface_id); | 1335 SendDelegatedFrameAck(output_surface_id); |
| 1501 } else { | 1336 } else { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1570 if (!software_frame_manager_->SwapToNewFrame( | 1405 if (!software_frame_manager_->SwapToNewFrame( |
| 1571 output_surface_id, | 1406 output_surface_id, |
| 1572 frame_data.get(), | 1407 frame_data.get(), |
| 1573 frame_device_scale_factor, | 1408 frame_device_scale_factor, |
| 1574 host_->GetProcess()->GetHandle())) { | 1409 host_->GetProcess()->GetHandle())) { |
| 1575 ReleaseSoftwareFrame(output_surface_id, frame_data->id); | 1410 ReleaseSoftwareFrame(output_surface_id, frame_data->id); |
| 1576 SendSoftwareFrameAck(output_surface_id); | 1411 SendSoftwareFrameAck(output_surface_id); |
| 1577 return; | 1412 return; |
| 1578 } | 1413 } |
| 1579 | 1414 |
| 1580 if (last_swapped_surface_size_ != frame_size) { | 1415 frame_provider_ = NULL; |
| 1416 delegated_frame_evictor_->DiscardedFrame(); |
| 1417 |
| 1418 if (last_swapped_software_frame_size_ != frame_size) { |
| 1581 DLOG_IF(ERROR, damage_rect != gfx::Rect(frame_size)) | 1419 DLOG_IF(ERROR, damage_rect != gfx::Rect(frame_size)) |
| 1582 << "Expected full damage rect"; | 1420 << "Expected full damage rect"; |
| 1583 } | 1421 } |
| 1584 last_swapped_surface_size_ = frame_size; | 1422 last_swapped_software_frame_size_ = frame_size; |
| 1585 last_swapped_surface_scale_factor_ = frame_device_scale_factor; | 1423 last_swapped_software_frame_scale_factor_ = frame_device_scale_factor; |
| 1586 | 1424 |
| 1587 cc::TextureMailbox mailbox; | 1425 cc::TextureMailbox mailbox; |
| 1588 scoped_ptr<cc::SingleReleaseCallback> callback; | 1426 scoped_ptr<cc::SingleReleaseCallback> callback; |
| 1589 software_frame_manager_->GetCurrentFrameMailbox(&mailbox, &callback); | 1427 software_frame_manager_->GetCurrentFrameMailbox(&mailbox, &callback); |
| 1590 DCHECK(mailbox.IsSharedMemory()); | 1428 DCHECK(mailbox.IsSharedMemory()); |
| 1591 current_frame_size_ = frame_size_in_dip; | 1429 current_frame_size_in_dip_ = frame_size_in_dip; |
| 1592 | 1430 |
| 1593 released_front_lock_ = NULL; | 1431 released_front_lock_ = NULL; |
| 1594 CheckResizeLock(); | 1432 CheckResizeLock(); |
| 1595 window_->layer()->SetTextureMailbox(mailbox, | 1433 window_->layer()->SetTextureMailbox(mailbox, |
| 1596 callback.Pass(), | 1434 callback.Pass(), |
| 1597 frame_device_scale_factor); | 1435 frame_device_scale_factor); |
| 1598 window_->SchedulePaintInRect( | 1436 window_->SchedulePaintInRect( |
| 1599 ConvertRectToDIP(frame_device_scale_factor, damage_rect)); | 1437 ConvertRectToDIP(frame_device_scale_factor, damage_rect)); |
| 1600 | 1438 |
| 1601 ui::Compositor* compositor = GetCompositor(); | 1439 ui::Compositor* compositor = GetCompositor(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1652 | 1490 |
| 1653 void RenderWidgetHostViewAura::OnSwapCompositorFrame( | 1491 void RenderWidgetHostViewAura::OnSwapCompositorFrame( |
| 1654 uint32 output_surface_id, | 1492 uint32 output_surface_id, |
| 1655 scoped_ptr<cc::CompositorFrame> frame) { | 1493 scoped_ptr<cc::CompositorFrame> frame) { |
| 1656 TRACE_EVENT0("content", "RenderWidgetHostViewAura::OnSwapCompositorFrame"); | 1494 TRACE_EVENT0("content", "RenderWidgetHostViewAura::OnSwapCompositorFrame"); |
| 1657 if (frame->delegated_frame_data) { | 1495 if (frame->delegated_frame_data) { |
| 1658 SwapDelegatedFrame(output_surface_id, | 1496 SwapDelegatedFrame(output_surface_id, |
| 1659 frame->delegated_frame_data.Pass(), | 1497 frame->delegated_frame_data.Pass(), |
| 1660 frame->metadata.device_scale_factor, | 1498 frame->metadata.device_scale_factor, |
| 1661 frame->metadata.latency_info); | 1499 frame->metadata.latency_info); |
| 1662 return; | 1500 } else if (frame->software_frame_data) { |
| 1663 } | |
| 1664 | |
| 1665 if (frame->software_frame_data) { | |
| 1666 SwapSoftwareFrame(output_surface_id, | 1501 SwapSoftwareFrame(output_surface_id, |
| 1667 frame->software_frame_data.Pass(), | 1502 frame->software_frame_data.Pass(), |
| 1668 frame->metadata.device_scale_factor, | 1503 frame->metadata.device_scale_factor, |
| 1669 frame->metadata.latency_info); | 1504 frame->metadata.latency_info); |
| 1670 return; | |
| 1671 } | 1505 } |
| 1672 | |
| 1673 if (!frame->gl_frame_data || frame->gl_frame_data->mailbox.IsZero()) | |
| 1674 return; | |
| 1675 | |
| 1676 BufferPresentedCallback ack_callback = base::Bind( | |
| 1677 &SendCompositorFrameAck, | |
| 1678 host_->GetRoutingID(), output_surface_id, host_->GetProcess()->GetID(), | |
| 1679 frame->gl_frame_data->mailbox, frame->gl_frame_data->size); | |
| 1680 | |
| 1681 if (!frame->gl_frame_data->sync_point) { | |
| 1682 LOG(ERROR) << "CompositorFrame without sync point. Skipping frame..."; | |
| 1683 ack_callback.Run(true, scoped_refptr<ui::Texture>()); | |
| 1684 return; | |
| 1685 } | |
| 1686 | |
| 1687 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); | |
| 1688 gl_helper->WaitSyncPoint(frame->gl_frame_data->sync_point); | |
| 1689 | |
| 1690 std::string mailbox_name( | |
| 1691 reinterpret_cast<const char*>(frame->gl_frame_data->mailbox.name), | |
| 1692 sizeof(frame->gl_frame_data->mailbox.name)); | |
| 1693 BuffersSwapped(frame->gl_frame_data->size, | |
| 1694 frame->gl_frame_data->sub_buffer_rect, | |
| 1695 frame->metadata.device_scale_factor, | |
| 1696 mailbox_name, | |
| 1697 frame->metadata.latency_info, | |
| 1698 ack_callback); | |
| 1699 } | 1506 } |
| 1700 | 1507 |
| 1701 #if defined(OS_WIN) | 1508 #if defined(OS_WIN) |
| 1702 void RenderWidgetHostViewAura::SetParentNativeViewAccessible( | 1509 void RenderWidgetHostViewAura::SetParentNativeViewAccessible( |
| 1703 gfx::NativeViewAccessible accessible_parent) { | 1510 gfx::NativeViewAccessible accessible_parent) { |
| 1704 if (GetBrowserAccessibilityManager()) { | 1511 if (GetBrowserAccessibilityManager()) { |
| 1705 GetBrowserAccessibilityManager()->ToBrowserAccessibilityManagerWin() | 1512 GetBrowserAccessibilityManager()->ToBrowserAccessibilityManagerWin() |
| 1706 ->set_parent_iaccessible(accessible_parent); | 1513 ->set_parent_iaccessible(accessible_parent); |
| 1707 } | 1514 } |
| 1708 } | 1515 } |
| 1709 | 1516 |
| 1710 gfx::NativeViewId RenderWidgetHostViewAura::GetParentForWindowlessPlugin() | 1517 gfx::NativeViewId RenderWidgetHostViewAura::GetParentForWindowlessPlugin() |
| 1711 const { | 1518 const { |
| 1712 if (legacy_render_widget_host_HWND_) { | 1519 if (legacy_render_widget_host_HWND_) { |
| 1713 return reinterpret_cast<gfx::NativeViewId>( | 1520 return reinterpret_cast<gfx::NativeViewId>( |
| 1714 legacy_render_widget_host_HWND_->hwnd()); | 1521 legacy_render_widget_host_HWND_->hwnd()); |
| 1715 } | 1522 } |
| 1716 return NULL; | 1523 return NULL; |
| 1717 } | 1524 } |
| 1718 #endif | 1525 #endif |
| 1719 | 1526 |
| 1720 void RenderWidgetHostViewAura::BuffersSwapped( | |
| 1721 const gfx::Size& surface_size, | |
| 1722 const gfx::Rect& damage_rect, | |
| 1723 float surface_scale_factor, | |
| 1724 const std::string& mailbox_name, | |
| 1725 const std::vector<ui::LatencyInfo>& latency_info, | |
| 1726 const BufferPresentedCallback& ack_callback) { | |
| 1727 scoped_refptr<ui::Texture> previous_texture(current_surface_); | |
| 1728 const gfx::Rect surface_rect = gfx::Rect(surface_size); | |
| 1729 software_frame_manager_->DiscardCurrentFrame(); | |
| 1730 | |
| 1731 if (!SwapBuffersPrepare(surface_rect, | |
| 1732 surface_scale_factor, | |
| 1733 damage_rect, | |
| 1734 mailbox_name, | |
| 1735 ack_callback)) { | |
| 1736 return; | |
| 1737 } | |
| 1738 | |
| 1739 SkRegion damage(RectToSkIRect(damage_rect)); | |
| 1740 if (!skipped_damage_.isEmpty()) { | |
| 1741 damage.op(skipped_damage_, SkRegion::kUnion_Op); | |
| 1742 skipped_damage_.setEmpty(); | |
| 1743 } | |
| 1744 | |
| 1745 DCHECK(surface_rect.Contains(SkIRectToRect(damage.getBounds()))); | |
| 1746 ui::Texture* current_texture = current_surface_.get(); | |
| 1747 | |
| 1748 const gfx::Size surface_size_in_pixel = surface_size; | |
| 1749 DLOG_IF(ERROR, previous_texture.get() && | |
| 1750 previous_texture->size() != current_texture->size() && | |
| 1751 SkIRectToRect(damage.getBounds()) != surface_rect) << | |
| 1752 "Expected full damage rect after size change"; | |
| 1753 if (previous_texture.get() && !previous_damage_.isEmpty() && | |
| 1754 previous_texture->size() == current_texture->size()) { | |
| 1755 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | |
| 1756 GLHelper* gl_helper = factory->GetGLHelper(); | |
| 1757 gl_helper->CopySubBufferDamage( | |
| 1758 current_texture->PrepareTexture(), | |
| 1759 previous_texture->PrepareTexture(), | |
| 1760 damage, | |
| 1761 previous_damage_); | |
| 1762 } | |
| 1763 previous_damage_ = damage; | |
| 1764 | |
| 1765 ui::Compositor* compositor = GetCompositor(); | |
| 1766 if (compositor) { | |
| 1767 // Co-ordinates come in OpenGL co-ordinate space. | |
| 1768 // We need to convert to layer space. | |
| 1769 gfx::Rect rect_to_paint = | |
| 1770 ConvertRectToDIP(surface_scale_factor, | |
| 1771 gfx::Rect(damage_rect.x(), | |
| 1772 surface_size_in_pixel.height() - | |
| 1773 damage_rect.y() - damage_rect.height(), | |
| 1774 damage_rect.width(), | |
| 1775 damage_rect.height())); | |
| 1776 | |
| 1777 // Damage may not have been DIP aligned, so inflate damage to compensate | |
| 1778 // for any round-off error. | |
| 1779 rect_to_paint.Inset(-1, -1); | |
| 1780 rect_to_paint.Intersect(window_->bounds()); | |
| 1781 | |
| 1782 window_->SchedulePaintInRect(rect_to_paint); | |
| 1783 for (size_t i = 0; i < latency_info.size(); i++) | |
| 1784 compositor->SetLatencyInfo(latency_info[i]); | |
| 1785 } | |
| 1786 | |
| 1787 SwapBuffersCompleted(ack_callback, previous_texture); | |
| 1788 } | |
| 1789 | |
| 1790 void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer( | 1527 void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer( |
| 1791 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel, | 1528 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel, |
| 1792 int gpu_host_id) { | 1529 int gpu_host_id) { |
| 1793 gfx::Rect damage_rect(params_in_pixel.x, | 1530 // Oldschool composited mode is no longer supported. |
| 1794 params_in_pixel.y, | |
| 1795 params_in_pixel.width, | |
| 1796 params_in_pixel.height); | |
| 1797 BufferPresentedCallback ack_callback = | |
| 1798 base::Bind(&AcknowledgeBufferForGpu, | |
| 1799 params_in_pixel.route_id, | |
| 1800 gpu_host_id, | |
| 1801 params_in_pixel.mailbox_name); | |
| 1802 BuffersSwapped(params_in_pixel.surface_size, | |
| 1803 damage_rect, | |
| 1804 params_in_pixel.surface_scale_factor, | |
| 1805 params_in_pixel.mailbox_name, | |
| 1806 params_in_pixel.latency_info, | |
| 1807 ack_callback); | |
| 1808 } | 1531 } |
| 1809 | 1532 |
| 1810 void RenderWidgetHostViewAura::AcceleratedSurfaceSuspend() { | 1533 void RenderWidgetHostViewAura::AcceleratedSurfaceSuspend() { |
| 1811 } | 1534 } |
| 1812 | 1535 |
| 1813 void RenderWidgetHostViewAura::AcceleratedSurfaceRelease() { | 1536 void RenderWidgetHostViewAura::AcceleratedSurfaceRelease() { |
| 1814 // This really tells us to release the frontbuffer. | |
| 1815 if (current_surface_.get()) { | |
| 1816 ui::Compositor* compositor = GetCompositor(); | |
| 1817 if (compositor) { | |
| 1818 // We need to wait for a commit to clear to guarantee that all we | |
| 1819 // will not issue any more GL referencing the previous surface. | |
| 1820 AddOnCommitCallbackAndDisableLocks( | |
| 1821 base::Bind(&RenderWidgetHostViewAura::SetSurfaceNotInUseByCompositor, | |
| 1822 AsWeakPtr(), | |
| 1823 current_surface_)); // Hold a ref so the texture will not | |
| 1824 // get deleted until after commit. | |
| 1825 } | |
| 1826 current_surface_ = NULL; | |
| 1827 UpdateExternalTexture(); | |
| 1828 } | |
| 1829 } | 1537 } |
| 1830 | 1538 |
| 1831 bool RenderWidgetHostViewAura::HasAcceleratedSurface( | 1539 bool RenderWidgetHostViewAura::HasAcceleratedSurface( |
| 1832 const gfx::Size& desired_size) { | 1540 const gfx::Size& desired_size) { |
| 1833 // Aura doesn't use GetBackingStore for accelerated pages, so it doesn't | 1541 // Aura doesn't use GetBackingStore for accelerated pages, so it doesn't |
| 1834 // matter what is returned here as GetBackingStore is the only caller of this | 1542 // matter what is returned here as GetBackingStore is the only caller of this |
| 1835 // method. TODO(jbates) implement this if other Aura code needs it. | 1543 // method. TODO(jbates) implement this if other Aura code needs it. |
| 1836 return false; | 1544 return false; |
| 1837 } | 1545 } |
| 1838 | 1546 |
| (...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2683 } | 2391 } |
| 2684 | 2392 |
| 2685 void RenderWidgetHostViewAura::GetHitTestMask(gfx::Path* mask) const { | 2393 void RenderWidgetHostViewAura::GetHitTestMask(gfx::Path* mask) const { |
| 2686 } | 2394 } |
| 2687 | 2395 |
| 2688 void RenderWidgetHostViewAura::DidRecreateLayer(ui::Layer *old_layer, | 2396 void RenderWidgetHostViewAura::DidRecreateLayer(ui::Layer *old_layer, |
| 2689 ui::Layer *new_layer) { | 2397 ui::Layer *new_layer) { |
| 2690 float mailbox_scale_factor; | 2398 float mailbox_scale_factor; |
| 2691 cc::TextureMailbox old_mailbox = | 2399 cc::TextureMailbox old_mailbox = |
| 2692 old_layer->GetTextureMailbox(&mailbox_scale_factor); | 2400 old_layer->GetTextureMailbox(&mailbox_scale_factor); |
| 2693 scoped_refptr<ui::Texture> old_texture = old_layer->external_texture(); | |
| 2694 // The new_layer is the one that will be used by our Window, so that's the one | 2401 // The new_layer is the one that will be used by our Window, so that's the one |
| 2695 // that should keep our texture. old_layer will be returned to the | 2402 // that should keep our texture. old_layer will be returned to the |
| 2696 // RecreateLayer caller, and should have a copy. | 2403 // RecreateLayer caller, and should have a copy. |
| 2697 if (old_texture.get()) { | 2404 if (old_mailbox.IsSharedMemory()) { |
| 2698 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | |
| 2699 GLHelper* gl_helper = factory->GetGLHelper(); | |
| 2700 scoped_refptr<ui::Texture> new_texture; | |
| 2701 if (host_->is_accelerated_compositing_active() && | |
| 2702 gl_helper && current_surface_.get()) { | |
| 2703 GLuint texture_id = | |
| 2704 gl_helper->CopyTexture(current_surface_->PrepareTexture(), | |
| 2705 current_surface_->size()); | |
| 2706 if (texture_id) { | |
| 2707 new_texture = factory->CreateOwnedTexture( | |
| 2708 current_surface_->size(), | |
| 2709 current_surface_->device_scale_factor(), texture_id); | |
| 2710 } | |
| 2711 } | |
| 2712 if (new_texture.get()) | |
| 2713 old_layer->SetExternalTexture(new_texture.get()); | |
| 2714 else | |
| 2715 old_layer->SetShowPaintedContent(); | |
| 2716 new_layer->SetExternalTexture(old_texture.get()); | |
| 2717 } else if (old_mailbox.IsSharedMemory()) { | |
| 2718 base::SharedMemory* old_buffer = old_mailbox.shared_memory(); | 2405 base::SharedMemory* old_buffer = old_mailbox.shared_memory(); |
| 2719 const size_t size = old_mailbox.shared_memory_size_in_bytes(); | 2406 const size_t size = old_mailbox.shared_memory_size_in_bytes(); |
| 2720 | 2407 |
| 2721 scoped_ptr<base::SharedMemory> new_buffer(new base::SharedMemory); | 2408 scoped_ptr<base::SharedMemory> new_buffer(new base::SharedMemory); |
| 2722 new_buffer->CreateAndMapAnonymous(size); | 2409 new_buffer->CreateAndMapAnonymous(size); |
| 2723 | 2410 |
| 2724 if (old_buffer->memory() && new_buffer->memory()) { | 2411 if (old_buffer->memory() && new_buffer->memory()) { |
| 2725 memcpy(new_buffer->memory(), old_buffer->memory(), size); | 2412 memcpy(new_buffer->memory(), old_buffer->memory(), size); |
| 2726 base::SharedMemory* new_buffer_raw_ptr = new_buffer.get(); | 2413 base::SharedMemory* new_buffer_raw_ptr = new_buffer.get(); |
| 2727 scoped_ptr<cc::SingleReleaseCallback> callback = | 2414 scoped_ptr<cc::SingleReleaseCallback> callback = |
| 2728 cc::SingleReleaseCallback::Create(base::Bind(MailboxReleaseCallback, | 2415 cc::SingleReleaseCallback::Create(base::Bind(MailboxReleaseCallback, |
| 2729 Passed(&new_buffer))); | 2416 Passed(&new_buffer))); |
| 2730 cc::TextureMailbox new_mailbox(new_buffer_raw_ptr, | 2417 cc::TextureMailbox new_mailbox(new_buffer_raw_ptr, |
| 2731 old_mailbox.shared_memory_size()); | 2418 old_mailbox.shared_memory_size()); |
| 2732 new_layer->SetTextureMailbox(new_mailbox, | 2419 new_layer->SetTextureMailbox(new_mailbox, |
| 2733 callback.Pass(), | 2420 callback.Pass(), |
| 2734 mailbox_scale_factor); | 2421 mailbox_scale_factor); |
| 2735 } | 2422 } |
| 2736 } else if (frame_provider_.get()) { | 2423 } else if (frame_provider_.get()) { |
| 2737 new_layer->SetShowDelegatedContent(frame_provider_.get(), | 2424 new_layer->SetShowDelegatedContent(frame_provider_.get(), |
| 2738 current_frame_size_); | 2425 current_frame_size_in_dip_); |
| 2739 } | 2426 } |
| 2740 } | 2427 } |
| 2741 | 2428 |
| 2742 //////////////////////////////////////////////////////////////////////////////// | 2429 //////////////////////////////////////////////////////////////////////////////// |
| 2743 // RenderWidgetHostViewAura, ui::EventHandler implementation: | 2430 // RenderWidgetHostViewAura, ui::EventHandler implementation: |
| 2744 | 2431 |
| 2745 void RenderWidgetHostViewAura::OnKeyEvent(ui::KeyEvent* event) { | 2432 void RenderWidgetHostViewAura::OnKeyEvent(ui::KeyEvent* event) { |
| 2746 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnKeyEvent"); | 2433 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnKeyEvent"); |
| 2747 if (touch_editing_client_ && touch_editing_client_->HandleInputEvent(event)) | 2434 if (touch_editing_client_ && touch_editing_client_->HandleInputEvent(event)) |
| 2748 return; | 2435 return; |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3165 uint32 output_surface_id, unsigned frame_id) { | 2852 uint32 output_surface_id, unsigned frame_id) { |
| 3166 ReleaseSoftwareFrame(output_surface_id, frame_id); | 2853 ReleaseSoftwareFrame(output_surface_id, frame_id); |
| 3167 } | 2854 } |
| 3168 | 2855 |
| 3169 void RenderWidgetHostViewAura::ReleaseReferencesToSoftwareFrame() { | 2856 void RenderWidgetHostViewAura::ReleaseReferencesToSoftwareFrame() { |
| 3170 ui::Compositor* compositor = GetCompositor(); | 2857 ui::Compositor* compositor = GetCompositor(); |
| 3171 if (compositor) { | 2858 if (compositor) { |
| 3172 AddOnCommitCallbackAndDisableLocks(base::Bind( | 2859 AddOnCommitCallbackAndDisableLocks(base::Bind( |
| 3173 &RenderWidgetHostViewAura::SendReclaimSoftwareFrames, AsWeakPtr())); | 2860 &RenderWidgetHostViewAura::SendReclaimSoftwareFrames, AsWeakPtr())); |
| 3174 } | 2861 } |
| 3175 UpdateExternalTexture(); | 2862 window_->layer()->SetShowPaintedContent(); |
| 3176 } | 2863 } |
| 3177 | 2864 |
| 3178 //////////////////////////////////////////////////////////////////////////////// | 2865 //////////////////////////////////////////////////////////////////////////////// |
| 3179 // RenderWidgetHostViewAura, ui::CompositorObserver implementation: | 2866 // RenderWidgetHostViewAura, ui::CompositorObserver implementation: |
| 3180 | 2867 |
| 3181 void RenderWidgetHostViewAura::OnCompositingDidCommit( | 2868 void RenderWidgetHostViewAura::OnCompositingDidCommit( |
| 3182 ui::Compositor* compositor) { | 2869 ui::Compositor* compositor) { |
| 3183 if (can_lock_compositor_ == NO_PENDING_COMMIT) { | 2870 if (can_lock_compositor_ == NO_PENDING_COMMIT) { |
| 3184 can_lock_compositor_ = YES; | 2871 can_lock_compositor_ = YES; |
| 3185 if (resize_lock_.get() && resize_lock_->GrabDeferredLock()) | 2872 if (resize_lock_.get() && resize_lock_->GrabDeferredLock()) |
| 3186 can_lock_compositor_ = YES_DID_LOCK; | 2873 can_lock_compositor_ = YES_DID_LOCK; |
| 3187 } | 2874 } |
| 3188 RunOnCommitCallbacks(); | 2875 RunOnCommitCallbacks(); |
| 3189 if (resize_lock_ && resize_lock_->expected_size() == current_frame_size_) { | 2876 if (resize_lock_ && |
| 2877 resize_lock_->expected_size() == current_frame_size_in_dip_) { |
| 3190 resize_lock_.reset(); | 2878 resize_lock_.reset(); |
| 3191 host_->WasResized(); | 2879 host_->WasResized(); |
| 3192 // We may have had a resize while we had the lock (e.g. if the lock expired, | 2880 // We may have had a resize while we had the lock (e.g. if the lock expired, |
| 3193 // or if the UI still gave us some resizes), so make sure we grab a new lock | 2881 // or if the UI still gave us some resizes), so make sure we grab a new lock |
| 3194 // if necessary. | 2882 // if necessary. |
| 3195 MaybeCreateResizeLock(); | 2883 MaybeCreateResizeLock(); |
| 3196 } | 2884 } |
| 3197 } | 2885 } |
| 3198 | 2886 |
| 3199 void RenderWidgetHostViewAura::OnCompositingStarted( | 2887 void RenderWidgetHostViewAura::OnCompositingStarted( |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3284 | 2972 |
| 3285 void RenderWidgetHostViewAura::FatalAccessibilityTreeError() { | 2973 void RenderWidgetHostViewAura::FatalAccessibilityTreeError() { |
| 3286 host_->FatalAccessibilityTreeError(); | 2974 host_->FatalAccessibilityTreeError(); |
| 3287 SetBrowserAccessibilityManager(NULL); | 2975 SetBrowserAccessibilityManager(NULL); |
| 3288 } | 2976 } |
| 3289 | 2977 |
| 3290 //////////////////////////////////////////////////////////////////////////////// | 2978 //////////////////////////////////////////////////////////////////////////////// |
| 3291 // RenderWidgetHostViewAura, ImageTransportFactoryObserver implementation: | 2979 // RenderWidgetHostViewAura, ImageTransportFactoryObserver implementation: |
| 3292 | 2980 |
| 3293 void RenderWidgetHostViewAura::OnLostResources() { | 2981 void RenderWidgetHostViewAura::OnLostResources() { |
| 3294 current_surface_ = NULL; | 2982 if (frame_provider_.get()) |
| 3295 UpdateExternalTexture(); | 2983 EvictDelegatedFrame(); |
| 3296 | |
| 3297 idle_frame_subscriber_textures_.clear(); | 2984 idle_frame_subscriber_textures_.clear(); |
| 3298 yuv_readback_pipeline_.reset(); | 2985 yuv_readback_pipeline_.reset(); |
| 3299 | 2986 |
| 3300 // Make sure all ImageTransportClients are deleted now that the context those | |
| 3301 // are using is becoming invalid. This sends pending ACKs and needs to happen | |
| 3302 // after calling UpdateExternalTexture() which syncs with the impl thread. | |
| 3303 RunOnCommitCallbacks(); | |
| 3304 host_->ScheduleComposite(); | 2987 host_->ScheduleComposite(); |
| 3305 } | 2988 } |
| 3306 | 2989 |
| 3307 //////////////////////////////////////////////////////////////////////////////// | 2990 //////////////////////////////////////////////////////////////////////////////// |
| 3308 // RenderWidgetHostViewAura, private: | 2991 // RenderWidgetHostViewAura, private: |
| 3309 | 2992 |
| 3310 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() { | 2993 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() { |
| 3311 if (touch_editing_client_) | 2994 if (touch_editing_client_) |
| 3312 touch_editing_client_->OnViewDestroyed(); | 2995 touch_editing_client_->OnViewDestroyed(); |
| 3313 | 2996 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3498 void RenderWidgetHostViewAura::AddedToRootWindow() { | 3181 void RenderWidgetHostViewAura::AddedToRootWindow() { |
| 3499 window_->GetDispatcher()->AddRootWindowObserver(this); | 3182 window_->GetDispatcher()->AddRootWindowObserver(this); |
| 3500 UpdateScreenInfo(window_); | 3183 UpdateScreenInfo(window_); |
| 3501 | 3184 |
| 3502 aura::client::CursorClient* cursor_client = | 3185 aura::client::CursorClient* cursor_client = |
| 3503 aura::client::GetCursorClient(window_->GetRootWindow()); | 3186 aura::client::GetCursorClient(window_->GetRootWindow()); |
| 3504 if (cursor_client) { | 3187 if (cursor_client) { |
| 3505 cursor_client->AddObserver(this); | 3188 cursor_client->AddObserver(this); |
| 3506 NotifyRendererOfCursorVisibilityState(cursor_client->IsCursorVisible()); | 3189 NotifyRendererOfCursorVisibilityState(cursor_client->IsCursorVisible()); |
| 3507 } | 3190 } |
| 3508 if (current_surface_.get()) | |
| 3509 UpdateExternalTexture(); | |
| 3510 if (HasFocus()) { | 3191 if (HasFocus()) { |
| 3511 ui::InputMethod* input_method = GetInputMethod(); | 3192 ui::InputMethod* input_method = GetInputMethod(); |
| 3512 if (input_method) | 3193 if (input_method) |
| 3513 input_method->SetFocusedTextInputClient(this); | 3194 input_method->SetFocusedTextInputClient(this); |
| 3514 } | 3195 } |
| 3515 | 3196 |
| 3516 #if defined(OS_WIN) | 3197 #if defined(OS_WIN) |
| 3517 // The parent may have changed here. Ensure that the legacy window is | 3198 // The parent may have changed here. Ensure that the legacy window is |
| 3518 // reparented accordingly. | 3199 // reparented accordingly. |
| 3519 if (legacy_render_widget_host_HWND_) | 3200 if (legacy_render_widget_host_HWND_) |
| 3520 legacy_render_widget_host_HWND_->UpdateParent( | 3201 legacy_render_widget_host_HWND_->UpdateParent( |
| 3521 reinterpret_cast<HWND>(GetNativeViewId())); | 3202 reinterpret_cast<HWND>(GetNativeViewId())); |
| 3522 #endif | 3203 #endif |
| 3523 } | 3204 } |
| 3524 | 3205 |
| 3525 void RenderWidgetHostViewAura::RemovingFromRootWindow() { | 3206 void RenderWidgetHostViewAura::RemovingFromRootWindow() { |
| 3526 aura::client::CursorClient* cursor_client = | 3207 aura::client::CursorClient* cursor_client = |
| 3527 aura::client::GetCursorClient(window_->GetRootWindow()); | 3208 aura::client::GetCursorClient(window_->GetRootWindow()); |
| 3528 if (cursor_client) | 3209 if (cursor_client) |
| 3529 cursor_client->RemoveObserver(this); | 3210 cursor_client->RemoveObserver(this); |
| 3530 | 3211 |
| 3531 DetachFromInputMethod(); | 3212 DetachFromInputMethod(); |
| 3532 | 3213 |
| 3533 window_->GetDispatcher()->RemoveRootWindowObserver(this); | 3214 window_->GetDispatcher()->RemoveRootWindowObserver(this); |
| 3534 ui::Compositor* compositor = GetCompositor(); | |
| 3535 if (current_surface_.get()) { | |
| 3536 // We can't get notification for commits after this point, which would | |
| 3537 // guarantee that the compositor isn't using an old texture any more, so | |
| 3538 // instead we force the layer to stop using any external resources which | |
| 3539 // synchronizes with the compositor thread, and makes it safe to run the | |
| 3540 // callback. | |
| 3541 window_->layer()->SetShowPaintedContent(); | |
| 3542 } | |
| 3543 RunOnCommitCallbacks(); | 3215 RunOnCommitCallbacks(); |
| 3544 resize_lock_.reset(); | 3216 resize_lock_.reset(); |
| 3545 host_->WasResized(); | 3217 host_->WasResized(); |
| 3218 ui::Compositor* compositor = GetCompositor(); |
| 3546 if (compositor && compositor->HasObserver(this)) | 3219 if (compositor && compositor->HasObserver(this)) |
| 3547 compositor->RemoveObserver(this); | 3220 compositor->RemoveObserver(this); |
| 3548 | 3221 |
| 3549 #if defined(OS_WIN) | 3222 #if defined(OS_WIN) |
| 3550 // Update the legacy window's parent temporarily to the desktop window. It | 3223 // Update the legacy window's parent temporarily to the desktop window. It |
| 3551 // will eventually get reparented to the right root. | 3224 // will eventually get reparented to the right root. |
| 3552 if (legacy_render_widget_host_HWND_) | 3225 if (legacy_render_widget_host_HWND_) |
| 3553 legacy_render_widget_host_HWND_->UpdateParent(::GetDesktopWindow()); | 3226 legacy_render_widget_host_HWND_->UpdateParent(::GetDesktopWindow()); |
| 3554 #endif | 3227 #endif |
| 3555 } | 3228 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 3583 RenderWidgetHost* widget) { | 3256 RenderWidgetHost* widget) { |
| 3584 return new RenderWidgetHostViewAura(widget); | 3257 return new RenderWidgetHostViewAura(widget); |
| 3585 } | 3258 } |
| 3586 | 3259 |
| 3587 // static | 3260 // static |
| 3588 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { | 3261 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { |
| 3589 GetScreenInfoForWindow(results, NULL); | 3262 GetScreenInfoForWindow(results, NULL); |
| 3590 } | 3263 } |
| 3591 | 3264 |
| 3592 } // namespace content | 3265 } // namespace content |
| OLD | NEW |