Changeset 104861 in webkit


Ignore:
Timestamp:
Jan 12, 2012 2:39:25 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[skia] Track a simple opaque area when painting via PlatformContextSkia and save in LayerTextureUpdater
https://bugs.webkit.org/show_bug.cgi?id=74352

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

Source/WebCore:

New unit tests in PlatformContextSkiaTest.cpp

  • WebCore.gypi:
  • platform/graphics/skia/GraphicsContextSkia.cpp:

(WebCore::GraphicsContext::clearRect):
(WebCore::GraphicsContext::drawConvexPolygon):
(WebCore::GraphicsContext::drawEllipse):
(WebCore::drawOuterPath):
(WebCore::drawInnerPath):
(WebCore::GraphicsContext::drawFocusRing):
(WebCore::GraphicsContext::drawLine):
(WebCore::GraphicsContext::drawLineForTextChecking):
(WebCore::GraphicsContext::drawLineForText):
(WebCore::GraphicsContext::fillPath):
(WebCore::GraphicsContext::fillRect):
(WebCore::GraphicsContext::fillRoundedRect):
(WebCore::GraphicsContext::strokeArc):
(WebCore::GraphicsContext::strokePath):
(WebCore::GraphicsContext::strokeRect):

  • platform/graphics/skia/ImageSkia.cpp:

(WebCore::paintSkBitmap):

  • platform/graphics/skia/OpaqueRegionSkia.cpp: Added.

(WebCore::OpaqueRegionSkia::OpaqueRegionSkia):
(WebCore::OpaqueRegionSkia::~OpaqueRegionSkia):
(WebCore::OpaqueRegionSkia::asRect):
(WebCore::xfermodeIsOpaque):
(WebCore::xfermodePreservesOpaque):
(WebCore::paintIsOpaque):
(WebCore::OpaqueRegionSkia::didDrawRect):
(WebCore::OpaqueRegionSkia::didDrawPath):
(WebCore::OpaqueRegionSkia::didDrawPoints):
(WebCore::OpaqueRegionSkia::didDrawBounded):
(WebCore::OpaqueRegionSkia::didDraw):
(WebCore::OpaqueRegionSkia::didDrawUnbounded):
(WebCore::OpaqueRegionSkia::markRectAsOpaque):
(WebCore::OpaqueRegionSkia::markRectAsNonOpaque):

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

(WebCore::PlatformContextSkia::PlatformContextSkia):
(WebCore::PlatformContextSkia::clippedToImage):
(WebCore::PlatformContextSkia::drawRect):
(WebCore::PlatformContextSkia::paintSkPaint):
(WebCore::PlatformContextSkia::didDrawRect):
(WebCore::PlatformContextSkia::didDrawPath):
(WebCore::PlatformContextSkia::didDrawPoints):
(WebCore::PlatformContextSkia::didDrawBounded):

  • platform/graphics/skia/PlatformContextSkia.h:

(WebCore::PlatformContextSkia::setTrackOpaqueRegion):
(WebCore::PlatformContextSkia::opaqueRegion):

Source/WebKit/chromium:

  • WebKit.gypi:
  • tests/PlatformContextSkiaTest.cpp: Added.

(WebCore::TEST):

Location:
trunk/Source
Files:
3 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r104860 r104861  
     12012-01-12  Dana Jansens  <danakj@chromium.org>
     2
     3        [skia] Track a simple opaque area when painting via PlatformContextSkia and save in LayerTextureUpdater
     4        https://bugs.webkit.org/show_bug.cgi?id=74352
     5
     6        Reviewed by Stephen White.
     7
     8        New unit tests in PlatformContextSkiaTest.cpp
     9
     10        * WebCore.gypi:
     11        * platform/graphics/skia/GraphicsContextSkia.cpp:
     12        (WebCore::GraphicsContext::clearRect):
     13        (WebCore::GraphicsContext::drawConvexPolygon):
     14        (WebCore::GraphicsContext::drawEllipse):
     15        (WebCore::drawOuterPath):
     16        (WebCore::drawInnerPath):
     17        (WebCore::GraphicsContext::drawFocusRing):
     18        (WebCore::GraphicsContext::drawLine):
     19        (WebCore::GraphicsContext::drawLineForTextChecking):
     20        (WebCore::GraphicsContext::drawLineForText):
     21        (WebCore::GraphicsContext::fillPath):
     22        (WebCore::GraphicsContext::fillRect):
     23        (WebCore::GraphicsContext::fillRoundedRect):
     24        (WebCore::GraphicsContext::strokeArc):
     25        (WebCore::GraphicsContext::strokePath):
     26        (WebCore::GraphicsContext::strokeRect):
     27        * platform/graphics/skia/ImageSkia.cpp:
     28        (WebCore::paintSkBitmap):
     29        * platform/graphics/skia/OpaqueRegionSkia.cpp: Added.
     30        (WebCore::OpaqueRegionSkia::OpaqueRegionSkia):
     31        (WebCore::OpaqueRegionSkia::~OpaqueRegionSkia):
     32        (WebCore::OpaqueRegionSkia::asRect):
     33        (WebCore::xfermodeIsOpaque):
     34        (WebCore::xfermodePreservesOpaque):
     35        (WebCore::paintIsOpaque):
     36        (WebCore::OpaqueRegionSkia::didDrawRect):
     37        (WebCore::OpaqueRegionSkia::didDrawPath):
     38        (WebCore::OpaqueRegionSkia::didDrawPoints):
     39        (WebCore::OpaqueRegionSkia::didDrawBounded):
     40        (WebCore::OpaqueRegionSkia::didDraw):
     41        (WebCore::OpaqueRegionSkia::didDrawUnbounded):
     42        (WebCore::OpaqueRegionSkia::markRectAsOpaque):
     43        (WebCore::OpaqueRegionSkia::markRectAsNonOpaque):
     44        * platform/graphics/skia/OpaqueRegionSkia.h: Added.
     45        * platform/graphics/skia/PlatformContextSkia.cpp:
     46        (WebCore::PlatformContextSkia::PlatformContextSkia):
     47        (WebCore::PlatformContextSkia::clippedToImage):
     48        (WebCore::PlatformContextSkia::drawRect):
     49        (WebCore::PlatformContextSkia::paintSkPaint):
     50        (WebCore::PlatformContextSkia::didDrawRect):
     51        (WebCore::PlatformContextSkia::didDrawPath):
     52        (WebCore::PlatformContextSkia::didDrawPoints):
     53        (WebCore::PlatformContextSkia::didDrawBounded):
     54        * platform/graphics/skia/PlatformContextSkia.h:
     55        (WebCore::PlatformContextSkia::setTrackOpaqueRegion):
     56        (WebCore::PlatformContextSkia::opaqueRegion):
     57
    1582012-01-12  Beth Dakin  <bdakin@apple.com>
    259
  • trunk/Source/WebCore/WebCore.gypi

    r104848 r104861  
    39293929            'platform/graphics/skia/NativeImageSkia.cpp',
    39303930            'platform/graphics/skia/NativeImageSkia.h',
     3931            'platform/graphics/skia/OpaqueRegionSkia.cpp',
     3932            'platform/graphics/skia/OpaqueRegionSkia.h',
    39313933            'platform/graphics/skia/PathSkia.cpp',
    39323934            'platform/graphics/skia/PatternSkia.cpp',
  • trunk/Source/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp

    r104609 r104861  
    340340    paint.setXfermodeMode(SkXfermode::kClear_Mode);
    341341    platformContext()->canvas()->drawRect(r, paint);
     342    platformContext()->didDrawRect(r, paint);
    342343}
    343344
     
    474475    paint.setAntiAlias(shouldAntialias);
    475476    platformContext()->canvas()->drawPath(path, paint);
     477    platformContext()->didDrawPath(path, paint);
    476478
    477479    if (strokeStyle() != NoStroke) {
     
    479481        platformContext()->setupPaintForStroking(&paint, 0, 0);
    480482        platformContext()->canvas()->drawPath(path, paint);
     483        platformContext()->didDrawPath(path, paint);
    481484    }
    482485}
     
    514517    platformContext()->setupPaintForFilling(&paint);
    515518    platformContext()->canvas()->drawOval(rect, paint);
     519    platformContext()->didDrawBounded(rect, paint);
    516520
    517521    if (strokeStyle() != NoStroke) {
     
    519523        platformContext()->setupPaintForStroking(&paint, &rect, 0);
    520524        platformContext()->canvas()->drawOval(rect, paint);
     525        platformContext()->didDrawBounded(rect, paint);
    521526    }
    522527}
     
    527532}
    528533
    529 static inline void drawOuterPath(SkCanvas* canvas, const SkPath& path, SkPaint& paint, int width)
     534static inline void drawOuterPath(PlatformContextSkia* context, const SkPath& path, SkPaint& paint, int width)
    530535{
    531536#if PLATFORM(CHROMIUM) && OS(DARWIN)
     
    537542    paint.setPathEffect(new SkCornerPathEffect(1))->unref();
    538543#endif
    539     canvas->drawPath(path, paint);
    540 }
    541 
    542 static inline void drawInnerPath(SkCanvas* canvas, const SkPath& path, SkPaint& paint, int width)
     544    context->canvas()->drawPath(path, paint);
     545    context->didDrawPath(path, paint);
     546}
     547
     548static inline void drawInnerPath(PlatformContextSkia* context, const SkPath& path, SkPaint& paint, int width)
    543549{
    544550#if PLATFORM(CHROMIUM) && OS(DARWIN)
    545551    paint.setAlpha(128);
    546552    paint.setStrokeWidth(width * 0.5f);
    547     canvas->drawPath(path, paint);
     553    context->canvas()->drawPath(path, paint);
     554    context->didDrawPath(path, paint);
    548555#endif
    549556}
     
    582589    paint.setColor(color.rgb());
    583590    focusRingRegion.getBoundaryPath(&path);
    584     SkCanvas* canvas = platformContext()->canvas();
    585     drawOuterPath(canvas, path, paint, width);
    586     drawInnerPath(canvas, path, paint, width);
     591    drawOuterPath(platformContext(), path, paint, width);
     592    drawInnerPath(platformContext(), path, paint, width);
    587593}
    588594
     
    632638        platformContext()->canvas()->drawRect(r1, fillPaint);
    633639        platformContext()->canvas()->drawRect(r2, fillPaint);
     640        platformContext()->didDrawRect(r1, fillPaint);
     641        platformContext()->didDrawRect(r2, fillPaint);
    634642    }
    635643
     
    638646
    639647    platformContext()->canvas()->drawPoints(SkCanvas::kLines_PointMode, 2, pts, paint);
     648    platformContext()->didDrawPoints(SkCanvas::kLines_PointMode, 2, pts, paint);
    640649}
    641650
     
    713722             originY + SkIntToScalar(misspellBitmap->height()));
    714723    platformContext()->canvas()->drawRect(rect, paint);
     724    platformContext()->didDrawRect(rect, paint);
    715725}
    716726
     
    737747    paint.setColor(platformContext()->effectiveStrokeColor());
    738748    platformContext()->canvas()->drawRect(r, paint);
     749    platformContext()->didDrawRect(r, paint);
    739750}
    740751
     
    771782
    772783    platformContext()->canvas()->drawPath(path, paint);
     784    platformContext()->didDrawPath(path, paint);
    773785}
    774786
     
    789801    platformContext()->setupPaintForFilling(&paint);
    790802    platformContext()->canvas()->drawRect(r, paint);
     803    platformContext()->didDrawRect(r, paint);
    791804
    792805    platformContext()->restore();
     
    817830    paint.setColor(color.rgb());
    818831    platformContext()->canvas()->drawRect(r, paint);
     832    platformContext()->didDrawRect(r, paint);
    819833}
    820834
     
    856870    paint.setColor(color.rgb());
    857871    platformContext()->canvas()->drawPath(path, paint);
     872    platformContext()->didDrawPath(path, paint);
    858873}
    859874
     
    11401155        return;
    11411156    platformContext()->canvas()->drawPath(path, paint);
     1157    platformContext()->didDrawPath(path, paint);
    11421158}
    11431159
     
    11541170    platformContext()->setupPaintForStroking(&paint, 0, 0);
    11551171    platformContext()->canvas()->drawPath(path, paint);
     1172    platformContext()->didDrawPath(path, paint);
    11561173}
    11571174
     
    11741191    bool validH = r.height() > 0;
    11751192    SkCanvas* canvas = platformContext()->canvas();
    1176     if (validW && validH)
     1193    if (validW && validH) {
    11771194        canvas->drawRect(r, paint);
    1178     else if (validW || validH) {
     1195        platformContext()->didDrawRect(r, paint);
     1196    } else if (validW || validH) {
    11791197        // we are expected to respect the lineJoin, so we can't just call
    11801198        // drawLine -- we have to create a path that doubles back on itself.
     
    11841202        path.close();
    11851203        canvas->drawPath(path, paint);
     1204        platformContext()->didDrawPath(path, paint);
    11861205    }
    11871206}
  • trunk/Source/WebCore/platform/graphics/skia/ImageSkia.cpp

    r103041 r104861  
    249249        canvas->drawBitmapRect(bitmap.bitmap(), &srcRect, destRect, &paint);
    250250    }
     251    platformContext->didDrawRect(destRect, paint, &bitmap.bitmap());
    251252}
    252253
  • trunk/Source/WebCore/platform/graphics/skia/PlatformContextSkia.cpp

    r103091 r104861  
    180180PlatformContextSkia::PlatformContextSkia(SkCanvas* canvas)
    181181    : m_canvas(canvas)
     182    , m_trackOpaqueRegion(false)
    182183    , m_printing(false)
    183184    , m_deferred(false)
     
    267268}
    268269
     270const SkBitmap& PlatformContextSkia::clippedToImage() const
     271{
     272    return m_state->m_imageBufferClip;
     273}
     274
    269275void PlatformContextSkia::restore()
    270276{
     
    288294        setupPaintForFilling(&paint);
    289295        canvas()->drawRect(rect, paint);
     296        didDrawRect(rect, paint);
    290297    }
    291298
     
    300307        SkRect topBorder = { rect.fLeft, rect.fTop, rect.fRight, rect.fTop + 1 };
    301308        canvas()->drawRect(topBorder, paint);
     309        didDrawRect(topBorder, paint);
    302310        SkRect bottomBorder = { rect.fLeft, rect.fBottom - 1, rect.fRight, rect.fBottom };
    303311        canvas()->drawRect(bottomBorder, paint);
     312        didDrawRect(bottomBorder, paint);
    304313        SkRect leftBorder = { rect.fLeft, rect.fTop + 1, rect.fLeft + 1, rect.fBottom - 1 };
    305314        canvas()->drawRect(leftBorder, paint);
     315        didDrawRect(leftBorder, paint);
    306316        SkRect rightBorder = { rect.fRight - 1, rect.fTop + 1, rect.fRight, rect.fBottom - 1 };
    307317        canvas()->drawRect(rightBorder, paint);
     318        didDrawRect(rightBorder, paint);
    308319    }
    309320}
     
    540551{
    541552    m_canvas->drawRect(rect, paint);
     553    didDrawRect(rect, paint);
    542554}
    543555
     
    598610}
    599611
     612void PlatformContextSkia::didDrawRect(const SkRect& rect, const SkPaint& paint, const SkBitmap* bitmap)
     613{
     614    if (m_trackOpaqueRegion)
     615        m_opaqueRegion.didDrawRect(this, rect, paint, bitmap);
     616}
     617
     618void PlatformContextSkia::didDrawPath(const SkPath& path, const SkPaint& paint)
     619{
     620    if (m_trackOpaqueRegion)
     621        m_opaqueRegion.didDrawPath(this, path, paint);
     622}
     623
     624void PlatformContextSkia::didDrawPoints(SkCanvas::PointMode mode, int numPoints, const SkPoint points[], const SkPaint& paint)
     625{
     626    if (m_trackOpaqueRegion)
     627        m_opaqueRegion.didDrawPoints(this, mode, numPoints, points, paint);
     628}
     629
     630void PlatformContextSkia::didDrawBounded(const SkRect& rect, const SkPaint& paint)
     631{
     632    if (m_trackOpaqueRegion)
     633        m_opaqueRegion.didDrawBounded(this, rect, paint);
     634}
     635
    600636} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/skia/PlatformContextSkia.h

    r103091 r104861  
    3434#include "GraphicsContext.h"
    3535#include "Noncopyable.h"
     36#include "OpaqueRegionSkia.h"
    3637
    3738#include "SkCanvas.h"
     
    99100    void beginLayerClippedToImage(const FloatRect&, const ImageBuffer*);
    100101    void clipPathAntiAliased(const SkPath&);
     102    // If non-empty, the layer is clipped to the bitmap.
     103    const SkBitmap& clippedToImage() const;
    101104
    102105    // Sets up the common flags on a paint for antialiasing, effects, etc.
     
    188191    void setDeferred(bool deferred) { m_deferred = deferred; }
    189192
     193    void setTrackOpaqueRegion(bool track) { m_trackOpaqueRegion = track; }
     194
     195    // This will be an empty region unless tracking is enabled.
     196    const OpaqueRegionSkia& opaqueRegion() const { return m_opaqueRegion; }
     197
     198    // After drawing in the context's canvas, use these functions to notify the context so it can track the opaque region.
     199    void didDrawRect(const SkRect&, const SkPaint&, const SkBitmap* = 0);
     200    void didDrawPath(const SkPath&, const SkPaint&);
     201    void didDrawPoints(SkCanvas::PointMode, int numPoints, const SkPoint[], const SkPaint&);
     202    // For drawing operations that do not fill the entire rect.
     203    void didDrawBounded(const SkRect&, const SkPaint&);
     204
    190205private:
    191206    // Used when restoring and the state has an image clip. Only shows the pixels in
     
    210225    // mStateStack.back().
    211226    State* m_state;
     227
     228    // Tracks the region painted opaque via the GraphicsContext.
     229    OpaqueRegionSkia m_opaqueRegion;
     230    bool m_trackOpaqueRegion;
    212231
    213232    // Stores image sizes for a hint to compute image resampling modes.
  • trunk/Source/WebKit/chromium/ChangeLog

    r104844 r104861  
     12012-01-12  Dana Jansens  <danakj@chromium.org>
     2
     3        [skia] Track a simple opaque area when painting via PlatformContextSkia and save in LayerTextureUpdater
     4        https://bugs.webkit.org/show_bug.cgi?id=74352
     5
     6        Reviewed by Stephen White.
     7
     8        * WebKit.gypi:
     9        * tests/PlatformContextSkiaTest.cpp: Added.
     10        (WebCore::TEST):
     11
    1122012-01-12  Nat Duca  <nduca@chromium.org>
    213
  • trunk/Source/WebKit/chromium/WebKit.gypi

    r104626 r104861  
    120120                    'tests/DragImageTest.cpp',
    121121                    'tests/ImageLayerChromiumTest.cpp',
     122                    'tests/PlatformContextSkiaTest.cpp',
    122123                ],
    123124            }],
Note: See TracChangeset for help on using the changeset viewer.