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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
14 #include "cc/output/compositor_frame.h" | 14 #include "cc/output/compositor_frame.h" |
15 #include "cc/output/compositor_frame_ack.h" | 15 #include "cc/output/compositor_frame_ack.h" |
16 #include "cc/resources/texture_mailbox.h" | |
16 #include "content/browser/accessibility/browser_accessibility_manager.h" | 17 #include "content/browser/accessibility/browser_accessibility_manager.h" |
17 #include "content/browser/accessibility/browser_accessibility_state_impl.h" | 18 #include "content/browser/accessibility/browser_accessibility_state_impl.h" |
18 #include "content/browser/renderer_host/backing_store_aura.h" | 19 #include "content/browser/renderer_host/backing_store_aura.h" |
19 #include "content/browser/renderer_host/dip_util.h" | 20 #include "content/browser/renderer_host/dip_util.h" |
20 #include "content/browser/renderer_host/overscroll_controller.h" | 21 #include "content/browser/renderer_host/overscroll_controller.h" |
21 #include "content/browser/renderer_host/render_view_host_delegate.h" | 22 #include "content/browser/renderer_host/render_view_host_delegate.h" |
22 #include "content/browser/renderer_host/render_widget_host_impl.h" | 23 #include "content/browser/renderer_host/render_widget_host_impl.h" |
23 #include "content/browser/renderer_host/touch_smooth_scroll_gesture_aura.h" | 24 #include "content/browser/renderer_host/touch_smooth_scroll_gesture_aura.h" |
24 #include "content/browser/renderer_host/ui_events_helper.h" | 25 #include "content/browser/renderer_host/ui_events_helper.h" |
25 #include "content/browser/renderer_host/web_input_event_aura.h" | 26 #include "content/browser/renderer_host/web_input_event_aura.h" |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
337 } else if (skip_frame) { | 338 } else if (skip_frame) { |
338 ack.mailbox_name = received_mailbox; | 339 ack.mailbox_name = received_mailbox; |
339 ack.sync_point = 0; | 340 ack.sync_point = 0; |
340 } | 341 } |
341 | 342 |
342 ack.sync_point = sync_point; | 343 ack.sync_point = sync_point; |
343 RenderWidgetHostImpl::AcknowledgeBufferPresent( | 344 RenderWidgetHostImpl::AcknowledgeBufferPresent( |
344 route_id, gpu_host_id, ack); | 345 route_id, gpu_host_id, ack); |
345 } | 346 } |
346 | 347 |
348 void ReleaseMailbox(base::SharedMemory* shared_memory, | |
349 base::Callback<void()> callback, | |
350 unsigned sync_point, bool lost_resource) { | |
351 delete shared_memory; | |
352 callback.Run(); | |
353 } | |
354 | |
347 } // namespace | 355 } // namespace |
348 | 356 |
349 // We need to watch for mouse events outside a Web Popup or its parent | 357 // We need to watch for mouse events outside a Web Popup or its parent |
350 // and dismiss the popup for certain events. | 358 // and dismiss the popup for certain events. |
351 class RenderWidgetHostViewAura::EventFilterForPopupExit : | 359 class RenderWidgetHostViewAura::EventFilterForPopupExit : |
352 public ui::EventHandler { | 360 public ui::EventHandler { |
353 public: | 361 public: |
354 explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva) | 362 explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva) |
355 : rwhva_(rwhva) { | 363 : rwhva_(rwhva) { |
356 DCHECK(rwhva_); | 364 DCHECK(rwhva_); |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
934 | 942 |
935 void RenderWidgetHostViewAura::Blur() { | 943 void RenderWidgetHostViewAura::Blur() { |
936 window_->Blur(); | 944 window_->Blur(); |
937 } | 945 } |
938 | 946 |
939 bool RenderWidgetHostViewAura::HasFocus() const { | 947 bool RenderWidgetHostViewAura::HasFocus() const { |
940 return window_->HasFocus(); | 948 return window_->HasFocus(); |
941 } | 949 } |
942 | 950 |
943 bool RenderWidgetHostViewAura::IsSurfaceAvailableForCopy() const { | 951 bool RenderWidgetHostViewAura::IsSurfaceAvailableForCopy() const { |
944 return current_surface_ || current_dib_ || !!host_->GetBackingStore(false); | 952 return current_surface_ || |
953 current_software_frame_.IsValid() || | |
954 !!host_->GetBackingStore(false); | |
945 } | 955 } |
946 | 956 |
947 void RenderWidgetHostViewAura::Show() { | 957 void RenderWidgetHostViewAura::Show() { |
948 window_->Show(); | 958 window_->Show(); |
949 } | 959 } |
950 | 960 |
951 void RenderWidgetHostViewAura::Hide() { | 961 void RenderWidgetHostViewAura::Hide() { |
952 window_->Hide(); | 962 window_->Hide(); |
953 } | 963 } |
954 | 964 |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1278 } | 1288 } |
1279 | 1289 |
1280 scoped_callback_runner.Release(); | 1290 scoped_callback_runner.Release(); |
1281 yuv_readback_pipeline_->ReadbackYUV( | 1291 yuv_readback_pipeline_->ReadbackYUV( |
1282 current_surface_->PrepareTexture(), | 1292 current_surface_->PrepareTexture(), |
1283 target, | 1293 target, |
1284 callback); | 1294 callback); |
1285 } | 1295 } |
1286 | 1296 |
1287 bool RenderWidgetHostViewAura::CanCopyToVideoFrame() const { | 1297 bool RenderWidgetHostViewAura::CanCopyToVideoFrame() const { |
1298 // TODO(skaslev): Implement this path for s/w compositing. | |
1288 return current_surface_ != NULL && host_->is_accelerated_compositing_active(); | 1299 return current_surface_ != NULL && host_->is_accelerated_compositing_active(); |
1289 } | 1300 } |
1290 | 1301 |
1291 bool RenderWidgetHostViewAura::CanSubscribeFrame() const { | 1302 bool RenderWidgetHostViewAura::CanSubscribeFrame() const { |
1292 return true; | 1303 return true; |
1293 } | 1304 } |
1294 | 1305 |
1295 void RenderWidgetHostViewAura::BeginFrameSubscription( | 1306 void RenderWidgetHostViewAura::BeginFrameSubscription( |
1296 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) { | 1307 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) { |
1297 frame_subscriber_ = subscriber.Pass(); | 1308 frame_subscriber_ = subscriber.Pass(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1340 | 1351 |
1341 void RenderWidgetHostViewAura::UpdateExternalTexture() { | 1352 void RenderWidgetHostViewAura::UpdateExternalTexture() { |
1342 // Delay processing accelerated compositing state change till here where we | 1353 // Delay processing accelerated compositing state change till here where we |
1343 // act upon the state change. (Clear the external texture if switching to | 1354 // act upon the state change. (Clear the external texture if switching to |
1344 // software mode or set the external texture if going to accelerated mode). | 1355 // software mode or set the external texture if going to accelerated mode). |
1345 if (accelerated_compositing_state_changed_) | 1356 if (accelerated_compositing_state_changed_) |
1346 accelerated_compositing_state_changed_ = false; | 1357 accelerated_compositing_state_changed_ = false; |
1347 | 1358 |
1348 bool is_compositing_active = host_->is_accelerated_compositing_active(); | 1359 bool is_compositing_active = host_->is_accelerated_compositing_active(); |
1349 if (is_compositing_active && current_surface_) { | 1360 if (is_compositing_active && current_surface_) { |
1350 window_->SetExternalTexture(current_surface_.get()); | 1361 window_->layer()->SetExternalTexture(current_surface_.get()); |
1351 current_frame_size_ = ConvertSizeToDIP( | 1362 current_frame_size_ = ConvertSizeToDIP( |
1352 current_surface_->device_scale_factor(), current_surface_->size()); | 1363 current_surface_->device_scale_factor(), current_surface_->size()); |
1353 CheckResizeLock(); | 1364 CheckResizeLock(); |
1354 } else if (is_compositing_active && current_dib_) { | 1365 } else if (is_compositing_active && |
1355 window_->SetExternalTexture(NULL); | 1366 current_software_frame_.IsSharedMemory()) { |
1356 current_frame_size_ = ConvertSizeToDIP(last_swapped_surface_scale_factor_, | 1367 window_->layer()->SetTextureMailbox(current_software_frame_, |
1357 last_swapped_surface_size_); | 1368 last_swapped_surface_scale_factor_); |
1369 current_frame_size_ = ConvertSizeToDIP( | |
1370 last_swapped_surface_scale_factor_, | |
1371 current_software_frame_.shared_memory_size()); | |
1358 CheckResizeLock(); | 1372 CheckResizeLock(); |
1359 } else { | 1373 } else { |
1360 window_->SetExternalTexture(NULL); | 1374 window_->layer()->SetExternalTexture(NULL); |
1361 resize_lock_.reset(); | 1375 resize_lock_.reset(); |
1362 host_->WasResized(); | 1376 host_->WasResized(); |
1363 } | 1377 } |
1364 } | 1378 } |
1365 | 1379 |
1366 bool RenderWidgetHostViewAura::SwapBuffersPrepare( | 1380 bool RenderWidgetHostViewAura::SwapBuffersPrepare( |
1367 const gfx::Rect& surface_rect, | 1381 const gfx::Rect& surface_rect, |
1368 float surface_scale_factor, | 1382 float surface_scale_factor, |
1369 const gfx::Rect& damage_rect, | 1383 const gfx::Rect& damage_rect, |
1370 const std::string& mailbox_name, | 1384 const std::string& mailbox_name, |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1508 void RenderWidgetHostViewAura::SendDelegatedFrameAck() { | 1522 void RenderWidgetHostViewAura::SendDelegatedFrameAck() { |
1509 cc::CompositorFrameAck ack; | 1523 cc::CompositorFrameAck ack; |
1510 window_->layer()->TakeUnusedResourcesForChildCompositor(&ack.resources); | 1524 window_->layer()->TakeUnusedResourcesForChildCompositor(&ack.resources); |
1511 RenderWidgetHostImpl::SendSwapCompositorFrameAck( | 1525 RenderWidgetHostImpl::SendSwapCompositorFrameAck( |
1512 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack); | 1526 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack); |
1513 } | 1527 } |
1514 | 1528 |
1515 void RenderWidgetHostViewAura::SwapSoftwareFrame( | 1529 void RenderWidgetHostViewAura::SwapSoftwareFrame( |
1516 scoped_ptr<cc::SoftwareFrameData> frame_data, | 1530 scoped_ptr<cc::SoftwareFrameData> frame_data, |
1517 float frame_device_scale_factor) { | 1531 float frame_device_scale_factor) { |
1532 base::SharedMemoryHandle handle = frame_data->handle; | |
1533 #ifdef OS_WIN | |
1534 BOOL success = ::DuplicateHandle( | |
1535 host_->GetProcess()->GetHandle(), frame_data->handle, | |
1536 ::GetCurrentProcess(), &handle, | |
1537 0, TRUE, DUPLICATE_SAME_ACCESS); | |
1538 if (!success) { | |
1539 host_->GetProcess()->ReceivedBadMessage(); | |
1540 return; | |
1541 } | |
1542 #endif | |
1543 scoped_ptr<base::SharedMemory> shared_memory( | |
1544 new base::SharedMemory(handle, false)); | |
1545 | |
1518 const gfx::Size& frame_size = frame_data->size; | 1546 const gfx::Size& frame_size = frame_data->size; |
1519 const gfx::Rect& damage_rect = frame_data->damage_rect; | 1547 const gfx::Rect& damage_rect = frame_data->damage_rect; |
1520 const TransportDIB::Id& dib_id = frame_data->dib_id; | 1548 gfx::Size frame_size_in_dip = |
1521 scoped_ptr<TransportDIB> dib(host_->GetProcess()->MapTransportDIB(dib_id)); | 1549 ConvertSizeToDIP(frame_device_scale_factor, frame_size); |
1522 | 1550 if (ShouldSkipFrame(frame_size_in_dip)) { |
1523 // Validate the received DIB. | 1551 SendSoftwareFrameAck(frame_data->id); |
1524 size_t expected_size = 4 * frame_size.GetArea(); | |
1525 if (!dib || dib->size() < expected_size) { | |
1526 host_->GetProcess()->ReceivedBadMessage(); | |
1527 return; | 1552 return; |
1528 } | 1553 } |
1529 | 1554 |
1530 if (last_swapped_surface_size_ != frame_size) { | 1555 if (last_swapped_surface_size_ != frame_size) { |
1531 DLOG_IF(ERROR, damage_rect != gfx::Rect(frame_size)) | 1556 DLOG_IF(ERROR, damage_rect != gfx::Rect(frame_size)) |
1532 << "Expected full damage rect"; | 1557 << "Expected full damage rect"; |
1533 } | 1558 } |
1534 | |
1535 TransportDIB::Id last_dib_id = current_dib_id_; | |
1536 current_dib_.reset(dib.release()); | |
1537 current_dib_id_ = dib_id; | |
1538 last_swapped_surface_size_ = frame_size; | 1559 last_swapped_surface_size_ = frame_size; |
1539 last_swapped_surface_scale_factor_ = frame_device_scale_factor; | 1560 last_swapped_surface_scale_factor_ = frame_device_scale_factor; |
1540 | 1561 |
1541 ui::Compositor* compositor = GetCompositor(); | 1562 cc::TextureMailbox::ReleaseCallback callback = |
1542 if (!compositor) { | 1563 base::Bind(ReleaseMailbox, shared_memory.release(), |
piman
2013/06/05 00:30:55
nit: you can use Passed(new_buffer), and make Rele
slavi
2013/06/06 23:02:47
Done.
| |
1543 SendSoftwareFrameAck(last_dib_id); | 1564 base::Bind(&RenderWidgetHostViewAura::SendSoftwareFrameAck, |
1544 return; | 1565 AsWeakPtr(), frame_data->id)); |
1545 } | 1566 current_software_frame_ = cc::TextureMailbox(handle, frame_size, callback); |
1567 DCHECK(current_software_frame_.IsSharedMemory()); | |
1568 current_frame_size_ = frame_size_in_dip; | |
1546 | 1569 |
1547 gfx::Size frame_size_in_dip = | 1570 released_front_lock_ = NULL; |
1548 ConvertSizeToDIP(frame_device_scale_factor, frame_size); | |
1549 if (ShouldSkipFrame(frame_size_in_dip)) { | |
1550 can_lock_compositor_ = NO_PENDING_COMMIT; | |
1551 SendSoftwareFrameAck(last_dib_id); | |
1552 } else { | |
1553 AddOnCommitCallbackAndDisableLocks( | |
1554 base::Bind(&RenderWidgetHostViewAura::SendSoftwareFrameAck, | |
1555 AsWeakPtr(), last_dib_id)); | |
1556 } | |
1557 | |
1558 current_frame_size_ = frame_size_in_dip; | |
1559 CheckResizeLock(); | 1571 CheckResizeLock(); |
1560 released_front_lock_ = NULL; | 1572 window_->layer()->SetTextureMailbox(current_software_frame_, |
1561 window_->SetExternalTexture(NULL); | 1573 frame_device_scale_factor); |
1562 window_->SchedulePaintInRect( | 1574 window_->SchedulePaintInRect( |
1563 ConvertRectToDIP(frame_device_scale_factor, damage_rect)); | 1575 ConvertRectToDIP(frame_device_scale_factor, damage_rect)); |
1564 | |
1565 if (paint_observer_) | 1576 if (paint_observer_) |
1566 paint_observer_->OnUpdateCompositorContent(); | 1577 paint_observer_->OnUpdateCompositorContent(); |
1567 } | 1578 } |
1568 | 1579 |
1569 void RenderWidgetHostViewAura::SendSoftwareFrameAck( | 1580 void RenderWidgetHostViewAura::SendSoftwareFrameAck(int software_frame_id) { |
1570 const TransportDIB::Id& id) { | |
1571 cc::CompositorFrameAck ack; | 1581 cc::CompositorFrameAck ack; |
1572 ack.last_dib_id = id; | 1582 ack.last_software_frame_id = software_frame_id; |
1573 RenderWidgetHostImpl::SendSwapCompositorFrameAck( | 1583 RenderWidgetHostImpl::SendSwapCompositorFrameAck( |
1574 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack); | 1584 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack); |
1575 } | 1585 } |
1576 | 1586 |
1577 void RenderWidgetHostViewAura::OnSwapCompositorFrame( | 1587 void RenderWidgetHostViewAura::OnSwapCompositorFrame( |
1578 scoped_ptr<cc::CompositorFrame> frame) { | 1588 scoped_ptr<cc::CompositorFrame> frame) { |
1579 if (frame->delegated_frame_data) { | 1589 if (frame->delegated_frame_data) { |
1580 SwapDelegatedFrame(frame->delegated_frame_data.Pass(), | 1590 SwapDelegatedFrame(frame->delegated_frame_data.Pass(), |
1581 frame->metadata.device_scale_factor); | 1591 frame->metadata.device_scale_factor); |
1582 return; | 1592 return; |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2172 return popup_type_ == WebKit::WebPopupTypeNone; | 2182 return popup_type_ == WebKit::WebPopupTypeNone; |
2173 } | 2183 } |
2174 | 2184 |
2175 void RenderWidgetHostViewAura::OnCaptureLost() { | 2185 void RenderWidgetHostViewAura::OnCaptureLost() { |
2176 host_->LostCapture(); | 2186 host_->LostCapture(); |
2177 if (touch_editing_client_) | 2187 if (touch_editing_client_) |
2178 touch_editing_client_->EndTouchEditing(); | 2188 touch_editing_client_->EndTouchEditing(); |
2179 } | 2189 } |
2180 | 2190 |
2181 void RenderWidgetHostViewAura::OnPaint(gfx::Canvas* canvas) { | 2191 void RenderWidgetHostViewAura::OnPaint(gfx::Canvas* canvas) { |
2182 bool is_compositing_active = host_->is_accelerated_compositing_active(); | |
2183 bool has_backing_store = !!host_->GetBackingStore(false); | 2192 bool has_backing_store = !!host_->GetBackingStore(false); |
2184 if (is_compositing_active && current_dib_) { | 2193 if (has_backing_store) { |
2185 const gfx::Size window_size = window_->bounds().size(); | |
2186 const gfx::Size& frame_size = last_swapped_surface_size_; | |
2187 | |
2188 SkBitmap bitmap; | |
2189 bitmap.setConfig(SkBitmap::kARGB_8888_Config, | |
2190 frame_size.width(), | |
2191 frame_size.height()); | |
2192 bitmap.setPixels(current_dib_->memory()); | |
2193 | |
2194 SkCanvas* sk_canvas = canvas->sk_canvas(); | |
2195 sk_canvas->drawBitmap(bitmap, 0, 0); | |
2196 | |
2197 if (frame_size != window_size) { | |
2198 SkRegion region; | |
2199 region.op(0, 0, window_size.width(), window_size.height(), | |
2200 SkRegion::kUnion_Op); | |
2201 region.op(0, 0, frame_size.width(), frame_size.height(), | |
2202 SkRegion::kDifference_Op); | |
2203 SkPaint paint; | |
2204 paint.setColor(SK_ColorWHITE); | |
2205 for (SkRegion::Iterator it(region); !it.done(); it.next()) | |
2206 sk_canvas->drawIRect(it.rect(), paint); | |
2207 } | |
2208 | |
2209 if (paint_observer_) | |
2210 paint_observer_->OnPaintComplete(); | |
2211 } else if (!is_compositing_active && has_backing_store) { | |
2212 paint_canvas_ = canvas; | 2194 paint_canvas_ = canvas; |
2213 BackingStoreAura* backing_store = static_cast<BackingStoreAura*>( | 2195 BackingStoreAura* backing_store = static_cast<BackingStoreAura*>( |
2214 host_->GetBackingStore(true)); | 2196 host_->GetBackingStore(true)); |
2215 paint_canvas_ = NULL; | 2197 paint_canvas_ = NULL; |
2216 backing_store->SkiaShowRect(gfx::Point(), canvas); | 2198 backing_store->SkiaShowRect(gfx::Point(), canvas); |
2217 | 2199 |
2218 if (paint_observer_) | 2200 if (paint_observer_) |
2219 paint_observer_->OnPaintComplete(); | 2201 paint_observer_->OnPaintComplete(); |
2220 } else if (aura::Env::GetInstance()->render_white_bg()) { | 2202 } else if (aura::Env::GetInstance()->render_white_bg()) { |
2221 canvas->DrawColor(SK_ColorWHITE); | 2203 canvas->DrawColor(SK_ColorWHITE); |
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3016 RenderWidgetHost* widget) { | 2998 RenderWidgetHost* widget) { |
3017 return new RenderWidgetHostViewAura(widget); | 2999 return new RenderWidgetHostViewAura(widget); |
3018 } | 3000 } |
3019 | 3001 |
3020 // static | 3002 // static |
3021 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { | 3003 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { |
3022 GetScreenInfoForWindow(results, NULL); | 3004 GetScreenInfoForWindow(results, NULL); |
3023 } | 3005 } |
3024 | 3006 |
3025 } // namespace content | 3007 } // namespace content |
OLD | NEW |