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

Side by Side Diff: chrome/browser/renderer_host/render_widget_host_view_win.cc

Issue 506075: Revert 34951 - Combine ViewHostMsg_{Paint,Scroll}Rect into one IPC.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/browser/renderer_host/render_widget_host_view_win.h" 5 #include "chrome/browser/renderer_host/render_widget_host_view_win.h"
6 6
7 #include "app/gfx/canvas.h" 7 #include "app/gfx/canvas.h"
8 #include "app/gfx/gdi_util.h" 8 #include "app/gfx/gdi_util.h"
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "app/l10n_util_win.h" 10 #include "app/l10n_util_win.h"
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 lparam = rect->width() << 16 | rect->height(); 561 lparam = rect->width() << 16 | rect->height();
562 562
563 // SendMessage gets the message across much quicker than PostMessage, since it 563 // SendMessage gets the message across much quicker than PostMessage, since it
564 // doesn't get queued. When the plugin thread calls PeekMessage or other 564 // doesn't get queued. When the plugin thread calls PeekMessage or other
565 // Win32 APIs, sent messages are dispatched automatically. 565 // Win32 APIs, sent messages are dispatched automatically.
566 SendNotifyMessage(hwnd, msg, wparam, lparam); 566 SendNotifyMessage(hwnd, msg, wparam, lparam);
567 567
568 return TRUE; 568 return TRUE;
569 } 569 }
570 570
571 void RenderWidgetHostViewWin::Redraw() { 571 void RenderWidgetHostViewWin::Redraw(const gfx::Rect& rect) {
572 RECT damage_bounds;
573 GetUpdateRect(&damage_bounds, FALSE);
574
575 ScopedGDIObject<HRGN> damage_region(CreateRectRgn(0, 0, 0, 0));
576 GetUpdateRgn(damage_region, FALSE);
577
578 // Paint the invalid region synchronously. Our caller will not paint again 572 // Paint the invalid region synchronously. Our caller will not paint again
579 // until we return, so by painting to the screen here, we ensure effective 573 // until we return, so by painting to the screen here, we ensure effective
580 // rate-limiting of backing store updates. This helps a lot on pages that 574 // rate-limiting of backing store updates. This helps a lot on pages that
581 // have animations or fairly expensive layout (e.g., google maps). 575 // have animations or fairly expensive layout (e.g., google maps).
582 // 576 //
583 // We paint this window synchronously, however child windows (i.e. plugins) 577 // We paint this window synchronously, however child windows (i.e. plugins)
584 // are painted asynchronously. By avoiding synchronous cross-process window 578 // are painted asynchronously. By avoiding synchronous cross-process window
585 // message dispatching we allow scrolling to be smooth, and also avoid the 579 // message dispatching we allow scrolling to be smooth, and also avoid the
586 // browser process locking up if the plugin process is hung. 580 // browser process locking up if the plugin process is hung.
587 // 581 //
588 RedrawWindow(NULL, damage_region, RDW_UPDATENOW | RDW_NOCHILDREN); 582 RedrawWindow(
583 &rect.ToRECT(), NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_NOCHILDREN);
589 584
590 // Send the invalid rect in screen coordinates. 585 // Send the invalid rect in screen coordinates.
591 gfx::Rect screen_rect = GetViewBounds(); 586 gfx::Rect screen_rect = GetViewBounds();
592 gfx::Rect invalid_screen_rect(damage_bounds); 587 gfx::Rect invalid_screen_rect = rect;
593 invalid_screen_rect.Offset(screen_rect.x(), screen_rect.y()); 588 invalid_screen_rect.Offset(screen_rect.x(), screen_rect.y());
594 589
595 LPARAM lparam = reinterpret_cast<LPARAM>(&invalid_screen_rect); 590 LPARAM lparam = reinterpret_cast<LPARAM>(&invalid_screen_rect);
596 EnumChildWindows(m_hWnd, EnumChildProc, lparam); 591 EnumChildWindows(m_hWnd, EnumChildProc, lparam);
597 } 592 }
598 593
599 void RenderWidgetHostViewWin::DrawResizeCorner(const gfx::Rect& paint_rect, 594 void RenderWidgetHostViewWin::DrawResizeCorner(const gfx::Rect& paint_rect,
600 HDC dc) { 595 HDC dc) {
601 gfx::Rect resize_corner_rect = 596 gfx::Rect resize_corner_rect =
602 render_widget_host_->GetRootWindowResizerRect(); 597 render_widget_host_->GetRootWindowResizerRect();
(...skipping 14 matching lines...) Expand all
617 } 612 }
618 canvas.DrawBitmapInt(*bitmap, 0, 0); 613 canvas.DrawBitmapInt(*bitmap, 0, 0);
619 canvas.getTopPlatformDevice().drawToHDC(dc, x, 614 canvas.getTopPlatformDevice().drawToHDC(dc, x,
620 resize_corner_rect.y() + resize_corner_rect.height() - 615 resize_corner_rect.y() + resize_corner_rect.height() -
621 bitmap->height(), NULL); 616 bitmap->height(), NULL);
622 if (rtl_dir) 617 if (rtl_dir)
623 canvas.restore(); 618 canvas.restore();
624 } 619 }
625 } 620 }
626 621
627 void RenderWidgetHostViewWin::DidPaintBackingStoreRects( 622 void RenderWidgetHostViewWin::DidPaintRect(const gfx::Rect& rect) {
628 const std::vector<gfx::Rect>& rects) {
629 if (is_hidden_) 623 if (is_hidden_)
630 return; 624 return;
631 625
632 for (size_t i = 0; i < rects.size(); ++i) 626 if (about_to_validate_and_paint_)
633 InvalidateRect(&rects[i].ToRECT(), false); 627 InvalidateRect(&rect.ToRECT(), false);
634 628 else
635 if (!about_to_validate_and_paint_) 629 Redraw(rect);
636 Redraw();
637 } 630 }
638 631
639 void RenderWidgetHostViewWin::DidScrollBackingStoreRect( 632 void RenderWidgetHostViewWin::DidScrollRect(
640 const gfx::Rect& rect, int dx, int dy) { 633 const gfx::Rect& rect, int dx, int dy) {
641 if (is_hidden_) 634 if (is_hidden_)
642 return; 635 return;
643 636
644 // We need to pass in SW_INVALIDATE to ScrollWindowEx. The documentation on 637 // We need to pass in SW_INVALIDATE to ScrollWindowEx. The MSDN
645 // MSDN states that it only applies to the HRGN argument, which is wrong. 638 // documentation states that it only applies to the HRGN argument, which is
646 // Not passing in this flag does not invalidate the region which was scrolled 639 // wrong. Not passing in this flag does not invalidate the region which was
647 // from, thus causing painting issues. 640 // scrolled from, thus causing painting issues.
648 RECT clip_rect = rect.ToRECT(); 641 RECT clip_rect = rect.ToRECT();
649 ScrollWindowEx(dx, dy, NULL, &clip_rect, NULL, NULL, SW_INVALIDATE); 642 ScrollWindowEx(dx, dy, NULL, &clip_rect, NULL, NULL, SW_INVALIDATE);
643
644 RECT invalid_rect = {0};
645 GetUpdateRect(&invalid_rect);
646 Redraw(gfx::Rect(invalid_rect));
650 } 647 }
651 648
652 void RenderWidgetHostViewWin::RenderViewGone() { 649 void RenderWidgetHostViewWin::RenderViewGone() {
653 // TODO(darin): keep this around, and draw sad-tab into it. 650 // TODO(darin): keep this around, and draw sad-tab into it.
654 UpdateCursorIfOverSelf(); 651 UpdateCursorIfOverSelf();
655 being_destroyed_ = true; 652 being_destroyed_ = true;
656 DestroyWindow(); 653 DestroyWindow();
657 } 654 }
658 655
659 void RenderWidgetHostViewWin::WillDestroyRenderWidget(RenderWidgetHost* rwh) { 656 void RenderWidgetHostViewWin::WillDestroyRenderWidget(RenderWidgetHost* rwh) {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 void RenderWidgetHostViewWin::OnPaint(HDC dc) { 758 void RenderWidgetHostViewWin::OnPaint(HDC dc) {
762 DCHECK(render_widget_host_->process()->HasConnection()); 759 DCHECK(render_widget_host_->process()->HasConnection());
763 760
764 about_to_validate_and_paint_ = true; 761 about_to_validate_and_paint_ = true;
765 BackingStore* backing_store = render_widget_host_->GetBackingStore(true); 762 BackingStore* backing_store = render_widget_host_->GetBackingStore(true);
766 763
767 // We initialize |paint_dc| (and thus call BeginPaint()) after calling 764 // We initialize |paint_dc| (and thus call BeginPaint()) after calling
768 // GetBackingStore(), so that if it updates the invalid rect we'll catch the 765 // GetBackingStore(), so that if it updates the invalid rect we'll catch the
769 // changes and repaint them. 766 // changes and repaint them.
770 about_to_validate_and_paint_ = false; 767 about_to_validate_and_paint_ = false;
771
772 // Grab the region to paint before creation of paint_dc since it clears the
773 // damage region.
774 ScopedGDIObject<HRGN> damage_region(CreateRectRgn(0, 0, 0, 0));
775 GetUpdateRgn(damage_region, FALSE);
776
777 CPaintDC paint_dc(m_hWnd); 768 CPaintDC paint_dc(m_hWnd);
778 769
779 gfx::Rect damaged_rect(paint_dc.m_ps.rcPaint); 770 gfx::Rect damaged_rect(paint_dc.m_ps.rcPaint);
780 if (damaged_rect.IsEmpty()) 771 if (damaged_rect.IsEmpty())
781 return; 772 return;
782 773
783 if (backing_store) { 774 if (backing_store) {
784 gfx::Rect bitmap_rect(gfx::Point(), backing_store->size()); 775 gfx::Rect bitmap_rect(
776 0, 0, backing_store->size().width(), backing_store->size().height());
785 777
786 bool manage_colors = BackingStore::ColorManagementEnabled(); 778 gfx::Rect paint_rect = bitmap_rect.Intersect(damaged_rect);
787 if (manage_colors) 779 if (!paint_rect.IsEmpty()) {
788 SetICMMode(paint_dc.m_hDC, ICM_ON); 780 DrawResizeCorner(paint_rect, backing_store->hdc());
789 781 bool manage_colors = BackingStore::ColorManagementEnabled();
790 // Blit only the damaged regions from the backing store. 782 if (manage_colors)
791 DWORD data_size = GetRegionData(damage_region, 0, NULL); 783 SetICMMode(paint_dc.m_hDC, ICM_ON);
792 scoped_array<char> region_data_buf(new char[data_size]); 784 BitBlt(paint_dc.m_hDC,
793 RGNDATA* region_data = reinterpret_cast<RGNDATA*>(region_data_buf.get()); 785 paint_rect.x(),
794 GetRegionData(damage_region, data_size, region_data); 786 paint_rect.y(),
795 787 paint_rect.width(),
796 RECT* region_rects = reinterpret_cast<RECT*>(region_data->Buffer); 788 paint_rect.height(),
797 for (DWORD i = 0; i < region_data->rdh.nCount; ++i) { 789 backing_store->hdc(),
798 gfx::Rect paint_rect = bitmap_rect.Intersect(gfx::Rect(region_rects[i])); 790 paint_rect.x(),
799 if (!paint_rect.IsEmpty()) { 791 paint_rect.y(),
800 DrawResizeCorner(paint_rect, backing_store->hdc()); 792 SRCCOPY);
801 BitBlt(paint_dc.m_hDC, 793 if (manage_colors)
802 paint_rect.x(), 794 SetICMMode(paint_dc.m_hDC, ICM_OFF);
803 paint_rect.y(),
804 paint_rect.width(),
805 paint_rect.height(),
806 backing_store->hdc(),
807 paint_rect.x(),
808 paint_rect.y(),
809 SRCCOPY);
810 }
811 } 795 }
812 796
813 if (manage_colors)
814 SetICMMode(paint_dc.m_hDC, ICM_OFF);
815
816 // Fill the remaining portion of the damaged_rect with the background 797 // Fill the remaining portion of the damaged_rect with the background
817 if (damaged_rect.right() > bitmap_rect.right()) { 798 if (damaged_rect.right() > bitmap_rect.right()) {
818 RECT r; 799 RECT r;
819 r.left = std::max(bitmap_rect.right(), damaged_rect.x()); 800 r.left = std::max(bitmap_rect.right(), damaged_rect.x());
820 r.right = damaged_rect.right(); 801 r.right = damaged_rect.right();
821 r.top = damaged_rect.y(); 802 r.top = damaged_rect.y();
822 r.bottom = std::min(bitmap_rect.bottom(), damaged_rect.bottom()); 803 r.bottom = std::min(bitmap_rect.bottom(), damaged_rect.bottom());
823 DrawBackground(r, &paint_dc); 804 DrawBackground(r, &paint_dc);
824 } 805 }
825 if (damaged_rect.bottom() > bitmap_rect.bottom()) { 806 if (damaged_rect.bottom() > bitmap_rect.bottom()) {
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
1481 SetFocus(); 1462 SetFocus();
1482 } 1463 }
1483 } 1464 }
1484 1465
1485 void RenderWidgetHostViewWin::ShutdownHost() { 1466 void RenderWidgetHostViewWin::ShutdownHost() {
1486 shutdown_factory_.RevokeAll(); 1467 shutdown_factory_.RevokeAll();
1487 if (render_widget_host_) 1468 if (render_widget_host_)
1488 render_widget_host_->Shutdown(); 1469 render_widget_host_->Shutdown();
1489 // Do not touch any members at this point, |this| has been deleted. 1470 // Do not touch any members at this point, |this| has been deleted.
1490 } 1471 }
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/render_widget_host_view_win.h ('k') | chrome/browser/renderer_host/resource_message_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698