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

Side by Side Diff: chrome/renderer/render_widget.cc

Issue 3834003: On Windows, create a new TransportDIB::Handle struct which includes the file (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Rebase Created 10 years, 2 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/renderer/render_widget.h" 5 #include "chrome/renderer/render_widget.h"
6 6
7 #include "app/surface/transport_dib.h" 7 #include "app/surface/transport_dib.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 // invalidation. Some WebCore rendering objects only layout when painted. 501 // invalidation. Some WebCore rendering objects only layout when painted.
502 PaintAggregator::PendingUpdate update = paint_aggregator_.GetPendingUpdate(); 502 PaintAggregator::PendingUpdate update = paint_aggregator_.GetPendingUpdate();
503 paint_aggregator_.ClearPendingUpdate(); 503 paint_aggregator_.ClearPendingUpdate();
504 504
505 gfx::Rect scroll_damage = update.GetScrollDamage(); 505 gfx::Rect scroll_damage = update.GetScrollDamage();
506 gfx::Rect bounds = update.GetPaintBounds().Union(scroll_damage); 506 gfx::Rect bounds = update.GetPaintBounds().Union(scroll_damage);
507 507
508 // A plugin may be able to do an optimized paint. First check this, in which 508 // A plugin may be able to do an optimized paint. First check this, in which
509 // case we can skip all of the bitmap generation and regular paint code. 509 // case we can skip all of the bitmap generation and regular paint code.
510 TransportDIB::Id dib_id = TransportDIB::Id(); 510 TransportDIB::Id dib_id = TransportDIB::Id();
511 TransportDIB::Handle dib_handle = TransportDIB::DefaultHandleValue();
511 TransportDIB* dib = NULL; 512 TransportDIB* dib = NULL;
512 std::vector<gfx::Rect> copy_rects; 513 std::vector<gfx::Rect> copy_rects;
513 gfx::Rect optimized_copy_rect, optimized_copy_location; 514 gfx::Rect optimized_copy_rect, optimized_copy_location;
514 if (update.scroll_rect.IsEmpty() && 515 if (update.scroll_rect.IsEmpty() &&
515 !is_gpu_rendering_active_ && 516 !is_gpu_rendering_active_ &&
516 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location, 517 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
517 &optimized_copy_rect)) { 518 &optimized_copy_rect)) {
518 bounds = optimized_copy_location; 519 bounds = optimized_copy_location;
519 copy_rects.push_back(optimized_copy_rect); 520 copy_rects.push_back(optimized_copy_rect);
520 dib_id = dib->id(); 521 dib_id = dib->id();
522 dib_handle = dib->handle();
521 } else if (!is_gpu_rendering_active_) { 523 } else if (!is_gpu_rendering_active_) {
522 // Compute a buffer for painting and cache it. 524 // Compute a buffer for painting and cache it.
523 scoped_ptr<skia::PlatformCanvas> canvas( 525 scoped_ptr<skia::PlatformCanvas> canvas(
524 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_, 526 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
525 bounds)); 527 bounds));
526 if (!canvas.get()) { 528 if (!canvas.get()) {
527 NOTREACHED(); 529 NOTREACHED();
528 return; 530 return;
529 } 531 }
530 532
(...skipping 15 matching lines...) Expand all
546 548
547 // The scroll damage is just another rectangle to paint and copy. 549 // The scroll damage is just another rectangle to paint and copy.
548 copy_rects.swap(update.paint_rects); 550 copy_rects.swap(update.paint_rects);
549 if (!scroll_damage.IsEmpty()) 551 if (!scroll_damage.IsEmpty())
550 copy_rects.push_back(scroll_damage); 552 copy_rects.push_back(scroll_damage);
551 553
552 for (size_t i = 0; i < copy_rects.size(); ++i) 554 for (size_t i = 0; i < copy_rects.size(); ++i)
553 PaintRect(copy_rects[i], bounds.origin(), canvas.get()); 555 PaintRect(copy_rects[i], bounds.origin(), canvas.get());
554 556
555 dib_id = current_paint_buf_->id(); 557 dib_id = current_paint_buf_->id();
558 dib_handle = current_paint_buf_->handle();
556 } else { // Accelerated compositing path 559 } else { // Accelerated compositing path
557 // Begin painting. 560 // Begin painting.
558 bool finish = next_paint_is_resize_ack(); 561 bool finish = next_paint_is_resize_ack();
559 webwidget_->composite(finish); 562 webwidget_->composite(finish);
560 } 563 }
561 564
562 // sending an ack to browser process that the paint is complete... 565 // sending an ack to browser process that the paint is complete...
563 ViewHostMsg_UpdateRect_Params params; 566 ViewHostMsg_UpdateRect_Params params;
564 params.bitmap = dib_id; 567 params.dib_id = dib_id;
568 params.dib_handle = dib_handle;
565 params.bitmap_rect = bounds; 569 params.bitmap_rect = bounds;
566 params.dx = update.scroll_delta.x(); 570 params.dx = update.scroll_delta.x();
567 params.dy = update.scroll_delta.y(); 571 params.dy = update.scroll_delta.y();
568 if (is_gpu_rendering_active_) { 572 if (is_gpu_rendering_active_) {
569 // If painting is done via the gpu process then we clear out all damage 573 // If painting is done via the gpu process then we clear out all damage
570 // rects to save the browser process from doing unecessary work. 574 // rects to save the browser process from doing unecessary work.
571 params.scroll_rect = gfx::Rect(); 575 params.scroll_rect = gfx::Rect();
572 params.copy_rects.clear(); 576 params.copy_rects.clear();
573 } else { 577 } else {
574 params.scroll_rect = update.scroll_rect; 578 params.scroll_rect = update.scroll_rect;
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 if (webwidget_) 816 if (webwidget_)
813 webwidget_->confirmComposition(); 817 webwidget_->confirmComposition();
814 } 818 }
815 819
816 // This message causes the renderer to render an image of the 820 // This message causes the renderer to render an image of the
817 // desired_size, regardless of whether the tab is hidden or not. 821 // desired_size, regardless of whether the tab is hidden or not.
818 void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle, 822 void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle,
819 int tag, 823 int tag,
820 const gfx::Size& page_size, 824 const gfx::Size& page_size,
821 const gfx::Size& desired_size) { 825 const gfx::Size& desired_size) {
822 if (!webwidget_ || dib_handle == TransportDIB::DefaultHandleValue()) 826 TransportDIB::ScopedHandle scoped_dib_handle(dib_handle);
827 if (!webwidget_ || !TransportDIB::is_valid(dib_handle))
823 return; 828 return;
824 829
825 if (page_size.IsEmpty() || desired_size.IsEmpty()) { 830 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
826 // If one of these is empty, then we just return the dib we were 831 // If one of these is empty, then we just return the dib we were
827 // given, to avoid leaking it. 832 // given, to avoid leaking it.
828 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size)); 833 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
829 return; 834 return;
830 } 835 }
831 836
832 // Map the given DIB ID into this process, and unmap it at the end 837 // Map the given DIB ID into this process, and unmap it at the end
833 // of this function. 838 // of this function.
834 scoped_ptr<TransportDIB> paint_at_size_buffer(TransportDIB::Map(dib_handle)); 839 scoped_ptr<TransportDIB> paint_at_size_buffer(
840 TransportDIB::CreateWithHandle(scoped_dib_handle.release()));
841 gfx::Size canvas_size = page_size;
842 scoped_ptr<skia::PlatformCanvas> canvas(
843 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
844 canvas_size.height()));
845 if (!canvas.get()) {
846 NOTREACHED();
847 return;
848 }
835 849
836 DCHECK(paint_at_size_buffer.get());
837 if (!paint_at_size_buffer.get())
838 return;
839
840 gfx::Size canvas_size = page_size;
841 float x_scale = static_cast<float>(desired_size.width()) / 850 float x_scale = static_cast<float>(desired_size.width()) /
842 static_cast<float>(canvas_size.width()); 851 static_cast<float>(canvas_size.width());
843 float y_scale = static_cast<float>(desired_size.height()) / 852 float y_scale = static_cast<float>(desired_size.height()) /
844 static_cast<float>(canvas_size.height()); 853 static_cast<float>(canvas_size.height());
845 854
846 gfx::Rect orig_bounds(canvas_size); 855 gfx::Rect orig_bounds(canvas_size);
847 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale)); 856 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
848 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale)); 857 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
849 gfx::Rect bounds(canvas_size); 858 gfx::Rect bounds(canvas_size);
850 859
851 scoped_ptr<skia::PlatformCanvas> canvas(
852 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
853 canvas_size.height()));
854 if (!canvas.get()) {
855 NOTREACHED();
856 return;
857 }
858
859 // Reset bounds to what we actually received, but they should be the 860 // Reset bounds to what we actually received, but they should be the
860 // same. 861 // same.
861 DCHECK_EQ(bounds.width(), canvas->getDevice()->width()); 862 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
862 DCHECK_EQ(bounds.height(), canvas->getDevice()->height()); 863 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
863 bounds.set_width(canvas->getDevice()->width()); 864 bounds.set_width(canvas->getDevice()->width());
864 bounds.set_height(canvas->getDevice()->height()); 865 bounds.set_height(canvas->getDevice()->height());
865 866
866 canvas->save(); 867 canvas->save();
867 // Add the scale factor to the canvas, so that we'll get the desired size. 868 // Add the scale factor to the canvas, so that we'll get the desired size.
868 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale)); 869 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 1014
1014 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { 1015 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
1015 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); 1016 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
1016 i != plugin_window_moves_.end(); ++i) { 1017 i != plugin_window_moves_.end(); ++i) {
1017 if (i->window == window) { 1018 if (i->window == window) {
1018 plugin_window_moves_.erase(i); 1019 plugin_window_moves_.erase(i);
1019 break; 1020 break;
1020 } 1021 }
1021 } 1022 }
1022 } 1023 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698