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

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: Passed(&foo) instead for Passed(foo.Pass()). 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 }
353
347 } // namespace 354 } // namespace
348 355
349 // We need to watch for mouse events outside a Web Popup or its parent 356 // We need to watch for mouse events outside a Web Popup or its parent
350 // and dismiss the popup for certain events. 357 // and dismiss the popup for certain events.
351 class RenderWidgetHostViewAura::EventFilterForPopupExit : 358 class RenderWidgetHostViewAura::EventFilterForPopupExit :
352 public ui::EventHandler { 359 public ui::EventHandler {
353 public: 360 public:
354 explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva) 361 explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva)
355 : rwhva_(rwhva) { 362 : rwhva_(rwhva) {
356 DCHECK(rwhva_); 363 DCHECK(rwhva_);
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 941
935 void RenderWidgetHostViewAura::Blur() { 942 void RenderWidgetHostViewAura::Blur() {
936 window_->Blur(); 943 window_->Blur();
937 } 944 }
938 945
939 bool RenderWidgetHostViewAura::HasFocus() const { 946 bool RenderWidgetHostViewAura::HasFocus() const {
940 return window_->HasFocus(); 947 return window_->HasFocus();
941 } 948 }
942 949
943 bool RenderWidgetHostViewAura::IsSurfaceAvailableForCopy() const { 950 bool RenderWidgetHostViewAura::IsSurfaceAvailableForCopy() const {
944 return current_surface_ || current_dib_ || !!host_->GetBackingStore(false); 951 return current_surface_ ||
952 current_software_frame_.IsValid() ||
953 !!host_->GetBackingStore(false);
945 } 954 }
946 955
947 void RenderWidgetHostViewAura::Show() { 956 void RenderWidgetHostViewAura::Show() {
948 window_->Show(); 957 window_->Show();
949 } 958 }
950 959
951 void RenderWidgetHostViewAura::Hide() { 960 void RenderWidgetHostViewAura::Hide() {
952 window_->Hide(); 961 window_->Hide();
953 } 962 }
954 963
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
1278 } 1287 }
1279 1288
1280 scoped_callback_runner.Release(); 1289 scoped_callback_runner.Release();
1281 yuv_readback_pipeline_->ReadbackYUV( 1290 yuv_readback_pipeline_->ReadbackYUV(
1282 current_surface_->PrepareTexture(), 1291 current_surface_->PrepareTexture(),
1283 target, 1292 target,
1284 callback); 1293 callback);
1285 } 1294 }
1286 1295
1287 bool RenderWidgetHostViewAura::CanCopyToVideoFrame() const { 1296 bool RenderWidgetHostViewAura::CanCopyToVideoFrame() const {
1297 // TODO(skaslev): Implement this path for s/w compositing.
1288 return current_surface_ != NULL && host_->is_accelerated_compositing_active(); 1298 return current_surface_ != NULL && host_->is_accelerated_compositing_active();
1289 } 1299 }
1290 1300
1291 bool RenderWidgetHostViewAura::CanSubscribeFrame() const { 1301 bool RenderWidgetHostViewAura::CanSubscribeFrame() const {
1292 return true; 1302 return true;
1293 } 1303 }
1294 1304
1295 void RenderWidgetHostViewAura::BeginFrameSubscription( 1305 void RenderWidgetHostViewAura::BeginFrameSubscription(
1296 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) { 1306 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) {
1297 frame_subscriber_ = subscriber.Pass(); 1307 frame_subscriber_ = subscriber.Pass();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1340 1350
1341 void RenderWidgetHostViewAura::UpdateExternalTexture() { 1351 void RenderWidgetHostViewAura::UpdateExternalTexture() {
1342 // Delay processing accelerated compositing state change till here where we 1352 // Delay processing accelerated compositing state change till here where we
1343 // act upon the state change. (Clear the external texture if switching to 1353 // 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). 1354 // software mode or set the external texture if going to accelerated mode).
1345 if (accelerated_compositing_state_changed_) 1355 if (accelerated_compositing_state_changed_)
1346 accelerated_compositing_state_changed_ = false; 1356 accelerated_compositing_state_changed_ = false;
1347 1357
1348 bool is_compositing_active = host_->is_accelerated_compositing_active(); 1358 bool is_compositing_active = host_->is_accelerated_compositing_active();
1349 if (is_compositing_active && current_surface_) { 1359 if (is_compositing_active && current_surface_) {
1350 window_->SetExternalTexture(current_surface_.get()); 1360 window_->layer()->SetExternalTexture(current_surface_.get());
1351 current_frame_size_ = ConvertSizeToDIP( 1361 current_frame_size_ = ConvertSizeToDIP(
1352 current_surface_->device_scale_factor(), current_surface_->size()); 1362 current_surface_->device_scale_factor(), current_surface_->size());
1353 CheckResizeLock(); 1363 CheckResizeLock();
1354 } else if (is_compositing_active && current_dib_) { 1364 } else if (is_compositing_active &&
1355 window_->SetExternalTexture(NULL); 1365 current_software_frame_.IsSharedMemory()) {
1356 current_frame_size_ = ConvertSizeToDIP(last_swapped_surface_scale_factor_, 1366 window_->layer()->SetTextureMailbox(current_software_frame_,
1357 last_swapped_surface_size_); 1367 last_swapped_surface_scale_factor_);
1368 current_frame_size_ = ConvertSizeToDIP(
1369 last_swapped_surface_scale_factor_,
1370 current_software_frame_.shared_memory_size());
1358 CheckResizeLock(); 1371 CheckResizeLock();
1359 } else { 1372 } else {
1360 window_->SetExternalTexture(NULL); 1373 window_->layer()->SetExternalTexture(NULL);
1361 resize_lock_.reset(); 1374 resize_lock_.reset();
1362 host_->WasResized(); 1375 host_->WasResized();
1363 } 1376 }
1364 } 1377 }
1365 1378
1366 bool RenderWidgetHostViewAura::SwapBuffersPrepare( 1379 bool RenderWidgetHostViewAura::SwapBuffersPrepare(
1367 const gfx::Rect& surface_rect, 1380 const gfx::Rect& surface_rect,
1368 float surface_scale_factor, 1381 float surface_scale_factor,
1369 const gfx::Rect& damage_rect, 1382 const gfx::Rect& damage_rect,
1370 const std::string& mailbox_name, 1383 const std::string& mailbox_name,
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 RenderWidgetHostImpl::SendSwapCompositorFrameAck( 1528 RenderWidgetHostImpl::SendSwapCompositorFrameAck(
1516 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack); 1529 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack);
1517 } 1530 }
1518 1531
1519 void RenderWidgetHostViewAura::SwapSoftwareFrame( 1532 void RenderWidgetHostViewAura::SwapSoftwareFrame(
1520 scoped_ptr<cc::SoftwareFrameData> frame_data, 1533 scoped_ptr<cc::SoftwareFrameData> frame_data,
1521 float frame_device_scale_factor, 1534 float frame_device_scale_factor,
1522 const ui::LatencyInfo& latency_info) { 1535 const ui::LatencyInfo& latency_info) {
1523 const gfx::Size& frame_size = frame_data->size; 1536 const gfx::Size& frame_size = frame_data->size;
1524 const gfx::Rect& damage_rect = frame_data->damage_rect; 1537 const gfx::Rect& damage_rect = frame_data->damage_rect;
1525 const TransportDIB::Id& dib_id = frame_data->dib_id; 1538 gfx::Size frame_size_in_dip =
1526 scoped_ptr<TransportDIB> dib(host_->GetProcess()->MapTransportDIB(dib_id)); 1539 ConvertSizeToDIP(frame_device_scale_factor, frame_size);
1540 if (ShouldSkipFrame(frame_size_in_dip)) {
1541 SendSoftwareFrameAck(frame_data->id);
1542 return;
1543 }
1527 1544
1528 // Validate the received DIB. 1545 base::SharedMemoryHandle handle = frame_data->handle;
1529 size_t expected_size = 4 * frame_size.GetArea(); 1546 #ifdef OS_WIN
1530 if (!dib || dib->size() < expected_size) { 1547 BOOL success = ::DuplicateHandle(
1548 host_->GetProcess()->GetHandle(), frame_data->handle,
1549 ::GetCurrentProcess(), &handle,
1550 0, TRUE, DUPLICATE_SAME_ACCESS);
1551 if (!success) {
1552 host_->GetProcess()->ReceivedBadMessage();
1553 return;
1554 }
1555 #endif
1556 const size_t expected_size = 4 * frame_size.GetArea();
1557 scoped_ptr<base::SharedMemory> shared_memory(
1558 new base::SharedMemory(handle, false));
1559 if (!shared_memory->Map(expected_size)) {
1531 host_->GetProcess()->ReceivedBadMessage(); 1560 host_->GetProcess()->ReceivedBadMessage();
1532 return; 1561 return;
1533 } 1562 }
1534 1563
1535 if (last_swapped_surface_size_ != frame_size) { 1564 if (last_swapped_surface_size_ != frame_size) {
1536 DLOG_IF(ERROR, damage_rect != gfx::Rect(frame_size)) 1565 DLOG_IF(ERROR, damage_rect != gfx::Rect(frame_size))
1537 << "Expected full damage rect"; 1566 << "Expected full damage rect";
1538 } 1567 }
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; 1568 last_swapped_surface_size_ = frame_size;
1544 last_swapped_surface_scale_factor_ = frame_device_scale_factor; 1569 last_swapped_surface_scale_factor_ = frame_device_scale_factor;
1545 1570
1546 ui::Compositor* compositor = GetCompositor(); 1571 base::SharedMemory* shared_memory_raw_ptr = shared_memory.get();
1547 if (!compositor) { 1572 cc::TextureMailbox::ReleaseCallback callback =
1548 SendSoftwareFrameAck(last_dib_id); 1573 base::Bind(ReleaseMailbox, Passed(&shared_memory),
1549 return; 1574 base::Bind(&RenderWidgetHostViewAura::SendSoftwareFrameAck,
1550 } 1575 AsWeakPtr(), frame_data->id));
1576 current_software_frame_ =
1577 cc::TextureMailbox(shared_memory_raw_ptr, frame_size, callback);
1578 DCHECK(current_software_frame_.IsSharedMemory());
1579 current_frame_size_ = frame_size_in_dip;
1551 1580
1552 gfx::Size frame_size_in_dip = 1581 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(); 1582 CheckResizeLock();
1565 released_front_lock_ = NULL; 1583 window_->layer()->SetTextureMailbox(current_software_frame_,
1566 window_->SetExternalTexture(NULL); 1584 frame_device_scale_factor);
1567 window_->SchedulePaintInRect( 1585 window_->SchedulePaintInRect(
1568 ConvertRectToDIP(frame_device_scale_factor, damage_rect)); 1586 ConvertRectToDIP(frame_device_scale_factor, damage_rect));
1569 compositor->SetLatencyInfo(latency_info);
1570 1587
1588 ui::Compositor* compositor = GetCompositor();
1589 if (compositor)
1590 compositor->SetLatencyInfo(latency_info);
1571 if (paint_observer_) 1591 if (paint_observer_)
1572 paint_observer_->OnUpdateCompositorContent(); 1592 paint_observer_->OnUpdateCompositorContent();
1573 } 1593 }
1574 1594
1575 void RenderWidgetHostViewAura::SendSoftwareFrameAck( 1595 void RenderWidgetHostViewAura::SendSoftwareFrameAck(
1576 const TransportDIB::Id& id) { 1596 unsigned software_frame_id) {
1577 cc::CompositorFrameAck ack; 1597 cc::CompositorFrameAck ack;
1578 ack.last_dib_id = id; 1598 ack.last_software_frame_id = software_frame_id;
1579 RenderWidgetHostImpl::SendSwapCompositorFrameAck( 1599 RenderWidgetHostImpl::SendSwapCompositorFrameAck(
1580 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack); 1600 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack);
1581 } 1601 }
1582 1602
1583 void RenderWidgetHostViewAura::OnSwapCompositorFrame( 1603 void RenderWidgetHostViewAura::OnSwapCompositorFrame(
1584 scoped_ptr<cc::CompositorFrame> frame) { 1604 scoped_ptr<cc::CompositorFrame> frame) {
1585 if (frame->delegated_frame_data) { 1605 if (frame->delegated_frame_data) {
1586 SwapDelegatedFrame(frame->delegated_frame_data.Pass(), 1606 SwapDelegatedFrame(frame->delegated_frame_data.Pass(),
1587 frame->metadata.device_scale_factor, 1607 frame->metadata.device_scale_factor,
1588 frame->metadata.latency_info); 1608 frame->metadata.latency_info);
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
2185 return popup_type_ == WebKit::WebPopupTypeNone; 2205 return popup_type_ == WebKit::WebPopupTypeNone;
2186 } 2206 }
2187 2207
2188 void RenderWidgetHostViewAura::OnCaptureLost() { 2208 void RenderWidgetHostViewAura::OnCaptureLost() {
2189 host_->LostCapture(); 2209 host_->LostCapture();
2190 if (touch_editing_client_) 2210 if (touch_editing_client_)
2191 touch_editing_client_->EndTouchEditing(); 2211 touch_editing_client_->EndTouchEditing();
2192 } 2212 }
2193 2213
2194 void RenderWidgetHostViewAura::OnPaint(gfx::Canvas* canvas) { 2214 void RenderWidgetHostViewAura::OnPaint(gfx::Canvas* canvas) {
2195 bool is_compositing_active = host_->is_accelerated_compositing_active();
2196 bool has_backing_store = !!host_->GetBackingStore(false); 2215 bool has_backing_store = !!host_->GetBackingStore(false);
2197 if (is_compositing_active && current_dib_) { 2216 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; 2217 paint_canvas_ = canvas;
2226 BackingStoreAura* backing_store = static_cast<BackingStoreAura*>( 2218 BackingStoreAura* backing_store = static_cast<BackingStoreAura*>(
2227 host_->GetBackingStore(true)); 2219 host_->GetBackingStore(true));
2228 paint_canvas_ = NULL; 2220 paint_canvas_ = NULL;
2229 backing_store->SkiaShowRect(gfx::Point(), canvas); 2221 backing_store->SkiaShowRect(gfx::Point(), canvas);
2230 2222
2231 if (paint_observer_) 2223 if (paint_observer_)
2232 paint_observer_->OnPaintComplete(); 2224 paint_observer_->OnPaintComplete();
2233 } else if (aura::Env::GetInstance()->render_white_bg()) { 2225 } else if (aura::Env::GetInstance()->render_white_bg()) {
2234 canvas->DrawColor(SK_ColorWHITE); 2226 canvas->DrawColor(SK_ColorWHITE);
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
3037 RenderWidgetHost* widget) { 3029 RenderWidgetHost* widget) {
3038 return new RenderWidgetHostViewAura(widget); 3030 return new RenderWidgetHostViewAura(widget);
3039 } 3031 }
3040 3032
3041 // static 3033 // static
3042 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { 3034 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) {
3043 GetScreenInfoForWindow(results, NULL); 3035 GetScreenInfoForWindow(results, NULL);
3044 } 3036 }
3045 3037
3046 } // namespace content 3038 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_aura.h ('k') | content/common/cc_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698