Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_aura.cc

Issue 15001027: [Aura] Added Support for rendering software compositor frames as cc::TextureLayers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed SharedMemory::DuplicateHandle. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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(scoped_ptr<base::SharedMemory> shared_memory,
349 base::Callback<void()> callback,
350 unsigned sync_point, bool lost_resource) {
351 callback.Run();
352 shared_memory.reset(NULL);
piman 2013/06/07 01:26:28 nit: you actually don't need this, it'll go away b
slavi 2013/06/07 21:49:21 I knew that. I thought leaving it makes the code c
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
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
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
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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1513 cc::CompositorFrameAck ack; 1527 cc::CompositorFrameAck ack;
1514 window_->layer()->TakeUnusedResourcesForChildCompositor(&ack.resources); 1528 window_->layer()->TakeUnusedResourcesForChildCompositor(&ack.resources);
1515 RenderWidgetHostImpl::SendSwapCompositorFrameAck( 1529 RenderWidgetHostImpl::SendSwapCompositorFrameAck(
1516 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack); 1530 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack);
1517 } 1531 }
1518 1532
1519 void RenderWidgetHostViewAura::SwapSoftwareFrame( 1533 void RenderWidgetHostViewAura::SwapSoftwareFrame(
1520 scoped_ptr<cc::SoftwareFrameData> frame_data, 1534 scoped_ptr<cc::SoftwareFrameData> frame_data,
1521 float frame_device_scale_factor, 1535 float frame_device_scale_factor,
1522 const ui::LatencyInfo& latency_info) { 1536 const ui::LatencyInfo& latency_info) {
1537 ui::Compositor* compositor = GetCompositor();
1538 if (!compositor) {
piman 2013/06/07 01:26:28 I believe I mentioned that earlier. GetCompositor
slavi 2013/06/07 21:49:21 Done.
1539 SendSoftwareFrameAck(frame_data->id);
1540 return;
1541 }
1542
1523 const gfx::Size& frame_size = frame_data->size; 1543 const gfx::Size& frame_size = frame_data->size;
1524 const gfx::Rect& damage_rect = frame_data->damage_rect; 1544 const gfx::Rect& damage_rect = frame_data->damage_rect;
1525 const TransportDIB::Id& dib_id = frame_data->dib_id; 1545 gfx::Size frame_size_in_dip =
1526 scoped_ptr<TransportDIB> dib(host_->GetProcess()->MapTransportDIB(dib_id)); 1546 ConvertSizeToDIP(frame_device_scale_factor, frame_size);
1547 if (ShouldSkipFrame(frame_size_in_dip)) {
1548 SendSoftwareFrameAck(frame_data->id);
1549 return;
1550 }
1527 1551
1528 // Validate the received DIB. 1552 base::SharedMemoryHandle handle = frame_data->handle;
1529 size_t expected_size = 4 * frame_size.GetArea(); 1553 #ifdef OS_WIN
1530 if (!dib || dib->size() < expected_size) { 1554 BOOL success = ::DuplicateHandle(
1555 host_->GetProcess()->GetHandle(), frame_data->handle,
1556 ::GetCurrentProcess(), &handle,
1557 0, TRUE, DUPLICATE_SAME_ACCESS);
1558 if (!success) {
1559 host_->GetProcess()->ReceivedBadMessage();
1560 return;
1561 }
1562 #endif
1563 const size_t expected_size = 4 * frame_size.GetArea();
1564 scoped_ptr<base::SharedMemory> shared_memory(
1565 new base::SharedMemory(handle, false));
1566 if (!shared_memory->Map(expected_size)) {
1531 host_->GetProcess()->ReceivedBadMessage(); 1567 host_->GetProcess()->ReceivedBadMessage();
1532 return; 1568 return;
1533 } 1569 }
1534 1570
1535 if (last_swapped_surface_size_ != frame_size) { 1571 if (last_swapped_surface_size_ != frame_size) {
1536 DLOG_IF(ERROR, damage_rect != gfx::Rect(frame_size)) 1572 DLOG_IF(ERROR, damage_rect != gfx::Rect(frame_size))
1537 << "Expected full damage rect"; 1573 << "Expected full damage rect";
1538 } 1574 }
1539
1540 TransportDIB::Id last_dib_id = current_dib_id_;
1541 current_dib_.reset(dib.release());
1542 current_dib_id_ = dib_id;
1543 last_swapped_surface_size_ = frame_size; 1575 last_swapped_surface_size_ = frame_size;
1544 last_swapped_surface_scale_factor_ = frame_device_scale_factor; 1576 last_swapped_surface_scale_factor_ = frame_device_scale_factor;
1545 1577
1546 ui::Compositor* compositor = GetCompositor(); 1578 base::SharedMemory* shared_memory_raw_ptr = shared_memory.get();
1547 if (!compositor) { 1579 cc::TextureMailbox::ReleaseCallback callback =
1548 SendSoftwareFrameAck(last_dib_id); 1580 base::Bind(ReleaseMailbox, Passed(shared_memory.Pass()),
piman 2013/06/07 01:26:28 nit: Passed(shared_memory) should work.
slavi 2013/06/07 21:49:21 It doesn't.
piman 2013/06/07 23:29:59 ok, Passed(&shared_memory).
1549 return; 1581 base::Bind(&RenderWidgetHostViewAura::SendSoftwareFrameAck,
1550 } 1582 AsWeakPtr(), frame_data->id));
1583 current_software_frame_ =
1584 cc::TextureMailbox(shared_memory_raw_ptr, frame_size, callback);
1585 DCHECK(current_software_frame_.IsSharedMemory());
1586 current_frame_size_ = frame_size_in_dip;
1551 1587
1552 gfx::Size frame_size_in_dip = 1588 released_front_lock_ = NULL;
1553 ConvertSizeToDIP(frame_device_scale_factor, frame_size);
1554 if (ShouldSkipFrame(frame_size_in_dip)) {
1555 can_lock_compositor_ = NO_PENDING_COMMIT;
1556 SendSoftwareFrameAck(last_dib_id);
1557 } else {
1558 AddOnCommitCallbackAndDisableLocks(
1559 base::Bind(&RenderWidgetHostViewAura::SendSoftwareFrameAck,
1560 AsWeakPtr(), last_dib_id));
1561 }
1562
1563 current_frame_size_ = frame_size_in_dip;
1564 CheckResizeLock(); 1589 CheckResizeLock();
1565 released_front_lock_ = NULL; 1590 window_->layer()->SetTextureMailbox(current_software_frame_,
1566 window_->SetExternalTexture(NULL); 1591 frame_device_scale_factor);
1567 window_->SchedulePaintInRect( 1592 window_->SchedulePaintInRect(
1568 ConvertRectToDIP(frame_device_scale_factor, damage_rect)); 1593 ConvertRectToDIP(frame_device_scale_factor, damage_rect));
1594
1569 compositor->SetLatencyInfo(latency_info); 1595 compositor->SetLatencyInfo(latency_info);
1570
1571 if (paint_observer_) 1596 if (paint_observer_)
1572 paint_observer_->OnUpdateCompositorContent(); 1597 paint_observer_->OnUpdateCompositorContent();
1573 } 1598 }
1574 1599
1575 void RenderWidgetHostViewAura::SendSoftwareFrameAck( 1600 void RenderWidgetHostViewAura::SendSoftwareFrameAck(
1576 const TransportDIB::Id& id) { 1601 unsigned software_frame_id) {
1577 cc::CompositorFrameAck ack; 1602 cc::CompositorFrameAck ack;
1578 ack.last_dib_id = id; 1603 ack.last_software_frame_id = software_frame_id;
1579 RenderWidgetHostImpl::SendSwapCompositorFrameAck( 1604 RenderWidgetHostImpl::SendSwapCompositorFrameAck(
1580 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack); 1605 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack);
1581 } 1606 }
1582 1607
1583 void RenderWidgetHostViewAura::OnSwapCompositorFrame( 1608 void RenderWidgetHostViewAura::OnSwapCompositorFrame(
1584 scoped_ptr<cc::CompositorFrame> frame) { 1609 scoped_ptr<cc::CompositorFrame> frame) {
1585 if (frame->delegated_frame_data) { 1610 if (frame->delegated_frame_data) {
1586 SwapDelegatedFrame(frame->delegated_frame_data.Pass(), 1611 SwapDelegatedFrame(frame->delegated_frame_data.Pass(),
1587 frame->metadata.device_scale_factor, 1612 frame->metadata.device_scale_factor,
1588 frame->metadata.latency_info); 1613 frame->metadata.latency_info);
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
2185 return popup_type_ == WebKit::WebPopupTypeNone; 2210 return popup_type_ == WebKit::WebPopupTypeNone;
2186 } 2211 }
2187 2212
2188 void RenderWidgetHostViewAura::OnCaptureLost() { 2213 void RenderWidgetHostViewAura::OnCaptureLost() {
2189 host_->LostCapture(); 2214 host_->LostCapture();
2190 if (touch_editing_client_) 2215 if (touch_editing_client_)
2191 touch_editing_client_->EndTouchEditing(); 2216 touch_editing_client_->EndTouchEditing();
2192 } 2217 }
2193 2218
2194 void RenderWidgetHostViewAura::OnPaint(gfx::Canvas* canvas) { 2219 void RenderWidgetHostViewAura::OnPaint(gfx::Canvas* canvas) {
2195 bool is_compositing_active = host_->is_accelerated_compositing_active();
2196 bool has_backing_store = !!host_->GetBackingStore(false); 2220 bool has_backing_store = !!host_->GetBackingStore(false);
2197 if (is_compositing_active && current_dib_) { 2221 if (has_backing_store) {
2198 const gfx::Size window_size = window_->bounds().size();
2199 const gfx::Size& frame_size = last_swapped_surface_size_;
2200
2201 SkBitmap bitmap;
2202 bitmap.setConfig(SkBitmap::kARGB_8888_Config,
2203 frame_size.width(),
2204 frame_size.height());
2205 bitmap.setPixels(current_dib_->memory());
2206
2207 SkCanvas* sk_canvas = canvas->sk_canvas();
2208 sk_canvas->drawBitmap(bitmap, 0, 0);
2209
2210 if (frame_size != window_size) {
2211 SkRegion region;
2212 region.op(0, 0, window_size.width(), window_size.height(),
2213 SkRegion::kUnion_Op);
2214 region.op(0, 0, frame_size.width(), frame_size.height(),
2215 SkRegion::kDifference_Op);
2216 SkPaint paint;
2217 paint.setColor(SK_ColorWHITE);
2218 for (SkRegion::Iterator it(region); !it.done(); it.next())
2219 sk_canvas->drawIRect(it.rect(), paint);
2220 }
2221
2222 if (paint_observer_)
2223 paint_observer_->OnPaintComplete();
2224 } else if (!is_compositing_active && has_backing_store) {
2225 paint_canvas_ = canvas; 2222 paint_canvas_ = canvas;
2226 BackingStoreAura* backing_store = static_cast<BackingStoreAura*>( 2223 BackingStoreAura* backing_store = static_cast<BackingStoreAura*>(
2227 host_->GetBackingStore(true)); 2224 host_->GetBackingStore(true));
2228 paint_canvas_ = NULL; 2225 paint_canvas_ = NULL;
2229 backing_store->SkiaShowRect(gfx::Point(), canvas); 2226 backing_store->SkiaShowRect(gfx::Point(), canvas);
2230 2227
2231 if (paint_observer_) 2228 if (paint_observer_)
2232 paint_observer_->OnPaintComplete(); 2229 paint_observer_->OnPaintComplete();
2233 } else if (aura::Env::GetInstance()->render_white_bg()) { 2230 } else if (aura::Env::GetInstance()->render_white_bg()) {
2234 canvas->DrawColor(SK_ColorWHITE); 2231 canvas->DrawColor(SK_ColorWHITE);
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
3029 RenderWidgetHost* widget) { 3026 RenderWidgetHost* widget) {
3030 return new RenderWidgetHostViewAura(widget); 3027 return new RenderWidgetHostViewAura(widget);
3031 } 3028 }
3032 3029
3033 // static 3030 // static
3034 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { 3031 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) {
3035 GetScreenInfoForWindow(results, NULL); 3032 GetScreenInfoForWindow(results, NULL);
3036 } 3033 }
3037 3034
3038 } // namespace content 3035 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698