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

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

Issue 10411086: Makes the browser send pixels to the GPU process where it should (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.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 "content/browser/renderer_host/backing_store_skia.h" 14 #include "content/browser/renderer_host/backing_store_skia.h"
15 #include "content/browser/renderer_host/dip_util.h"
15 #include "content/browser/renderer_host/image_transport_client.h" 16 #include "content/browser/renderer_host/image_transport_client.h"
16 #include "content/browser/renderer_host/render_widget_host_impl.h" 17 #include "content/browser/renderer_host/render_widget_host_impl.h"
17 #include "content/browser/renderer_host/web_input_event_aura.h" 18 #include "content/browser/renderer_host/web_input_event_aura.h"
18 #include "content/common/gpu/client/gl_helper.h" 19 #include "content/common/gpu/client/gl_helper.h"
19 #include "content/common/gpu/gpu_messages.h" 20 #include "content/common/gpu/gpu_messages.h"
20 #include "content/port/browser/render_widget_host_view_port.h" 21 #include "content/port/browser/render_widget_host_view_port.h"
21 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
22 #include "content/public/common/content_switches.h" 23 #include "content/public/common/content_switches.h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli ne.h" 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli ne.h"
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 } 263 }
263 264
264 void RenderWidgetHostViewAura::InitAsFullscreen( 265 void RenderWidgetHostViewAura::InitAsFullscreen(
265 RenderWidgetHostView* reference_host_view) { 266 RenderWidgetHostView* reference_host_view) {
266 is_fullscreen_ = true; 267 is_fullscreen_ = true;
267 window_->SetType(aura::client::WINDOW_TYPE_NORMAL); 268 window_->SetType(aura::client::WINDOW_TYPE_NORMAL);
268 window_->Init(ui::LAYER_TEXTURED); 269 window_->Init(ui::LAYER_TEXTURED);
269 window_->SetName("RenderWidgetHostViewAura"); 270 window_->SetName("RenderWidgetHostViewAura");
270 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); 271 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
271 window_->SetParent(NULL); 272 window_->SetParent(NULL);
272 // Don't scale the canvas on high density screen because 273 // Don't scale the contents on high density screen because
273 // the renderer takes care of it. 274 // the renderer takes care of it.
274 window_->layer()->set_scale_canvas(false); 275 window_->layer()->set_scale_content(false);
275 Show(); 276 Show();
276 Focus(); 277 Focus();
277 } 278 }
278 279
279 RenderWidgetHost* RenderWidgetHostViewAura::GetRenderWidgetHost() const { 280 RenderWidgetHost* RenderWidgetHostViewAura::GetRenderWidgetHost() const {
280 return host_; 281 return host_;
281 } 282 }
282 283
283 void RenderWidgetHostViewAura::DidBecomeSelected() { 284 void RenderWidgetHostViewAura::DidBecomeSelected() {
284 host_->WasRestored(); 285 host_->WasRestored();
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 base::Callback<void(bool)> callback) { 446 base::Callback<void(bool)> callback) {
446 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false)); 447 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false));
447 ui::Compositor* compositor = GetCompositor(); 448 ui::Compositor* compositor = GetCompositor();
448 if (!compositor) 449 if (!compositor)
449 return; 450 return;
450 451
451 ImageTransportClient* container = image_transport_clients_[current_surface_]; 452 ImageTransportClient* container = image_transport_clients_[current_surface_];
452 if (!container) 453 if (!container)
453 return; 454 return;
454 455
455 if (!output->initialize(size.width(), size.height(), true)) 456 gfx::Size size_in_pixel = content::ConvertSizeToPixel(this, size);
457 if (!output->initialize(
458 size_in_pixel.width(), size_in_pixel.height(), true))
456 return; 459 return;
457 460
458 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 461 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
459 content::GLHelper* gl_helper = factory->GetGLHelper(compositor); 462 content::GLHelper* gl_helper = factory->GetGLHelper(compositor);
460 if (!gl_helper) 463 if (!gl_helper)
461 return; 464 return;
462 465
463 unsigned char* addr = static_cast<unsigned char*>( 466 unsigned char* addr = static_cast<unsigned char*>(
464 output->getTopDevice()->accessBitmap(true).getPixels()); 467 output->getTopDevice()->accessBitmap(true).getPixels());
465 scoped_callback_runner.Release(); 468 scoped_callback_runner.Release();
466 gl_helper->CopyTextureTo(container->texture_id(), 469 gl_helper->CopyTextureTo(container->texture_id(),
467 container->size(), 470 container->size(),
468 size, 471 size_in_pixel,
469 addr, 472 addr,
470 callback); 473 callback);
471 } 474 }
472 475
473 void RenderWidgetHostViewAura::OnAcceleratedCompositingStateChange() { 476 void RenderWidgetHostViewAura::OnAcceleratedCompositingStateChange() {
474 // Delay UpdateExternalTexture until we actually got a software frame. 477 // Delay UpdateExternalTexture until we actually got a software frame.
475 // Sometimes (e.g. on a page load) the renderer will spuriously disable then 478 // Sometimes (e.g. on a page load) the renderer will spuriously disable then
476 // re-enable accelerated compositing, causing us to flash. 479 // re-enable accelerated compositing, causing us to flash.
477 // TODO(piman): factor the enable/disable accelerated compositing message into 480 // TODO(piman): factor the enable/disable accelerated compositing message into
478 // the UpdateRect/AcceleratedSurfaceBuffersSwapped messages so that we have 481 // the UpdateRect/AcceleratedSurfaceBuffersSwapped messages so that we have
479 // fewer inconsistent temporary states. 482 // fewer inconsistent temporary states.
480 needs_update_texture_ = true; 483 needs_update_texture_ = true;
484
485 // Don't scale contents on high density screen when content is accelerated
486 // because renderer takes care of it.
487 // TODO(pkotwicz): Implement DIP backing store such that renderer always
488 // scales web contents.
489 window_->layer()->set_scale_content(
490 !host_->is_accelerated_compositing_active());
481 } 491 }
482 492
483 void RenderWidgetHostViewAura::UpdateExternalTexture() { 493 void RenderWidgetHostViewAura::UpdateExternalTexture() {
484 needs_update_texture_ = false; 494 needs_update_texture_ = false;
485 if (current_surface_ != 0 && 495 if (current_surface_ != 0 &&
486 host_->is_accelerated_compositing_active()) { 496 host_->is_accelerated_compositing_active()) {
487 497
488 ImageTransportClient* container = 498 ImageTransportClient* container =
489 image_transport_clients_[current_surface_]; 499 image_transport_clients_[current_surface_];
490 if (container) 500 if (container)
491 container->Update(); 501 container->Update();
492 window_->SetExternalTexture(container); 502 window_->SetExternalTexture(container);
493 503
494 if (!container) { 504 if (!container) {
495 resize_locks_.clear(); 505 resize_locks_.clear();
496 } else { 506 } else {
497 typedef std::vector<linked_ptr<ResizeLock> > ResizeLockList; 507 typedef std::vector<linked_ptr<ResizeLock> > ResizeLockList;
498 ResizeLockList::iterator it = resize_locks_.begin(); 508 ResizeLockList::iterator it = resize_locks_.begin();
499 while (it != resize_locks_.end()) { 509 while (it != resize_locks_.end()) {
500 if ((*it)->expected_size() == container->size()) 510 gfx::Size container_size = content::ConvertSizeToDIP(this,
511 container->size());
512 if ((*it)->expected_size() == container_size)
501 break; 513 break;
502 ++it; 514 ++it;
503 } 515 }
504 if (it != resize_locks_.end()) { 516 if (it != resize_locks_.end()) {
505 ++it; 517 ++it;
506 ui::Compositor* compositor = GetCompositor(); 518 ui::Compositor* compositor = GetCompositor();
507 if (compositor) { 519 if (compositor) {
508 // Delay the release of the lock until we've kicked a frame with the 520 // Delay the release of the lock until we've kicked a frame with the
509 // new texture, to avoid resizing the UI before we have a chance to 521 // new texture, to avoid resizing the UI before we have a chance to
510 // draw a "good" frame. 522 // draw a "good" frame.
(...skipping 11 matching lines...) Expand all
522 resize_locks_.erase(resize_locks_.begin(), it); 534 resize_locks_.erase(resize_locks_.begin(), it);
523 } 535 }
524 } 536 }
525 } else { 537 } else {
526 window_->SetExternalTexture(NULL); 538 window_->SetExternalTexture(NULL);
527 resize_locks_.clear(); 539 resize_locks_.clear();
528 } 540 }
529 } 541 }
530 542
531 void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped( 543 void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped(
532 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, 544 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel,
533 int gpu_host_id) { 545 int gpu_host_id) {
534 current_surface_ = params.surface_handle; 546 current_surface_ = params_in_pixel.surface_handle;
535 UpdateExternalTexture(); 547 UpdateExternalTexture();
536 548
537 ui::Compositor* compositor = GetCompositor(); 549 ui::Compositor* compositor = GetCompositor();
538 if (!compositor) { 550 if (!compositor) {
539 // We have no compositor, so we have no way to display the surface. 551 // We have no compositor, so we have no way to display the surface.
540 // Must still send the ACK. 552 // Must still send the ACK.
541 RenderWidgetHostImpl::AcknowledgeSwapBuffers(params.route_id, gpu_host_id); 553 RenderWidgetHostImpl::AcknowledgeSwapBuffers(params_in_pixel.route_id,
554 gpu_host_id);
542 } else { 555 } else {
543 gfx::Size surface_size = 556 gfx::Size surface_size_in_pixel =
544 image_transport_clients_[params.surface_handle]->size(); 557 image_transport_clients_[params_in_pixel.surface_handle]->size();
558 gfx::Size surface_size = content::ConvertSizeToDIP(this,
559 surface_size_in_pixel);
545 window_->SchedulePaintInRect(gfx::Rect(surface_size)); 560 window_->SchedulePaintInRect(gfx::Rect(surface_size));
546 561
547 if (!resize_locks_.empty() && !compositor->DrawPending()) { 562 if (!resize_locks_.empty() && !compositor->DrawPending()) {
548 // If we are waiting for the resize, fast-track the ACK. 563 // If we are waiting for the resize, fast-track the ACK.
549 // However only do so if we're not between the Draw() and the 564 // However only do so if we're not between the Draw() and the
550 // OnCompositingEnded(), because out-of-order execution in the GPU process 565 // OnCompositingEnded(), because out-of-order execution in the GPU process
551 // might corrupt the "front buffer" for the currently issued frame. 566 // might corrupt the "front buffer" for the currently issued frame.
552 RenderWidgetHostImpl::AcknowledgeSwapBuffers( 567 RenderWidgetHostImpl::AcknowledgeSwapBuffers(
553 params.route_id, gpu_host_id); 568 params_in_pixel.route_id, gpu_host_id);
554 } else { 569 } else {
555 // Add sending an ACK to the list of things to do OnCompositingEnded 570 // Add sending an ACK to the list of things to do OnCompositingEnded
556 on_compositing_ended_callbacks_.push_back( 571 on_compositing_ended_callbacks_.push_back(
557 base::Bind(&RenderWidgetHostImpl::AcknowledgeSwapBuffers, 572 base::Bind(&RenderWidgetHostImpl::AcknowledgeSwapBuffers,
558 params.route_id, gpu_host_id)); 573 params_in_pixel.route_id, gpu_host_id));
559 if (!compositor->HasObserver(this)) 574 if (!compositor->HasObserver(this))
560 compositor->AddObserver(this); 575 compositor->AddObserver(this);
561 } 576 }
562 } 577 }
563 } 578 }
564 579
565 void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer( 580 void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer(
566 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, 581 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel,
567 int gpu_host_id) { 582 int gpu_host_id) {
568 current_surface_ = params.surface_handle; 583 current_surface_ = params_in_pixel.surface_handle;
569 UpdateExternalTexture(); 584 UpdateExternalTexture();
570 585
571 ui::Compositor* compositor = GetCompositor(); 586 ui::Compositor* compositor = GetCompositor();
572 if (!compositor) { 587 if (!compositor) {
573 // We have no compositor, so we have no way to display the surface 588 // We have no compositor, so we have no way to display the surface
574 // Must still send the ACK 589 // Must still send the ACK
575 RenderWidgetHostImpl::AcknowledgePostSubBuffer( 590 RenderWidgetHostImpl::AcknowledgePostSubBuffer(
576 params.route_id, gpu_host_id); 591 params_in_pixel.route_id, gpu_host_id);
577 } else { 592 } else {
578 gfx::Size surface_size = 593 gfx::Size surface_size_in_pixel =
579 image_transport_clients_[params.surface_handle]->size(); 594 image_transport_clients_[params_in_pixel.surface_handle]->size();
580 595
581 // Co-ordinates come in OpenGL co-ordinate space. 596 // Co-ordinates come in OpenGL co-ordinate space.
582 // We need to convert to layer space. 597 // We need to convert to layer space.
583 window_->SchedulePaintInRect(gfx::Rect( 598 gfx::Rect rect_to_paint = content::ConvertRectToDIP(this, gfx::Rect(
584 params.x, 599 params_in_pixel.x,
585 surface_size.height() - params.y - params.height, 600 surface_size_in_pixel.height() - params_in_pixel.y -
586 params.width, 601 params_in_pixel.height,
587 params.height)); 602 params_in_pixel.width,
603 params_in_pixel.height));
604 window_->SchedulePaintInRect(rect_to_paint);
588 605
589 if (!resize_locks_.empty() && !compositor->DrawPending()) { 606 if (!resize_locks_.empty() && !compositor->DrawPending()) {
590 // If we are waiting for the resize, fast-track the ACK. 607 // If we are waiting for the resize, fast-track the ACK.
591 // However only do so if we're not between the Draw() and the 608 // However only do so if we're not between the Draw() and the
592 // OnCompositingEnded(), because out-of-order execution in the GPU process 609 // OnCompositingEnded(), because out-of-order execution in the GPU process
593 // might corrupt the "front buffer" for the currently issued frame. 610 // might corrupt the "front buffer" for the currently issued frame.
594 RenderWidgetHostImpl::AcknowledgePostSubBuffer( 611 RenderWidgetHostImpl::AcknowledgePostSubBuffer(
595 params.route_id, gpu_host_id); 612 params_in_pixel.route_id, gpu_host_id);
596 } else { 613 } else {
597 // Add sending an ACK to the list of things to do OnCompositingEnded 614 // Add sending an ACK to the list of things to do OnCompositingEnded
598 on_compositing_ended_callbacks_.push_back( 615 on_compositing_ended_callbacks_.push_back(
599 base::Bind(&RenderWidgetHostImpl::AcknowledgePostSubBuffer, 616 base::Bind(&RenderWidgetHostImpl::AcknowledgePostSubBuffer,
600 params.route_id, gpu_host_id)); 617 params_in_pixel.route_id, gpu_host_id));
601 if (!compositor->HasObserver(this)) 618 if (!compositor->HasObserver(this))
602 compositor->AddObserver(this); 619 compositor->AddObserver(this);
603 } 620 }
604 } 621 }
605 } 622 }
606 623
607 void RenderWidgetHostViewAura::AcceleratedSurfaceSuspend() { 624 void RenderWidgetHostViewAura::AcceleratedSurfaceSuspend() {
608 } 625 }
609 626
610 bool RenderWidgetHostViewAura::HasAcceleratedSurface( 627 bool RenderWidgetHostViewAura::HasAcceleratedSurface(
611 const gfx::Size& desired_size) { 628 const gfx::Size& desired_size) {
612 // Aura doesn't use GetBackingStore for accelerated pages, so it doesn't 629 // Aura doesn't use GetBackingStore for accelerated pages, so it doesn't
613 // matter what is returned here as GetBackingStore is the only caller of this 630 // matter what is returned here as GetBackingStore is the only caller of this
614 // method. TODO(jbates) implement this if other Aura code needs it. 631 // method. TODO(jbates) implement this if other Aura code needs it.
615 return false; 632 return false;
616 } 633 }
617 634
618 void RenderWidgetHostViewAura::AcceleratedSurfaceNew( 635 void RenderWidgetHostViewAura::AcceleratedSurfaceNew(
619 int32 width, 636 int32 width_in_pixel,
620 int32 height, 637 int32 height_in_pixel,
621 uint64* surface_handle, 638 uint64* surface_handle,
622 TransportDIB::Handle* shm_handle) { 639 TransportDIB::Handle* shm_handle) {
623 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 640 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
624 scoped_refptr<ImageTransportClient> surface(factory->CreateTransportClient( 641 scoped_refptr<ImageTransportClient> surface(factory->CreateTransportClient(
625 gfx::Size(width, height), surface_handle)); 642 gfx::Size(width_in_pixel, height_in_pixel), surface_handle));
626 if (!surface) { 643 if (!surface) {
627 LOG(ERROR) << "Failed to create ImageTransportClient"; 644 LOG(ERROR) << "Failed to create ImageTransportClient";
628 return; 645 return;
629 } 646 }
630 *shm_handle = surface->Handle(); 647 *shm_handle = surface->Handle();
631 648
632 image_transport_clients_[*surface_handle] = surface; 649 image_transport_clients_[*surface_handle] = surface;
633 } 650 }
634 651
635 void RenderWidgetHostViewAura::AcceleratedSurfaceRelease( 652 void RenderWidgetHostViewAura::AcceleratedSurfaceRelease(
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( 1327 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget(
1311 RenderWidgetHost* widget) { 1328 RenderWidgetHost* widget) {
1312 return new RenderWidgetHostViewAura(widget); 1329 return new RenderWidgetHostViewAura(widget);
1313 } 1330 }
1314 1331
1315 // static 1332 // static
1316 void content::RenderWidgetHostViewPort::GetDefaultScreenInfo( 1333 void content::RenderWidgetHostViewPort::GetDefaultScreenInfo(
1317 WebKit::WebScreenInfo* results) { 1334 WebKit::WebScreenInfo* results) {
1318 GetScreenInfoForWindow(results, NULL); 1335 GetScreenInfoForWindow(results, NULL);
1319 } 1336 }
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_aura.h ('k') | content/browser/web_contents/web_contents_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698