WebKit/win/ChangeLog

112007-11-25 Adam Roben <aroben@apple.com>
22
 3 Refactor WebView's repaint rect code
 4
 5 Reviewed by NOBODY (OOPS!).
 6
 7 * WebView.cpp:
 8 (getUpdateRects): Factored code out of updateBackingStore and paint
 9 into this new helper function.
 10 (WebView::updateBackingStore): Use getUpdateRects.
 11 (WebView::paint): Ditto.
 12 (WebView::paintIntoBackingStore): Changed to take a const IntRect&.
 13 (WebView::paintIntoWindow): Ditto.
 14 * WebView.h:
 15
 162007-11-25 Adam Roben <aroben@apple.com>
 17
318 Add ImageDiff.vcproj to WebKit.sln
419
520 Reviewed by Sam.

WebKit/win/WebView.cpp

@@void WebView::scrollBackingStore(FrameView* frameView, int dx, int dy, const Int
704704
705705}
706706
 707// This emulates the Mac smarts for painting rects intelligently. This is very
 708// important for us, since we double buffer based off dirty rects.
 709static void getUpdateRects(HRGN region, const IntRect& dirtyRect, Vector<IntRect>& rects)
 710{
 711 ASSERT_ARG(region, region);
 712
 713 const int cRectThreshold = 10;
 714 const float cWastedSpaceThreshold = 0.75f;
 715
 716 rects.clear();
 717
 718 DWORD regionDataSize = GetRegionData(region, sizeof(RGNDATA), NULL);
 719 if (!regionDataSize) {
 720 rects.append(dirtyRect);
 721 return;
 722 }
 723
 724 Vector<unsigned char> buffer(regionDataSize);
 725 RGNDATA* regionData = reinterpret_cast<RGNDATA*>(buffer.data());
 726 GetRegionData(region, regionDataSize, regionData);
 727 if (regionData->rdh.nCount > cRectThreshold) {
 728 rects.append(dirtyRect);
 729 return;
 730 }
 731
 732 double singlePixels = 0.0;
 733 unsigned i;
 734 RECT* rect;
 735 for (i = 0, rect = reinterpret_cast<RECT*>(regionData->Buffer); i < regionData->rdh.nCount; i++, rect++)
 736 singlePixels += (rect->right - rect->left) * (rect->bottom - rect->top);
 737
 738 double unionPixels = dirtyRect.width() * dirtyRect.height();
 739 double wastedSpace = 1.0 - (singlePixels / unionPixels);
 740 if (wastedSpace <= cWastedSpaceThreshold) {
 741 rects.append(dirtyRect);
 742 return;
 743 }
 744
 745 for (i = 0, rect = reinterpret_cast<RECT*>(regionData->Buffer); i < regionData->rdh.nCount; i++, rect++)
 746 rects.append(*rect);
 747}
 748
707749void WebView::updateBackingStore(FrameView* frameView, HDC dc, bool backingStoreCompletelyDirty)
708750{
709751 LOCAL_GDI_COUNTER(0, __FUNCTION__);

@@void WebView::updateBackingStore(FrameView* frameView, HDC dc, bool backingStore
722764 if (FrameView* view = coreFrame->view())
723765 view->layoutIfNeededRecursive();
724766
725  // This emulates the Mac smarts for painting rects intelligently. This is
726  // very important for us, since we double buffer based off dirty rects.
727  bool useRegionBox = true;
728  const int cRectThreshold = 10;
729  const float cWastedSpaceThreshold = 0.75f;
730  RECT regionBox;
 767 Vector<IntRect> paintRects;
731768 if (!backingStoreCompletelyDirty) {
 769 RECT regionBox;
732770 ::GetRgnBox(m_backingStoreDirtyRegion.get(), &regionBox);
733  DWORD regionDataSize = GetRegionData(m_backingStoreDirtyRegion.get(), sizeof(RGNDATA), NULL);
734  if (regionDataSize) {
735  RGNDATA* regionData = (RGNDATA*)malloc(regionDataSize);
736  GetRegionData(m_backingStoreDirtyRegion.get(), regionDataSize, regionData);
737  if (regionData->rdh.nCount <= cRectThreshold) {
738  double unionPixels = (regionBox.right - regionBox.left) * (regionBox.bottom - regionBox.top);
739  double singlePixels = 0;
740 
741  unsigned i;
742  RECT* rect;
743  for (i = 0, rect = (RECT*)regionData->Buffer; i < regionData->rdh.nCount; i++, rect++)
744  singlePixels += (rect->right - rect->left) * (rect->bottom - rect->top);
745  double wastedSpace = 1.0 - (singlePixels / unionPixels);
746  if (wastedSpace > cWastedSpaceThreshold) {
747  // Paint individual rects.
748  useRegionBox = false;
749  for (i = 0, rect = (RECT*)regionData->Buffer; i < regionData->rdh.nCount; i++, rect++)
750  paintIntoBackingStore(frameView, bitmapDC, rect);
751  }
752  }
753  free(regionData);
754  }
755  } else
756  ::GetClientRect(m_viewWindow, &regionBox);
 771 getUpdateRects(m_backingStoreDirtyRegion.get(), regionBox, paintRects);
 772 } else {
 773 RECT clientRect;
 774 ::GetClientRect(m_viewWindow, &clientRect);
 775 paintRects.append(clientRect);
 776 }
757777
758  if (useRegionBox)
759  paintIntoBackingStore(frameView, bitmapDC, &regionBox);
 778 for (unsigned i = 0; i < paintRects.size(); ++i)
 779 paintIntoBackingStore(frameView, bitmapDC, paintRects[i]);
760780
761781 if (m_uiDelegatePrivate) {
762782 COMPtr<IWebUIDelegatePrivate2> uiDelegatePrivate2(Query, m_uiDelegatePrivate);

@@void WebView::paint(HDC dc, LPARAM options)
814834 IntRect windowDirtyRect = rcPaint;
815835
816836 // Apply the same heuristic for this update region too.
817  bool useWindowDirtyRect = true;
818  if (region && regionType == COMPLEXREGION) {
819  LOCAL_GDI_COUNTER(1, __FUNCTION__" (COMPLEXREGION)");
820 
821  const int cRectThreshold = 10;
822  const float cWastedSpaceThreshold = 0.75f;
823  DWORD regionDataSize = GetRegionData(region.get(), sizeof(RGNDATA), NULL);
824  if (regionDataSize) {
825  RGNDATA* regionData = (RGNDATA*)malloc(regionDataSize);
826  GetRegionData(region.get(), regionDataSize, regionData);
827  if (regionData->rdh.nCount <= cRectThreshold) {
828  double unionPixels = windowDirtyRect.width() * windowDirtyRect.height();
829  double singlePixels = 0;
830 
831  unsigned i;
832  RECT* rect;
833  for (i = 0, rect = (RECT*)regionData->Buffer; i < regionData->rdh.nCount; i++, rect++)
834  singlePixels += (rect->right - rect->left) * (rect->bottom - rect->top);
835  double wastedSpace = 1.0 - (singlePixels / unionPixels);
836  if (wastedSpace > cWastedSpaceThreshold) {
837  // Paint individual rects.
838  useWindowDirtyRect = false;
839  for (i = 0, rect = (RECT*)regionData->Buffer; i < regionData->rdh.nCount; i++, rect++)
840  paintIntoWindow(bitmapDC, hdc, rect);
841  }
842  }
843  free(regionData);
844  }
845  }
 837 Vector<IntRect> blitRects;
 838 if (region && regionType == COMPLEXREGION)
 839 getUpdateRects(region.get(), windowDirtyRect, blitRects);
 840 else
 841 blitRects.append(windowDirtyRect);
846842
847  if (useWindowDirtyRect)
848  paintIntoWindow(bitmapDC, hdc, &rcPaint);
 843 for (unsigned i = 0; i < blitRects.size(); ++i)
 844 paintIntoWindow(bitmapDC, hdc, blitRects[i]);
849845
850846 ::DeleteDC(bitmapDC);
851847

@@void WebView::paint(HDC dc, LPARAM options)
868864 m_paintCount--;
869865}
870866
871 void WebView::paintIntoBackingStore(FrameView* frameView, HDC bitmapDC, LPRECT dirtyRect)
 867void WebView::paintIntoBackingStore(FrameView* frameView, HDC bitmapDC, const IntRect& dirtyRect)
872868{
873869 LOCAL_GDI_COUNTER(0, __FUNCTION__);
874870
 871 RECT rect = dirtyRect;
 872
875873#if FLASH_BACKING_STORE_REDRAW
876874 HDC dc = ::GetDC(m_viewWindow);
877875 OwnPtr<HBRUSH> yellowBrush = CreateSolidBrush(RGB(255, 255, 0));
878  FillRect(dc, dirtyRect, yellowBrush.get());
 876 FillRect(dc, &rect, yellowBrush.get());
879877 GdiFlush();
880878 Sleep(50);
881879 paintIntoWindow(bitmapDC, dc, dirtyRect);
882880 ::ReleaseDC(m_viewWindow, dc);
883881#endif
884882
885  FillRect(bitmapDC, dirtyRect, (HBRUSH)GetStockObject(WHITE_BRUSH));
 883 FillRect(bitmapDC, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH));
886884 if (frameView && frameView->frame() && frameView->frame()->renderer()) {
887885 GraphicsContext gc(bitmapDC);
888886 gc.save();
889  gc.clip(IntRect(*dirtyRect));
890  frameView->paint(&gc, IntRect(*dirtyRect));
 887 gc.clip(dirtyRect);
 888 frameView->paint(&gc, dirtyRect);
891889 gc.restore();
892890 }
893891}
894892
895 void WebView::paintIntoWindow(HDC bitmapDC, HDC windowDC, LPRECT dirtyRect)
 893void WebView::paintIntoWindow(HDC bitmapDC, HDC windowDC, const IntRect& dirtyRect)
896894{
897895 LOCAL_GDI_COUNTER(0, __FUNCTION__);
898896#if FLASH_WINDOW_REDRAW
899897 OwnPtr<HBRUSH> greenBrush = CreateSolidBrush(RGB(0, 255, 0));
900  FillRect(windowDC, dirtyRect, greenBrush.get());
 898 RECT rect = dirtyRect;
 899 FillRect(windowDC, &rect, greenBrush.get());
901900 GdiFlush();
902901 Sleep(50);
903902#endif
904903
905904 // Blit the dirty rect from the backing store into the same position
906905 // in the destination DC.
907  BitBlt(windowDC, dirtyRect->left, dirtyRect->top, dirtyRect->right - dirtyRect->left, dirtyRect->bottom - dirtyRect->top, bitmapDC,
908  dirtyRect->left, dirtyRect->top, SRCCOPY);
 906 BitBlt(windowDC, dirtyRect.x(), dirtyRect.y(), dirtyRect.width(), dirtyRect.height(), bitmapDC,
 907 dirtyRect.x(), dirtyRect.y(), SRCCOPY);
909908}
910909
911910void WebView::frameRect(RECT* rect)

WebKit/win/WebView.h

@@public:
634634 bool keyUp(WPARAM, LPARAM, bool systemKeyDown = false);
635635 bool inResizer(LPARAM lParam);
636636 void paint(HDC, LPARAM);
637  void paintIntoBackingStore(WebCore::FrameView*, HDC bitmapDC, LPRECT dirtyRect);
638  void paintIntoWindow(HDC bitmapDC, HDC windowDC, LPRECT dirtyRect);
 637 void paintIntoBackingStore(WebCore::FrameView*, HDC bitmapDC, const WebCore::IntRect& dirtyRect);
 638 void paintIntoWindow(HDC bitmapDC, HDC windowDC, const WebCore::IntRect& dirtyRect);
639639 bool ensureBackingStore();
640640 void addToDirtyRegion(const WebCore::IntRect&);
641641 void addToDirtyRegion(HRGN);