Changeset 109514 in webkit


Ignore:
Timestamp:
Mar 1, 2012 10:47:13 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[chromium] Make opaque paint tracker aware of SkCanvas layers
https://bugs.webkit.org/show_bug.cgi?id=79145

Patch by Dana Jansens <danakj@chromium.org> on 2012-03-01
Reviewed by Stephen White.

Source/WebCore:

The current opaque paint tracker ignored SkCanvas layers entirely. But
SkCanvas layers can be used to apply things like alpha. So we make it
know about layers, and apply any clipping and SkPaint objects for layers
when tracking a paint.

Image clipping is done via a layer, so we can now also remove the
special-case code around image clipping in PlatformContextSkia and
OpaqueRegionSkia.

Unit test: PlatformContextSkiaTest.contextTransparencyLayerTest

Test: compositing/culling/clear-fixed-iframe.html

  • platform/graphics/skia/OpaqueRegionSkia.cpp:

(WebCore::OpaqueRegionSkia::didDrawRect):
(WebCore::OpaqueRegionSkia::didDrawPath):
(WebCore::OpaqueRegionSkia::didDrawPoints):
(WebCore::OpaqueRegionSkia::didDrawBounded):
(WebCore::OpaqueRegionSkia::didDraw):
(WebCore):

  • platform/graphics/skia/OpaqueRegionSkia.h:

(OpaqueRegionSkia):

  • platform/graphics/skia/PlatformContextSkia.cpp:
  • platform/graphics/skia/PlatformContextSkia.h:

(PlatformContextSkia):

Source/WebKit/chromium:

  • tests/PlatformContextSkiaTest.cpp:

(WebCore::TEST):
(WebCore):

LayoutTests:

  • compositing/culling/clear-fixed-iframe-expected.png: Added.
  • compositing/culling/clear-fixed-iframe-expected.txt: Added.
  • compositing/culling/clear-fixed-iframe.html: Added.
  • compositing/culling/resources/clear-fixed-iframe-content.html: Added.
Location:
trunk
Files:
5 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r109512 r109514  
     12012-03-01  Dana Jansens  <danakj@chromium.org>
     2
     3        [chromium] Make opaque paint tracker aware of SkCanvas layers
     4        https://bugs.webkit.org/show_bug.cgi?id=79145
     5
     6        Reviewed by Stephen White.
     7
     8        * compositing/culling/clear-fixed-iframe-expected.png: Added.
     9        * compositing/culling/clear-fixed-iframe-expected.txt: Added.
     10        * compositing/culling/clear-fixed-iframe.html: Added.
     11        * compositing/culling/resources/clear-fixed-iframe-content.html: Added.
     12
    1132012-03-01  Hironori Bono  <hbono@chromium.org>
    214
  • trunk/Source/WebCore/ChangeLog

    r109513 r109514  
     12012-03-01  Dana Jansens  <danakj@chromium.org>
     2
     3        [chromium] Make opaque paint tracker aware of SkCanvas layers
     4        https://bugs.webkit.org/show_bug.cgi?id=79145
     5
     6        Reviewed by Stephen White.
     7
     8        The current opaque paint tracker ignored SkCanvas layers entirely. But
     9        SkCanvas layers can be used to apply things like alpha. So we make it
     10        know about layers, and apply any clipping and SkPaint objects for layers
     11        when tracking a paint.
     12
     13        Image clipping is done via a layer, so we can now also remove the
     14        special-case code around image clipping in PlatformContextSkia and
     15        OpaqueRegionSkia.
     16
     17        Unit test: PlatformContextSkiaTest.contextTransparencyLayerTest
     18
     19        Test: compositing/culling/clear-fixed-iframe.html
     20
     21        * platform/graphics/skia/OpaqueRegionSkia.cpp:
     22        (WebCore::OpaqueRegionSkia::didDrawRect):
     23        (WebCore::OpaqueRegionSkia::didDrawPath):
     24        (WebCore::OpaqueRegionSkia::didDrawPoints):
     25        (WebCore::OpaqueRegionSkia::didDrawBounded):
     26        (WebCore::OpaqueRegionSkia::didDraw):
     27        (WebCore):
     28        * platform/graphics/skia/OpaqueRegionSkia.h:
     29        (OpaqueRegionSkia):
     30        * platform/graphics/skia/PlatformContextSkia.cpp:
     31        * platform/graphics/skia/PlatformContextSkia.h:
     32        (PlatformContextSkia):
     33
    1342012-03-02  Kent Tamura  <tkent@chromium.org>
    235
  • trunk/Source/WebCore/platform/graphics/skia/OpaqueRegionSkia.cpp

    r107988 r109514  
    148148}
    149149
    150 void OpaqueRegionSkia::didDrawRect(const PlatformContextSkia* context, const AffineTransform& transform, const SkRect& fillRect, const SkPaint& paint, const SkBitmap* bitmap)
     150void OpaqueRegionSkia::didDrawRect(PlatformContextSkia* context, const AffineTransform& transform, const SkRect& fillRect, const SkPaint& paint, const SkBitmap* bitmap)
    151151{
    152152    // Any stroking may put alpha in pixels even if the filling part does not.
     
    170170}
    171171
    172 void OpaqueRegionSkia::didDrawPath(const PlatformContextSkia* context, const AffineTransform& transform, const SkPath& path, const SkPaint& paint)
     172void OpaqueRegionSkia::didDrawPath(PlatformContextSkia* context, const AffineTransform& transform, const SkPath& path, const SkPaint& paint)
    173173{
    174174    SkRect rect;
     
    189189}
    190190
    191 void OpaqueRegionSkia::didDrawPoints(const PlatformContextSkia* context, const AffineTransform& transform, SkCanvas::PointMode mode, int numPoints, const SkPoint points[], const SkPaint& paint)
     191void OpaqueRegionSkia::didDrawPoints(PlatformContextSkia* context, const AffineTransform& transform, SkCanvas::PointMode mode, int numPoints, const SkPoint points[], const SkPaint& paint)
    192192{
    193193    if (!numPoints)
     
    218218}
    219219
    220 void OpaqueRegionSkia::didDrawBounded(const PlatformContextSkia* context, const AffineTransform& transform, const SkRect& bounds, const SkPaint& paint)
     220void OpaqueRegionSkia::didDrawBounded(PlatformContextSkia* context, const AffineTransform& transform, const SkRect& bounds, const SkPaint& paint)
    221221{
    222222    bool opaque = paintIsOpaque(paint);
     
    232232}
    233233
    234 void OpaqueRegionSkia::didDraw(const PlatformContextSkia* context, const AffineTransform& transform, const SkRect& rect, const SkPaint& paint, bool drawsOpaque, bool fillsBounds)
     234void OpaqueRegionSkia::didDraw(PlatformContextSkia* context, const AffineTransform& transform, const SkRect& rect, const SkPaint& paint, bool drawsOpaque, bool fillsBounds)
    235235{
    236236    SkRect targetRect = rect;
     237
     238    bool xfersOpaque = xfermodeIsOpaque(paint, drawsOpaque);
     239    bool preservesOpaque = xfermodePreservesOpaque(paint, drawsOpaque);
    237240
    238241    // Apply the transform to device coordinate space.
     
    250253            return;
    251254    }
    252     if (!context->clippedToImage().isOpaque())
    253         fillsBounds = false;
     255
     256    // Apply any layers that we are drawing into.
     257    for (SkCanvas::LayerIter it(context->canvas(), false); !it.done(); it.next()) {
     258        // Apply the layer's clip (which is in device space)
     259        const SkRegion& deviceLayerClip = it.clip();
     260        if (deviceLayerClip.isEmpty() || !deviceLayerClip.isRect())
     261            fillsBounds = false;
     262        else {
     263            SkIRect clipBounds = it.clip().getBounds();
     264            if (!targetRect.intersect(SkIntToScalar(clipBounds.fLeft), SkIntToScalar(clipBounds.fTop), SkIntToScalar(clipBounds.fRight), SkIntToScalar(clipBounds.fBottom)))
     265                return;
     266        }
     267
     268        // Make sure the paint stays opaque through the layer.
     269        bool drawsOpaque = paintIsOpaque(it.paint());
     270        xfersOpaque = xfersOpaque && xfermodeIsOpaque(it.paint(), drawsOpaque);
     271        preservesOpaque = preservesOpaque && xfermodePreservesOpaque(it.paint(), drawsOpaque);
     272    }
    254273
    255274    // Apply the transform to the tracking space.
     
    258277        fillsBounds = false;
    259278
    260     if (fillsBounds && xfermodeIsOpaque(paint, drawsOpaque))
     279    if (fillsBounds && xfersOpaque)
    261280        markRectAsOpaque(targetRect);
    262     else if (SkRect::Intersects(targetRect, m_opaqueRect) && !xfermodePreservesOpaque(paint, drawsOpaque))
     281    else if (SkRect::Intersects(targetRect, m_opaqueRect) && !preservesOpaque)
    263282        markRectAsNonOpaque(targetRect);
    264283}
     
    340359}
    341360
     361
    342362} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/skia/OpaqueRegionSkia.h

    r107143 r109514  
    5454    IntRect asRect() const;
    5555
    56     void didDrawRect(const PlatformContextSkia*, const AffineTransform&, const SkRect&, const SkPaint&, const SkBitmap*);
    57     void didDrawPath(const PlatformContextSkia*, const AffineTransform&, const SkPath&, const SkPaint&);
    58     void didDrawPoints(const PlatformContextSkia*, const AffineTransform&, SkCanvas::PointMode, int numPoints, const SkPoint[], const SkPaint&);
    59     void didDrawBounded(const PlatformContextSkia*, const AffineTransform&, const SkRect&, const SkPaint&);
     56    // FIXME: make all the PlatformContextSkia* into a const pointer when Skia fixes LayerIter's SkCanvas*.
     57
     58    void didDrawRect(PlatformContextSkia*, const AffineTransform&, const SkRect&, const SkPaint&, const SkBitmap*);
     59    void didDrawPath(PlatformContextSkia*, const AffineTransform&, const SkPath&, const SkPaint&);
     60    void didDrawPoints(PlatformContextSkia*, const AffineTransform&, SkCanvas::PointMode, int numPoints, const SkPoint[], const SkPaint&);
     61    void didDrawBounded(PlatformContextSkia*, const AffineTransform&, const SkRect&, const SkPaint&);
    6062
    6163private:
    62     void didDraw(const PlatformContextSkia*, const AffineTransform&, const SkRect&, const SkPaint&, bool drawsOpaque, bool fillsBounds);
     64    void didDraw(PlatformContextSkia*, const AffineTransform&, const SkRect&, const SkPaint&, bool drawsOpaque, bool fillsBounds);
    6365    void didDrawUnbounded(const SkPaint&, bool drawsOpaque);
    6466    void markRectAsOpaque(const SkRect&);
  • trunk/Source/WebCore/platform/graphics/skia/PlatformContextSkia.cpp

    r109016 r109514  
    266266{
    267267    canvas()->clipPath(clipPath, SkRegion::kIntersect_Op, true);
    268 }
    269 
    270 const SkBitmap& PlatformContextSkia::clippedToImage() const
    271 {
    272     return m_state->m_imageBufferClip;
    273268}
    274269
  • trunk/Source/WebCore/platform/graphics/skia/PlatformContextSkia.h

    r107143 r109514  
    101101    void beginLayerClippedToImage(const FloatRect&, const ImageBuffer*);
    102102    void clipPathAntiAliased(const SkPath&);
    103     // If non-empty, the layer is clipped to the bitmap.
    104     const SkBitmap& clippedToImage() const;
    105103
    106104    // Sets up the common flags on a paint for antialiasing, effects, etc.
  • trunk/Source/WebKit/chromium/ChangeLog

    r109512 r109514  
     12012-03-01  Dana Jansens  <danakj@chromium.org>
     2
     3        [chromium] Make opaque paint tracker aware of SkCanvas layers
     4        https://bugs.webkit.org/show_bug.cgi?id=79145
     5
     6        Reviewed by Stephen White.
     7
     8        * tests/PlatformContextSkiaTest.cpp:
     9        (WebCore::TEST):
     10        (WebCore):
     11
    1122012-03-01  Hironori Bono  <hbono@chromium.org>
    213
  • trunk/Source/WebKit/chromium/tests/PlatformContextSkiaTest.cpp

    r107988 r109514  
    642642}
    643643
     644TEST(PlatformContextSkiaTest, contextTransparencyLayerTest)
     645{
     646    SkBitmap bitmap;
     647    bitmap.setConfig(SkBitmap::kARGB_8888_Config, 400, 400);
     648    bitmap.allocPixels();
     649    bitmap.eraseColor(0);
     650    SkCanvas canvas(bitmap);
     651    AffineTransform transform;
     652    transform.scale(2);
     653
     654    PlatformContextSkia platformContext(&canvas);
     655    platformContext.setTrackOpaqueRegion(true);
     656    platformContext.setOpaqueRegionTransform(transform);
     657    GraphicsContext context(&platformContext);
     658   
     659    Color opaque(1.0f, 0.0f, 0.0f, 1.0f);
     660   
     661    context.fillRect(FloatRect(20, 20, 10, 10), opaque, ColorSpaceDeviceRGB, CompositeSourceOver);
     662    EXPECT_EQ_RECT(IntRect(40, 40, 20, 20), platformContext.opaqueRegion().asRect());
     663    EXPECT_PIXELS_MATCH(bitmap, transform.inverse().mapRect(platformContext.opaqueRegion().asRect()));
     664   
     665    context.clearRect(FloatRect(20, 20, 10, 10));
     666    EXPECT_EQ_RECT(IntRect(), platformContext.opaqueRegion().asRect());
     667
     668    context.beginTransparencyLayer(0.5);
     669    context.save();
     670    context.fillRect(FloatRect(20, 20, 10, 10), opaque, ColorSpaceDeviceRGB, CompositeSourceOver);
     671    context.restore();
     672    context.endTransparencyLayer();
     673    EXPECT_EQ_RECT(IntRect(), platformContext.opaqueRegion().asRect());
     674
     675    context.clearRect(FloatRect(20, 20, 10, 10));
     676    EXPECT_EQ_RECT(IntRect(), platformContext.opaqueRegion().asRect());
     677
     678    context.beginTransparencyLayer(0.5);
     679    context.fillRect(FloatRect(20, 20, 10, 10), opaque, ColorSpaceDeviceRGB, CompositeSourceOver);
     680    context.endTransparencyLayer();
     681    EXPECT_EQ_RECT(IntRect(), platformContext.opaqueRegion().asRect());
     682}
     683
    644684} // namespace
Note: See TracChangeset for help on using the changeset viewer.