Changeset 163265 in webkit


Ignore:
Timestamp:
Feb 2, 2014 10:38:45 AM (10 years ago)
Author:
Alan Bujtas
Message:

Subpixel rendering: Introduce device pixel snapping helper functions.
https://bugs.webkit.org/show_bug.cgi?id=128049

Reviewed by Simon Fraser.

These functions help device pixel snapping during painting. They follow the logic of
the corresponding pixelSnappedInt* functions.

No change in functionality.

  • platform/LayoutUnit.h:

(WebCore::roundToDevicePixel):
(WebCore::floorToDevicePixel):
(WebCore::snapSizeToPixel):
(WebCore::snapSizeToDevicePixel):

  • platform/graphics/GraphicsContext.cpp:

(WebCore::GraphicsContext::GraphicsContext):

  • platform/graphics/GraphicsContext.h:

(WebCore::GraphicsContext::pixelSnappingFactor):

  • platform/graphics/LayoutRect.h:

(WebCore::pixelSnappedForPainting):

  • platform/graphics/cg/GraphicsContextCG.cpp:

(WebCore::GraphicsContext::platformInit):

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r163264 r163265  
     12014-02-02  Zalan Bujtas  <zalan@apple.com>
     2
     3        Subpixel rendering: Introduce device pixel snapping helper functions.
     4        https://bugs.webkit.org/show_bug.cgi?id=128049
     5
     6        Reviewed by Simon Fraser.
     7
     8        These functions help device pixel snapping during painting. They follow the logic of
     9        the corresponding pixelSnappedInt* functions.
     10
     11        No change in functionality.
     12
     13        * platform/LayoutUnit.h:
     14        (WebCore::roundToDevicePixel):
     15        (WebCore::floorToDevicePixel):
     16        (WebCore::snapSizeToPixel):
     17        (WebCore::snapSizeToDevicePixel):
     18        * platform/graphics/GraphicsContext.cpp:
     19        (WebCore::GraphicsContext::GraphicsContext):
     20        * platform/graphics/GraphicsContext.h:
     21        (WebCore::GraphicsContext::pixelSnappingFactor):
     22        * platform/graphics/LayoutRect.h:
     23        (WebCore::pixelSnappedForPainting):
     24        * platform/graphics/cg/GraphicsContextCG.cpp:
     25        (WebCore::GraphicsContext::platformInit):
     26
    1272014-02-02  Zalan Bujtas  <zalan@apple.com>
    228
  • trunk/Source/WebCore/platform/LayoutUnit.h

    r163260 r163265  
    936936}
    937937
     938inline float roundToDevicePixel(LayoutUnit value, float pixelSnappingFactor)
     939{
     940    return round((value.rawValue() * pixelSnappingFactor) / kEffectiveFixedPointDenominator) / pixelSnappingFactor;
     941}
     942
     943inline float floorToDevicePixel(LayoutUnit value, float pixelSnappingFactor)
     944{
     945    return floor((value.rawValue() * pixelSnappingFactor) / kEffectiveFixedPointDenominator) / pixelSnappingFactor;
     946}
     947
     948inline float snapSizeToDevicePixel(LayoutUnit size, LayoutUnit location, float pixelSnappingFactor)
     949{
     950    LayoutUnit fraction = location.fraction();
     951    return roundToDevicePixel(fraction + size, pixelSnappingFactor) - roundToDevicePixel(fraction, pixelSnappingFactor);
     952}
     953
    938954inline LayoutUnit roundedLayoutUnit(float value)
    939955{
  • trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp

    r163156 r163265  
    8181    : m_updatingControlTints(false)
    8282    , m_transparencyCount(0)
     83    , m_pixelSnappingFactor(1)
    8384{
    8485    platformInit(platformGraphicsContext);
     
    8889    : m_updatingControlTints(false)
    8990    , m_transparencyCount(0)
     91    , m_pixelSnappingFactor(1)
    9092{
    9193    platformInit(platformGraphicsContext, shouldUseContextColors);
  • trunk/Source/WebCore/platform/graphics/GraphicsContext.h

    r163159 r163265  
    445445        AffineTransform getCTM(IncludeDeviceScale includeScale = PossiblyIncludeDeviceScale) const;
    446446
     447        float pixelSnappingFactor() const { return m_pixelSnappingFactor; }
     448
    447449#if ENABLE(3D_RENDERING) && USE(TEXTURE_MAPPER)
    448450        // This is needed when using accelerated-compositing in software mode, like in TextureMapper.
     
    581583        bool m_updatingControlTints;
    582584        unsigned m_transparencyCount;
     585        float m_pixelSnappingFactor;
    583586    };
    584587
  • trunk/Source/WebCore/platform/graphics/LayoutRect.h

    r162732 r163265  
    232232}
    233233
     234inline FloatRect pixelSnappedForPainting(const LayoutRect& rect, float pixelSnappingFactor)
     235{
     236#if ENABLE(SUBPIXEL_LAYOUT)
     237    return FloatRect(roundToDevicePixel(rect.x(), pixelSnappingFactor), roundToDevicePixel(rect.y(), pixelSnappingFactor),
     238        snapSizeToDevicePixel(rect.width(), rect.x(), pixelSnappingFactor), snapSizeToDevicePixel(rect.height(), rect.y(), pixelSnappingFactor));
     239#else
     240    UNUSED_PARAM(pixelSnappingFactor);
     241    return FloatRect(rect);
     242#endif
     243}
     244
     245inline FloatRect pixelSnappedForPainting(LayoutUnit x, LayoutUnit y, LayoutUnit width, LayoutUnit height, float pixelSnappingFactor)
     246{
     247    return pixelSnappedForPainting(LayoutRect(x, y, width, height), pixelSnappingFactor);
     248}
     249
    234250} // namespace WebCore
    235251
  • trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp

    r163159 r163265  
    139139        setPlatformStrokeColor(strokeColor(), strokeColorSpace());
    140140    }
     141
     142    CGAffineTransform baseDeviceMatrix = CGContextGetUserSpaceToDeviceSpaceTransform(cgContext);
     143    ASSERT(abs(baseDeviceMatrix.a) == abs(baseDeviceMatrix.d));
     144    m_pixelSnappingFactor = baseDeviceMatrix.a;
    141145}
    142146
Note: See TracChangeset for help on using the changeset viewer.