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

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

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