Changeset 49641 in webkit
- Timestamp:
- Oct 15, 2009 11:16:38 AM (15 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r49636 r49641 1 2009-10-08 Adam Langley <agl@google.com> 2 3 Reviewed by Eric Seidel. 4 5 Currently, Skia clip paths are 1-bit. This patch makes our path 6 clipping anti-aliased for non-canvas drawing. 7 8 http://code.google.com/p/chromium/issues/detail?id=5927 9 https://bugs.webkit.org/show_bug.cgi?id=28820 10 http://www.imperialviolet.org/2009/09/02/anti-aliased-clipping.html 11 12 Already covered by layout tests. New baselines will be needed in the 13 Chromium tree. 14 15 (Reland. First landed in r49329, reverted in r49330 due to Windows 16 build break) 17 18 * html/canvas/CanvasRenderingContext2D.cpp: 19 (WebCore::CanvasRenderingContext2D::clip): 20 * platform/graphics/GraphicsContext.h: 21 * platform/graphics/cairo/GraphicsContextCairo.cpp: 22 (WebCore::GraphicsContext::canvasClip): 23 * platform/graphics/cg/GraphicsContextCG.cpp: 24 (WebCore::GraphicsContext::canvasClip): 25 * platform/graphics/haiku/GraphicsContextHaiku.cpp: 26 (WebCore::GraphicsContext::canvasClip): 27 * platform/graphics/qt/GraphicsContextQt.cpp: 28 (WebCore::GraphicsContext::canvasClip): 29 * platform/graphics/skia/GraphicsContextSkia.cpp: 30 (WebCore::GraphicsContext::addInnerRoundedRectClip): 31 (WebCore::GraphicsContext::clip): 32 (WebCore::GraphicsContext::canvasClip): 33 (WebCore::GraphicsContext::clipPath): 34 * platform/graphics/skia/PlatformContextSkia.cpp: 35 (PlatformContextSkia::clipPathAntiAliased): 36 (PlatformContextSkia::restore): 37 (PlatformContextSkia::applyAntiAliasedClipPaths): 38 * platform/graphics/skia/PlatformContextSkia.h: 39 * platform/graphics/win/GraphicsContextWin.cpp: 40 (WebCore::GraphicsContext::canvasClip): 41 * platform/graphics/wince/GraphicsContextWince.cpp: 42 (WebCore::GraphicsContext::canvasClip): 43 * platform/graphics/wx/GraphicsContextWx.cpp: 44 (WebCore::GraphicsContext::canvasClip): 45 1 46 2009-10-15 Eric Carlson <eric.carlson@apple.com> 2 47 -
trunk/WebCore/html/canvas/CanvasRenderingContext2D.cpp
r49330 r49641 688 688 if (!state().m_invertibleCTM) 689 689 return; 690 c->c lip(m_path);690 c->canvasClip(m_path); 691 691 #if ENABLE(DASHBOARD_SUPPORT) 692 692 clearPathForDashboardBackwardCompatibilityMode(); -
trunk/WebCore/platform/graphics/GraphicsContext.h
r49330 r49641 298 298 299 299 void clip(const Path&); 300 301 // This clip function is used only by <canvas> code. It allows 302 // implementations to handle clipping on the canvas differently since 303 // the disipline is different. 304 void canvasClip(const Path&); 300 305 void clipOut(const Path&); 301 306 -
trunk/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp
r49330 r49641 932 932 } 933 933 934 void GraphicsContext::canvasClip(const Path& path) 935 { 936 clip(path); 937 } 938 934 939 void GraphicsContext::clipOut(const Path& path) 935 940 { -
trunk/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
r49330 r49641 850 850 } 851 851 852 void GraphicsContext::canvasClip(const Path& path) 853 { 854 clip(path); 855 } 856 852 857 void GraphicsContext::clipOut(const Path& path) 853 858 { -
trunk/WebCore/platform/graphics/haiku/GraphicsContextHaiku.cpp
r49330 r49641 370 370 } 371 371 372 void GraphicsContext::canvasClip(const Path& path) 373 { 374 clip(path); 375 } 376 372 377 void GraphicsContext::clipOut(const Path& path) 373 378 { -
trunk/WebCore/platform/graphics/qt/GraphicsContextQt.cpp
r49330 r49641 1054 1054 } 1055 1055 1056 void GraphicsContext::canvasClip(const Path& path) 1057 { 1058 clip(path); 1059 } 1060 1056 1061 void GraphicsContext::clipOut(const Path& path) 1057 1062 { -
trunk/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp
r49330 r49641 297 297 path.addOval(r, SkPath::kCCW_Direction); 298 298 } 299 platformContext()->c anvas()->clipPath(path);299 platformContext()->clipPathAntiAliased(path); 300 300 } 301 301 … … 357 357 return; 358 358 359 platformContext()->clipPathAntiAliased(p); 360 } 361 362 void GraphicsContext::canvasClip(const Path& path) 363 { 364 if (paintingDisabled()) 365 return; 366 367 const SkPath& p = *path.platformPath(); 368 if (!isPathSkiaSafe(getCTM(), p)) 369 return; 370 359 371 platformContext()->canvas()->clipPath(p); 360 372 } … … 408 420 409 421 path.setFillType(clipRule == RULE_EVENODD ? SkPath::kEvenOdd_FillType : SkPath::kWinding_FillType); 410 platformContext()->c anvas()->clipPath(path);422 platformContext()->clipPathAntiAliased(path); 411 423 } 412 424 -
trunk/WebCore/platform/graphics/skia/PlatformContextSkia.cpp
r49330 r49641 46 46 47 47 #include <wtf/MathExtras.h> 48 #include <wtf/Vector.h> 48 49 49 50 namespace WebCore … … 95 96 WebCore::FloatRect m_clip; 96 97 #endif 98 99 // This is a list of clipping paths which are currently active, in the 100 // order in which they were pushed. 101 WTF::Vector<SkPath> m_antiAliasClipPaths; 97 102 98 103 private: … … 250 255 #endif 251 256 257 void PlatformContextSkia::clipPathAntiAliased(const SkPath& clipPath) 258 { 259 // If we are currently tracking any anti-alias clip paths, then we already 260 // have a layer in place and don't need to add another. 261 bool haveLayerOutstanding = m_state->m_antiAliasClipPaths.size(); 262 263 // See comments in applyAntiAliasedClipPaths about how this works. 264 m_state->m_antiAliasClipPaths.append(clipPath); 265 266 if (!haveLayerOutstanding) { 267 SkRect bounds = clipPath.getBounds(); 268 canvas()->saveLayerAlpha(&bounds, 255, static_cast<SkCanvas::SaveFlags>(SkCanvas::kHasAlphaLayer_SaveFlag | SkCanvas::kFullColorLayer_SaveFlag | SkCanvas::kClipToLayer_SaveFlag)); 269 } 270 } 271 252 272 void PlatformContextSkia::restore() 253 273 { … … 258 278 } 259 279 #endif 280 281 if (!m_state->m_antiAliasClipPaths.isEmpty()) 282 applyAntiAliasedClipPaths(m_state->m_antiAliasClipPaths); 260 283 261 284 m_stateStack.removeLast(); … … 550 573 } 551 574 #endif 575 576 void PlatformContextSkia::applyAntiAliasedClipPaths(WTF::Vector<SkPath>& paths) 577 { 578 // Anti-aliased clipping: 579 // 580 // Skia's clipping is 1-bit only. Consider what would happen if it were 8-bit: 581 // We have a square canvas, filled with white and we declare a circular 582 // clipping path. Then we fill twice with a black rectangle. The fractional 583 // pixels would first get the correct color (white * alpha + black * (1 - 584 // alpha)), but the second fill would apply the alpha to the already 585 // modified color and the result would be too dark. 586 // 587 // This, anti-aliased clipping needs to be performed after the drawing has 588 // been done. In order to do this, we create a new layer of the canvas in 589 // clipPathAntiAliased and store the clipping path. All drawing is done to 590 // the layer's bitmap while it's in effect. When WebKit calls restore() to 591 // undo the clipping, this function is called. 592 // 593 // Here, we walk the list of clipping paths backwards and, for each, we 594 // clear outside of the clipping path. We only need a single extra layer 595 // for any number of clipping paths. 596 // 597 // When we call restore on the SkCanvas, the layer's bitmap is composed 598 // into the layer below and we end up with correct, anti-aliased clipping. 599 600 SkPaint paint; 601 paint.setXfermodeMode(SkXfermode::kClear_Mode); 602 paint.setAntiAlias(true); 603 paint.setStyle(SkPaint::kFill_Style); 604 605 for (size_t i = paths.size() - 1; i < paths.size(); --i) { 606 paths[i].setFillType(SkPath::kInverseWinding_FillType); 607 m_canvas->drawPath(paths[i], paint); 608 } 609 610 m_canvas->restore(); 611 } -
trunk/WebCore/platform/graphics/skia/PlatformContextSkia.h
r49330 r49641 93 93 const WebCore::ImageBuffer*); 94 94 #endif 95 void clipPathAntiAliased(const SkPath&); 95 96 96 97 // Sets up the common flags on a paint for antialiasing, effects, etc. … … 173 174 void applyClipFromImage(const WebCore::FloatRect&, const SkBitmap&); 174 175 #endif 176 void applyAntiAliasedClipPaths(WTF::Vector<SkPath>& paths); 175 177 176 178 // Defines drawing style. -
trunk/WebCore/platform/graphics/wince/GraphicsContextWince.cpp
r49330 r49641 1218 1218 { 1219 1219 notImplemented(); 1220 } 1221 1222 void GraphicsContext::canvasClip(const Path& path) 1223 { 1224 clip(path); 1220 1225 } 1221 1226 -
trunk/WebCore/platform/graphics/wx/GraphicsContextWx.cpp
r49330 r49641 345 345 } 346 346 347 void GraphicsContext::canvasClip(const Path& path) 348 { 349 clip(path); 350 } 351 347 352 void GraphicsContext::clipToImageBuffer(const FloatRect&, const ImageBuffer*) 348 353 {
Note: See TracChangeset
for help on using the changeset viewer.