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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 SkAutoLockPixels lock(bitmap); | 361 SkAutoLockPixels lock(bitmap); |
361 media::CopyRGBToVideoFrame( | 362 media::CopyRGBToVideoFrame( |
362 reinterpret_cast<const uint8*>(bitmap.getPixels()), | 363 reinterpret_cast<const uint8*>(bitmap.getPixels()), |
363 bitmap.rowBytes(), | 364 bitmap.rowBytes(), |
364 region_in_frame, | 365 region_in_frame, |
365 target.get()); | 366 target.get()); |
366 } | 367 } |
367 callback.Run(true); | 368 callback.Run(true); |
368 } | 369 } |
369 | 370 |
371 void ReleaseMailbox(MessageLoop *msg_loop, base::Callback<void()> callback, | |
piman
2013/05/28 20:58:57
The callback is always called on the UI thread. Th
slavi
2013/05/29 18:31:48
Done.
| |
372 unsigned sync_point, bool lost_resource) { | |
373 if (MessageLoop::current() == msg_loop) { | |
374 callback.Run(); | |
375 } else | |
376 msg_loop->PostTask(FROM_HERE, callback); | |
377 } | |
378 | |
370 } // namespace | 379 } // namespace |
371 | 380 |
372 // We need to watch for mouse events outside a Web Popup or its parent | 381 // We need to watch for mouse events outside a Web Popup or its parent |
373 // and dismiss the popup for certain events. | 382 // and dismiss the popup for certain events. |
374 class RenderWidgetHostViewAura::EventFilterForPopupExit : | 383 class RenderWidgetHostViewAura::EventFilterForPopupExit : |
375 public ui::EventHandler { | 384 public ui::EventHandler { |
376 public: | 385 public: |
377 explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva) | 386 explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva) |
378 : rwhva_(rwhva) { | 387 : rwhva_(rwhva) { |
379 DCHECK(rwhva_); | 388 DCHECK(rwhva_); |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
951 | 960 |
952 void RenderWidgetHostViewAura::Blur() { | 961 void RenderWidgetHostViewAura::Blur() { |
953 window_->Blur(); | 962 window_->Blur(); |
954 } | 963 } |
955 | 964 |
956 bool RenderWidgetHostViewAura::HasFocus() const { | 965 bool RenderWidgetHostViewAura::HasFocus() const { |
957 return window_->HasFocus(); | 966 return window_->HasFocus(); |
958 } | 967 } |
959 | 968 |
960 bool RenderWidgetHostViewAura::IsSurfaceAvailableForCopy() const { | 969 bool RenderWidgetHostViewAura::IsSurfaceAvailableForCopy() const { |
961 return current_surface_ || current_dib_ || !!host_->GetBackingStore(false); | 970 return current_surface_ || |
971 current_frame_.IsValid() || | |
972 !!host_->GetBackingStore(false); | |
962 } | 973 } |
963 | 974 |
964 void RenderWidgetHostViewAura::Show() { | 975 void RenderWidgetHostViewAura::Show() { |
965 window_->Show(); | 976 window_->Show(); |
966 } | 977 } |
967 | 978 |
968 void RenderWidgetHostViewAura::Hide() { | 979 void RenderWidgetHostViewAura::Hide() { |
969 window_->Hide(); | 980 window_->Hide(); |
970 } | 981 } |
971 | 982 |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1252 | 1263 |
1253 CopyFromCompositingSurfaceHelper(src_subrect, | 1264 CopyFromCompositingSurfaceHelper(src_subrect, |
1254 region_in_frame.size(), | 1265 region_in_frame.size(), |
1255 base::Bind(CopySnapshotToVideoFrame, | 1266 base::Bind(CopySnapshotToVideoFrame, |
1256 target, | 1267 target, |
1257 region_in_frame, | 1268 region_in_frame, |
1258 callback)); | 1269 callback)); |
1259 } | 1270 } |
1260 | 1271 |
1261 bool RenderWidgetHostViewAura::CanCopyToVideoFrame() const { | 1272 bool RenderWidgetHostViewAura::CanCopyToVideoFrame() const { |
1273 // TODO(skaslev): Implement this path for s/w compositing. | |
1262 return current_surface_ != NULL && host_->is_accelerated_compositing_active(); | 1274 return current_surface_ != NULL && host_->is_accelerated_compositing_active(); |
1263 } | 1275 } |
1264 | 1276 |
1265 bool RenderWidgetHostViewAura::CanSubscribeFrame() const { | 1277 bool RenderWidgetHostViewAura::CanSubscribeFrame() const { |
1266 return true; | 1278 return true; |
1267 } | 1279 } |
1268 | 1280 |
1269 void RenderWidgetHostViewAura::BeginFrameSubscription( | 1281 void RenderWidgetHostViewAura::BeginFrameSubscription( |
1270 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) { | 1282 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) { |
1271 frame_subscriber_ = subscriber.Pass(); | 1283 frame_subscriber_ = subscriber.Pass(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1314 | 1326 |
1315 void RenderWidgetHostViewAura::UpdateExternalTexture() { | 1327 void RenderWidgetHostViewAura::UpdateExternalTexture() { |
1316 // Delay processing accelerated compositing state change till here where we | 1328 // Delay processing accelerated compositing state change till here where we |
1317 // act upon the state change. (Clear the external texture if switching to | 1329 // act upon the state change. (Clear the external texture if switching to |
1318 // software mode or set the external texture if going to accelerated mode). | 1330 // software mode or set the external texture if going to accelerated mode). |
1319 if (accelerated_compositing_state_changed_) | 1331 if (accelerated_compositing_state_changed_) |
1320 accelerated_compositing_state_changed_ = false; | 1332 accelerated_compositing_state_changed_ = false; |
1321 | 1333 |
1322 bool is_compositing_active = host_->is_accelerated_compositing_active(); | 1334 bool is_compositing_active = host_->is_accelerated_compositing_active(); |
1323 if (is_compositing_active && current_surface_) { | 1335 if (is_compositing_active && current_surface_) { |
1324 window_->SetExternalTexture(current_surface_.get()); | 1336 window_->layer()->SetExternalTexture(current_surface_.get()); |
1325 current_frame_size_ = ConvertSizeToDIP( | 1337 current_frame_size_ = ConvertSizeToDIP( |
1326 current_surface_->device_scale_factor(), current_surface_->size()); | 1338 current_surface_->device_scale_factor(), current_surface_->size()); |
1327 CheckResizeLock(); | 1339 CheckResizeLock(); |
1328 } else if (is_compositing_active && current_dib_) { | 1340 } else if (is_compositing_active && current_frame_.IsSharedMemory()) { |
1329 window_->SetExternalTexture(NULL); | 1341 window_->layer()->SetTextureMailbox(current_frame_, |
1342 last_swapped_surface_scale_factor_); | |
1330 current_frame_size_ = ConvertSizeToDIP(last_swapped_surface_scale_factor_, | 1343 current_frame_size_ = ConvertSizeToDIP(last_swapped_surface_scale_factor_, |
1331 last_swapped_surface_size_); | 1344 current_frame_.size()); |
1332 CheckResizeLock(); | 1345 CheckResizeLock(); |
1333 } else { | 1346 } else { |
1334 window_->SetExternalTexture(NULL); | 1347 window_->layer()->SetExternalTexture(NULL); |
1335 resize_lock_.reset(); | 1348 resize_lock_.reset(); |
1336 host_->WasResized(); | 1349 host_->WasResized(); |
1337 } | 1350 } |
1338 } | 1351 } |
1339 | 1352 |
1340 bool RenderWidgetHostViewAura::SwapBuffersPrepare( | 1353 bool RenderWidgetHostViewAura::SwapBuffersPrepare( |
1341 const gfx::Rect& surface_rect, | 1354 const gfx::Rect& surface_rect, |
1342 float surface_scale_factor, | 1355 float surface_scale_factor, |
1343 const gfx::Rect& damage_rect, | 1356 const gfx::Rect& damage_rect, |
1344 const std::string& mailbox_name, | 1357 const std::string& mailbox_name, |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1482 void RenderWidgetHostViewAura::SendDelegatedFrameAck() { | 1495 void RenderWidgetHostViewAura::SendDelegatedFrameAck() { |
1483 cc::CompositorFrameAck ack; | 1496 cc::CompositorFrameAck ack; |
1484 window_->layer()->TakeUnusedResourcesForChildCompositor(&ack.resources); | 1497 window_->layer()->TakeUnusedResourcesForChildCompositor(&ack.resources); |
1485 RenderWidgetHostImpl::SendSwapCompositorFrameAck( | 1498 RenderWidgetHostImpl::SendSwapCompositorFrameAck( |
1486 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack); | 1499 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack); |
1487 } | 1500 } |
1488 | 1501 |
1489 void RenderWidgetHostViewAura::SwapSoftwareFrame( | 1502 void RenderWidgetHostViewAura::SwapSoftwareFrame( |
1490 scoped_ptr<cc::SoftwareFrameData> frame_data, | 1503 scoped_ptr<cc::SoftwareFrameData> frame_data, |
1491 float frame_device_scale_factor) { | 1504 float frame_device_scale_factor) { |
1505 ui::Compositor* compositor = GetCompositor(); | |
1506 if (!compositor) { | |
1507 SendSoftwareFrameAck(frame_data->id); | |
piman
2013/05/28 20:58:57
We still want to keep the new frame around.
The ca
slavi
2013/05/29 18:31:48
Done.
| |
1508 return; | |
1509 } | |
1510 | |
1492 const gfx::Size& frame_size = frame_data->size; | 1511 const gfx::Size& frame_size = frame_data->size; |
1493 const gfx::Rect& damage_rect = frame_data->damage_rect; | 1512 const gfx::Rect& damage_rect = frame_data->damage_rect; |
1494 const TransportDIB::Id& dib_id = frame_data->dib_id; | 1513 gfx::Size frame_size_in_dip = |
1495 scoped_ptr<TransportDIB> dib(host_->GetProcess()->MapTransportDIB(dib_id)); | 1514 ConvertSizeToDIP(frame_device_scale_factor, frame_size); |
1515 if (ShouldSkipFrame(frame_size_in_dip)) { | |
1516 SendSoftwareFrameAck(frame_data->id); | |
1517 return; | |
1518 } | |
1496 | 1519 |
1497 // Validate the received DIB. | 1520 base::SharedMemoryHandle handle = frame_data->handle; |
1498 size_t expected_size = 4 * frame_size.GetArea(); | 1521 #ifdef OS_WIN |
1499 if (!dib || dib->size() < expected_size) { | 1522 BOOL success = ::DuplicateHandle( |
piman
2013/05/28 20:58:57
We need to keep this test.
Without it, ResourcePro
slavi
2013/05/29 18:31:48
If the size is wrong (too big), SharedMemory::Map
| |
1523 host_->GetProcess()->GetHandle(), frame_data->handle, | |
1524 ::GetCurrentProcess(), &handle, | |
1525 0, TRUE, DUPLICATE_SAME_ACCESS); | |
1526 if (!success) { | |
1500 host_->GetProcess()->ReceivedBadMessage(); | 1527 host_->GetProcess()->ReceivedBadMessage(); |
1501 return; | 1528 return; |
1502 } | 1529 } |
1530 #endif | |
1503 | 1531 |
1504 if (last_swapped_surface_size_ != frame_size) { | 1532 if (last_swapped_surface_size_ != frame_size) { |
1505 DLOG_IF(ERROR, damage_rect != gfx::Rect(frame_size)) | 1533 DLOG_IF(ERROR, damage_rect != gfx::Rect(frame_size)) |
1506 << "Expected full damage rect"; | 1534 << "Expected full damage rect"; |
1507 } | 1535 } |
1508 | |
1509 TransportDIB::Id last_dib_id = current_dib_id_; | |
1510 current_dib_.reset(dib.release()); | |
1511 current_dib_id_ = dib_id; | |
1512 last_swapped_surface_size_ = frame_size; | 1536 last_swapped_surface_size_ = frame_size; |
1513 last_swapped_surface_scale_factor_ = frame_device_scale_factor; | 1537 last_swapped_surface_scale_factor_ = frame_device_scale_factor; |
1514 | 1538 |
1515 ui::Compositor* compositor = GetCompositor(); | 1539 cc::TextureMailbox::ReleaseCallback callback = |
1516 if (!compositor) { | 1540 base::Bind(ReleaseMailbox, MessageLoop::current(), |
1517 SendSoftwareFrameAck(last_dib_id); | 1541 base::Bind(&RenderWidgetHostViewAura::SendSoftwareFrameAck, |
1518 return; | 1542 AsWeakPtr(), |
1519 } | 1543 frame_data->id)); |
1544 current_frame_ = cc::TextureMailbox(handle, frame_size, callback); | |
1545 DCHECK(current_frame_.IsSharedMemory()); | |
1546 current_frame_size_ = frame_size_in_dip; | |
1520 | 1547 |
1521 gfx::Size frame_size_in_dip = | 1548 released_front_lock_ = NULL; |
1522 ConvertSizeToDIP(frame_device_scale_factor, frame_size); | |
1523 if (ShouldSkipFrame(frame_size_in_dip)) { | |
1524 can_lock_compositor_ = NO_PENDING_COMMIT; | |
1525 SendSoftwareFrameAck(last_dib_id); | |
1526 } else { | |
1527 AddOnCommitCallbackAndDisableLocks( | |
1528 base::Bind(&RenderWidgetHostViewAura::SendSoftwareFrameAck, | |
1529 AsWeakPtr(), last_dib_id)); | |
1530 } | |
1531 | |
1532 current_frame_size_ = frame_size_in_dip; | |
1533 CheckResizeLock(); | 1549 CheckResizeLock(); |
1534 released_front_lock_ = NULL; | 1550 window_->layer()->SetTextureMailbox(current_frame_, |
1535 window_->SetExternalTexture(NULL); | 1551 frame_device_scale_factor); |
1536 window_->SchedulePaintInRect( | 1552 window_->SchedulePaintInRect( |
1537 ConvertRectToDIP(frame_device_scale_factor, damage_rect)); | 1553 ConvertRectToDIP(frame_device_scale_factor, damage_rect)); |
1538 | |
1539 if (paint_observer_) | 1554 if (paint_observer_) |
1540 paint_observer_->OnUpdateCompositorContent(); | 1555 paint_observer_->OnUpdateCompositorContent(); |
1541 } | 1556 } |
1542 | 1557 |
1543 void RenderWidgetHostViewAura::SendSoftwareFrameAck( | 1558 void RenderWidgetHostViewAura::SendSoftwareFrameAck(int id) { |
1544 const TransportDIB::Id& id) { | |
1545 cc::CompositorFrameAck ack; | 1559 cc::CompositorFrameAck ack; |
1546 ack.last_dib_id = id; | 1560 ack.last_software_frame_id = id; |
1547 RenderWidgetHostImpl::SendSwapCompositorFrameAck( | 1561 RenderWidgetHostImpl::SendSwapCompositorFrameAck( |
1548 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack); | 1562 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack); |
1549 } | 1563 } |
1550 | 1564 |
1551 void RenderWidgetHostViewAura::OnSwapCompositorFrame( | 1565 void RenderWidgetHostViewAura::OnSwapCompositorFrame( |
1552 scoped_ptr<cc::CompositorFrame> frame) { | 1566 scoped_ptr<cc::CompositorFrame> frame) { |
1553 if (frame->delegated_frame_data) { | 1567 if (frame->delegated_frame_data) { |
1554 SwapDelegatedFrame(frame->delegated_frame_data.Pass(), | 1568 SwapDelegatedFrame(frame->delegated_frame_data.Pass(), |
1555 frame->metadata.device_scale_factor); | 1569 frame->metadata.device_scale_factor); |
1556 return; | 1570 return; |
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2142 return popup_type_ == WebKit::WebPopupTypeNone; | 2156 return popup_type_ == WebKit::WebPopupTypeNone; |
2143 } | 2157 } |
2144 | 2158 |
2145 void RenderWidgetHostViewAura::OnCaptureLost() { | 2159 void RenderWidgetHostViewAura::OnCaptureLost() { |
2146 host_->LostCapture(); | 2160 host_->LostCapture(); |
2147 if (touch_editing_client_) | 2161 if (touch_editing_client_) |
2148 touch_editing_client_->EndTouchEditing(); | 2162 touch_editing_client_->EndTouchEditing(); |
2149 } | 2163 } |
2150 | 2164 |
2151 void RenderWidgetHostViewAura::OnPaint(gfx::Canvas* canvas) { | 2165 void RenderWidgetHostViewAura::OnPaint(gfx::Canvas* canvas) { |
2152 bool is_compositing_active = host_->is_accelerated_compositing_active(); | |
2153 bool has_backing_store = !!host_->GetBackingStore(false); | 2166 bool has_backing_store = !!host_->GetBackingStore(false); |
2154 if (is_compositing_active && current_dib_) { | 2167 if (has_backing_store) { |
2155 const gfx::Size window_size = window_->bounds().size(); | |
2156 const gfx::Size& frame_size = last_swapped_surface_size_; | |
2157 | |
2158 SkBitmap bitmap; | |
2159 bitmap.setConfig(SkBitmap::kARGB_8888_Config, | |
2160 frame_size.width(), | |
2161 frame_size.height()); | |
2162 bitmap.setPixels(current_dib_->memory()); | |
2163 | |
2164 SkCanvas* sk_canvas = canvas->sk_canvas(); | |
2165 sk_canvas->drawBitmap(bitmap, 0, 0); | |
2166 | |
2167 if (frame_size != window_size) { | |
2168 SkRegion region; | |
2169 region.op(0, 0, window_size.width(), window_size.height(), | |
2170 SkRegion::kUnion_Op); | |
2171 region.op(0, 0, frame_size.width(), frame_size.height(), | |
2172 SkRegion::kDifference_Op); | |
2173 SkPaint paint; | |
2174 paint.setColor(SK_ColorWHITE); | |
2175 for (SkRegion::Iterator it(region); !it.done(); it.next()) | |
2176 sk_canvas->drawIRect(it.rect(), paint); | |
2177 } | |
2178 | |
2179 if (paint_observer_) | |
2180 paint_observer_->OnPaintComplete(); | |
2181 } else if (!is_compositing_active && has_backing_store) { | |
2182 paint_canvas_ = canvas; | 2168 paint_canvas_ = canvas; |
2183 BackingStoreAura* backing_store = static_cast<BackingStoreAura*>( | 2169 BackingStoreAura* backing_store = static_cast<BackingStoreAura*>( |
2184 host_->GetBackingStore(true)); | 2170 host_->GetBackingStore(true)); |
2185 paint_canvas_ = NULL; | 2171 paint_canvas_ = NULL; |
2186 backing_store->SkiaShowRect(gfx::Point(), canvas); | 2172 backing_store->SkiaShowRect(gfx::Point(), canvas); |
2187 | 2173 |
2188 if (paint_observer_) | 2174 if (paint_observer_) |
2189 paint_observer_->OnPaintComplete(); | 2175 paint_observer_->OnPaintComplete(); |
2190 } else if (aura::Env::GetInstance()->render_white_bg()) { | 2176 } else if (aura::Env::GetInstance()->render_white_bg()) { |
2191 canvas->DrawColor(SK_ColorWHITE); | 2177 canvas->DrawColor(SK_ColorWHITE); |
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2986 RenderWidgetHost* widget) { | 2972 RenderWidgetHost* widget) { |
2987 return new RenderWidgetHostViewAura(widget); | 2973 return new RenderWidgetHostViewAura(widget); |
2988 } | 2974 } |
2989 | 2975 |
2990 // static | 2976 // static |
2991 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { | 2977 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { |
2992 GetScreenInfoForWindow(results, NULL); | 2978 GetScreenInfoForWindow(results, NULL); |
2993 } | 2979 } |
2994 | 2980 |
2995 } // namespace content | 2981 } // namespace content |
OLD | NEW |