Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
2010-07-28 Stephen White <senorblanco@chromium.org>
        Reviewed by Darin Fisher.

        Hook the GLES2 rendering path up to GraphicsContextSkia.
        https://bugs.webkit.org/show_bug.cgi?id=43119

        This connects the state-setting and drawing calls implemented in
        so far in GLES2Canvas, and calls PlatformContextSkia's
        prepareForSoftwareDraw() for all the non-accelerated paths.

        * platform/graphics/skia/GraphicsContextSkia.cpp:
        (WebCore::GraphicsContext::addInnerRoundedRectClip):
        (WebCore::GraphicsContext::addPath):
        (WebCore::GraphicsContext::beginPath):
        (WebCore::GraphicsContext::clip):
        (WebCore::GraphicsContext::drawConvexPolygon):
        (WebCore::GraphicsContext::drawEllipse):
        (WebCore::GraphicsContext::drawFocusRing):
        (WebCore::GraphicsContext::drawLine):
        (WebCore::GraphicsContext::drawLineForMisspellingOrBadGrammar):
        (WebCore::GraphicsContext::drawLineForText):
        (WebCore::GraphicsContext::drawRect):
        (WebCore::GraphicsContext::fillPath):
        (WebCore::GraphicsContext::fillRoundedRect):
        (WebCore::GraphicsContext::strokeArc):
        (WebCore::GraphicsContext::strokePath):
        (WebCore::GraphicsContext::strokeRect):
        These calls are software-only; call preSoftwareDraw() for these.
        (WebCore::GraphicsContext::savePlatformState):
        (WebCore::GraphicsContext::restorePlatformState):
        (WebCore::GraphicsContext::setAlpha):
        (WebCore::GraphicsContext::setCompositeOperation):
        (WebCore::GraphicsContext::setPlatformFillColor):
        (WebCore::GraphicsContext::scale):
        (WebCore::GraphicsContext::rotate):
        (WebCore::GraphicsContext::translate):
        (WebCore::GraphicsContext::concatCTM):
        These ones set state on both Skia and GLES2Canvas.
        (WebCore::GraphicsContext::clearRect):
        (WebCore::GraphicsContext::fillRect):
        These ones have a GLES2 implementation; call through to it if PlatformContextSkia's useGPU() flag is set and the state permits.
        * platform/graphics/skia/PlatformContextSkia.cpp:
        (PlatformContextSkia::prepareForSoftwareDraw):
        (PlatformContextSkia::prepareForHardwareDraw):
        Rename preXXXDraw() -> prepareForXXXDraw().
        * platform/graphics/skia/PlatformContextSkia.h:
        (PlatformContextSkia::prepareForSoftwareDraw):
        (PlatformContextSkia::prepareForHardwareDraw):
        Rename preXXXDraw() -> prepareForXXXDraw().


Canonical link: https://commits.webkit.org/55051@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@64227 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
SenorBlanco committed Jul 28, 2010
1 parent 89bec7a commit 4b0e4f0
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 6 deletions.
51 changes: 51 additions & 0 deletions WebCore/ChangeLog
@@ -1,3 +1,54 @@
2010-07-28 Stephen White <senorblanco@chromium.org>

Reviewed by Darin Fisher.

Hook the GLES2 rendering path up to GraphicsContextSkia.
https://bugs.webkit.org/show_bug.cgi?id=43119

This connects the state-setting and drawing calls implemented in
so far in GLES2Canvas, and calls PlatformContextSkia's
prepareForSoftwareDraw() for all the non-accelerated paths.

* platform/graphics/skia/GraphicsContextSkia.cpp:
(WebCore::GraphicsContext::addInnerRoundedRectClip):
(WebCore::GraphicsContext::addPath):
(WebCore::GraphicsContext::beginPath):
(WebCore::GraphicsContext::clip):
(WebCore::GraphicsContext::drawConvexPolygon):
(WebCore::GraphicsContext::drawEllipse):
(WebCore::GraphicsContext::drawFocusRing):
(WebCore::GraphicsContext::drawLine):
(WebCore::GraphicsContext::drawLineForMisspellingOrBadGrammar):
(WebCore::GraphicsContext::drawLineForText):
(WebCore::GraphicsContext::drawRect):
(WebCore::GraphicsContext::fillPath):
(WebCore::GraphicsContext::fillRoundedRect):
(WebCore::GraphicsContext::strokeArc):
(WebCore::GraphicsContext::strokePath):
(WebCore::GraphicsContext::strokeRect):
These calls are software-only; call preSoftwareDraw() for these.
(WebCore::GraphicsContext::savePlatformState):
(WebCore::GraphicsContext::restorePlatformState):
(WebCore::GraphicsContext::setAlpha):
(WebCore::GraphicsContext::setCompositeOperation):
(WebCore::GraphicsContext::setPlatformFillColor):
(WebCore::GraphicsContext::scale):
(WebCore::GraphicsContext::rotate):
(WebCore::GraphicsContext::translate):
(WebCore::GraphicsContext::concatCTM):
These ones set state on both Skia and GLES2Canvas.
(WebCore::GraphicsContext::clearRect):
(WebCore::GraphicsContext::fillRect):
These ones have a GLES2 implementation; call through to it if PlatformContextSkia's useGPU() flag is set and the state permits.
* platform/graphics/skia/PlatformContextSkia.cpp:
(PlatformContextSkia::prepareForSoftwareDraw):
(PlatformContextSkia::prepareForHardwareDraw):
Rename preXXXDraw() -> prepareForXXXDraw().
* platform/graphics/skia/PlatformContextSkia.h:
(PlatformContextSkia::prepareForSoftwareDraw):
(PlatformContextSkia::prepareForHardwareDraw):
Rename preXXXDraw() -> prepareForXXXDraw().

2010-07-28 fsamuel@chromium.org <fsamuel@chromium.org>

Reviewed by David Hyatt.
Expand Down
106 changes: 106 additions & 0 deletions WebCore/platform/graphics/skia/GraphicsContextSkia.cpp
Expand Up @@ -54,6 +54,10 @@
#include <wtf/Assertions.h>
#include <wtf/MathExtras.h>

#if USE(GLES2_RENDERING)
#include "GLES2Canvas.h"
#endif

using namespace std;

namespace WebCore {
Expand Down Expand Up @@ -243,6 +247,11 @@ void GraphicsContext::savePlatformState()
if (paintingDisabled())
return;

#if USE(GLES2_RENDERING)
if (platformContext()->useGPU())
platformContext()->gpuCanvas()->save();
#endif

// Save our private State.
platformContext()->save();
}
Expand All @@ -252,6 +261,11 @@ void GraphicsContext::restorePlatformState()
if (paintingDisabled())
return;

#if USE(GLES2_RENDERING)
if (platformContext()->useGPU())
platformContext()->gpuCanvas()->restore();
#endif

// Restore our private State.
platformContext()->restore();
}
Expand Down Expand Up @@ -290,6 +304,7 @@ void GraphicsContext::addInnerRoundedRectClip(const IntRect& rect, int thickness
if (!isRectSkiaSafe(getCTM(), r))
return;

platformContext()->prepareForSoftwareDraw();
SkPath path;
path.addOval(r, SkPath::kCW_Direction);
// only perform the inset if we won't invert r
Expand All @@ -307,13 +322,15 @@ void GraphicsContext::addPath(const Path& path)
{
if (paintingDisabled())
return;
platformContext()->prepareForSoftwareDraw();
platformContext()->addPath(*path.platformPath());
}

void GraphicsContext::beginPath()
{
if (paintingDisabled())
return;
platformContext()->prepareForSoftwareDraw();
platformContext()->beginPath();
}

Expand All @@ -329,6 +346,16 @@ void GraphicsContext::clearRect(const FloatRect& rect)
if (paintingDisabled())
return;

#if USE(GLES2_RENDERING)
if (platformContext()->useGPU()) {
platformContext()->prepareForHardwareDraw();
platformContext()->gpuCanvas()->clearRect(rect);
return;
}
#endif

platformContext()->prepareForSoftwareDraw();

SkRect r = rect;
if (!isRectSkiaSafe(getCTM(), r))
ClipRectToCanvas(*platformContext()->canvas(), r, &r);
Expand All @@ -348,6 +375,7 @@ void GraphicsContext::clip(const FloatRect& rect)
if (!isRectSkiaSafe(getCTM(), r))
return;

platformContext()->prepareForSoftwareDraw();
platformContext()->canvas()->clipRect(r);
}

Expand All @@ -360,6 +388,7 @@ void GraphicsContext::clip(const Path& path)
if (!isPathSkiaSafe(getCTM(), p))
return;

platformContext()->prepareForSoftwareDraw();
platformContext()->clipPathAntiAliased(p);
}

Expand Down Expand Up @@ -441,6 +470,12 @@ void GraphicsContext::concatCTM(const AffineTransform& affine)
{
if (paintingDisabled())
return;

#if USE(GLES2_RENDERING)
if (platformContext()->useGPU())
platformContext()->gpuCanvas()->concatCTM(affine);
#endif

platformContext()->canvas()->concat(affine);
}

Expand All @@ -454,6 +489,8 @@ void GraphicsContext::drawConvexPolygon(size_t numPoints,
if (numPoints <= 1)
return;

platformContext()->prepareForSoftwareDraw();

SkPath path;

path.incReserve(numPoints);
Expand Down Expand Up @@ -499,6 +536,7 @@ void GraphicsContext::drawEllipse(const IntRect& elipseRect)
if (!isRectSkiaSafe(getCTM(), rect))
return;

platformContext()->prepareForSoftwareDraw();
SkPaint paint;
platformContext()->setupPaintForFilling(&paint);
platformContext()->canvas()->drawOval(rect, paint);
Expand All @@ -524,6 +562,7 @@ void GraphicsContext::drawFocusRing(const Vector<IntRect>& rects, int /* width *
if (!rectCount)
return;

platformContext()->prepareForSoftwareDraw();
SkRegion focusRingRegion;
const SkScalar focusRingOutset = WebCoreFloatToSkScalar(0.5);
for (unsigned i = 0; i < rectCount; i++) {
Expand Down Expand Up @@ -558,6 +597,8 @@ void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2)
if (!isPointSkiaSafe(getCTM(), point1) || !isPointSkiaSafe(getCTM(), point2))
return;

platformContext()->prepareForSoftwareDraw();

FloatPoint p1 = point1;
FloatPoint p2 = point2;
bool isVerticalLine = (p1.x() == p2.x());
Expand Down Expand Up @@ -604,6 +645,8 @@ void GraphicsContext::drawLineForMisspellingOrBadGrammar(const IntPoint& pt,
if (paintingDisabled())
return;

platformContext()->prepareForSoftwareDraw();

// Create the pattern we'll use to draw the underline.
static SkBitmap* misspellBitmap = 0;
if (!misspellBitmap) {
Expand Down Expand Up @@ -684,6 +727,8 @@ void GraphicsContext::drawLineForText(const IntPoint& pt,
if (width <= 0)
return;

platformContext()->prepareForSoftwareDraw();

int thickness = SkMax32(static_cast<int>(strokeThickness()), 1);
SkRect r;
r.fLeft = SkIntToScalar(pt.x());
Expand All @@ -704,6 +749,8 @@ void GraphicsContext::drawRect(const IntRect& rect)
if (paintingDisabled())
return;

platformContext()->prepareForSoftwareDraw();

SkRect r = rect;
if (!isRectSkiaSafe(getCTM(), r)) {
// See the fillRect below.
Expand All @@ -722,6 +769,8 @@ void GraphicsContext::fillPath()
if (!isPathSkiaSafe(getCTM(), path))
return;

platformContext()->prepareForSoftwareDraw();

const GraphicsContextState& state = m_common->state;
path.setFillType(state.fillRule == RULE_EVENODD ?
SkPath::kEvenOdd_FillType : SkPath::kWinding_FillType);
Expand All @@ -745,6 +794,16 @@ void GraphicsContext::fillRect(const FloatRect& rect)
ClipRectToCanvas(*platformContext()->canvas(), r, &r);
}

#if USE(GLES2_RENDERING)
if (platformContext()->useGPU() && !m_common->state.fillPattern && !m_common->state.fillGradient) {
platformContext()->prepareForHardwareDraw();
platformContext()->gpuCanvas()->fillRect(rect);
return;
}
#endif

platformContext()->prepareForSoftwareDraw();

SkPaint paint;
platformContext()->setupPaintForFilling(&paint);
platformContext()->canvas()->drawRect(r, paint);
Expand All @@ -757,6 +816,16 @@ void GraphicsContext::fillRect(const FloatRect& rect, const Color& color, ColorS
if (paintingDisabled())
return;

#if USE(GLES2_RENDERING)
if (platformContext()->useGPU() && !m_common->state.fillPattern && !m_common->state.fillGradient) {
platformContext()->prepareForHardwareDraw();
platformContext()->gpuCanvas()->fillRect(rect, color, colorSpace);
return;
}
#endif

platformContext()->prepareForSoftwareDraw();

SkRect r = rect;
if (!isRectSkiaSafe(getCTM(), r)) {
// Special case when the rectangle overflows fixed point. This is a
Expand Down Expand Up @@ -789,6 +858,8 @@ void GraphicsContext::fillRoundedRect(const IntRect& rect,
if (paintingDisabled())
return;

platformContext()->prepareForSoftwareDraw();

SkRect r = rect;
if (!isRectSkiaSafe(getCTM(), r))
// See fillRect().
Expand Down Expand Up @@ -872,6 +943,12 @@ void GraphicsContext::scale(const FloatSize& size)
{
if (paintingDisabled())
return;

#if USE(GLES2_RENDERING)
if (platformContext()->useGPU())
platformContext()->gpuCanvas()->scale(size);
#endif

platformContext()->canvas()->scale(WebCoreFloatToSkScalar(size.width()),
WebCoreFloatToSkScalar(size.height()));
}
Expand All @@ -880,13 +957,21 @@ void GraphicsContext::setAlpha(float alpha)
{
if (paintingDisabled())
return;
#if USE(GLES2_RENDERING)
if (platformContext()->useGPU())
platformContext()->gpuCanvas()->setAlpha(alpha);
#endif
platformContext()->setAlpha(alpha);
}

void GraphicsContext::setCompositeOperation(CompositeOperator op)
{
if (paintingDisabled())
return;
#if USE(GLES2_RENDERING)
if (platformContext()->useGPU())
platformContext()->gpuCanvas()->setCompositeOperation(op);
#endif
platformContext()->setXfermodeMode(WebCoreCompositeToSkiaComposite(op));
}

Expand Down Expand Up @@ -973,6 +1058,11 @@ void GraphicsContext::setPlatformFillColor(const Color& color, ColorSpace colorS
{
if (paintingDisabled())
return;
#if USE(GLES2_RENDERING)
if (platformContext()->useGPU())
platformContext()->gpuCanvas()->setFillColor(color, colorSpace);
#endif

platformContext()->setFillColor(color.rgb());
}

Expand Down Expand Up @@ -1102,6 +1192,8 @@ void GraphicsContext::strokeArc(const IntRect& r, int startAngle, int angleSpan)
if (paintingDisabled())
return;

platformContext()->prepareForSoftwareDraw();

SkPaint paint;
SkRect oval = r;
if (strokeStyle() == NoStroke) {
Expand Down Expand Up @@ -1133,6 +1225,8 @@ void GraphicsContext::strokePath()
if (!isPathSkiaSafe(getCTM(), path))
return;

platformContext()->prepareForSoftwareDraw();

SkPaint paint;
platformContext()->setupPaintForStroking(&paint, 0, 0);
platformContext()->canvas()->drawPath(path, paint);
Expand All @@ -1146,6 +1240,8 @@ void GraphicsContext::strokeRect(const FloatRect& rect, float lineWidth)
if (!isRectSkiaSafe(getCTM(), rect))
return;

platformContext()->prepareForSoftwareDraw();

SkPaint paint;
platformContext()->setupPaintForStroking(&paint, 0, 0);
paint.setStrokeWidth(WebCoreFloatToSkScalar(lineWidth));
Expand All @@ -1157,6 +1253,11 @@ void GraphicsContext::rotate(float angleInRadians)
if (paintingDisabled())
return;

#if USE(GLES2_RENDERING)
if (platformContext()->useGPU())
platformContext()->gpuCanvas()->rotate(angleInRadians);
#endif

platformContext()->canvas()->rotate(WebCoreFloatToSkScalar(
angleInRadians * (180.0f / 3.14159265f)));
}
Expand All @@ -1166,6 +1267,11 @@ void GraphicsContext::translate(float w, float h)
if (paintingDisabled())
return;

#if USE(GLES2_RENDERING)
if (platformContext()->useGPU())
platformContext()->gpuCanvas()->translate(w, h);
#endif

platformContext()->canvas()->translate(WebCoreFloatToSkScalar(w),
WebCoreFloatToSkScalar(h));
}
Expand Down
4 changes: 2 additions & 2 deletions WebCore/platform/graphics/skia/PlatformContextSkia.cpp
Expand Up @@ -682,7 +682,7 @@ void PlatformContextSkia::setGLES2Context(WebCore::GLES2Context* context, const
m_gpuCanvas = new WebCore::GLES2Canvas(context, size);
}

void PlatformContextSkia::preSoftwareDraw() const
void PlatformContextSkia::prepareForSoftwareDraw() const
{
if (!m_useGPU)
return;
Expand Down Expand Up @@ -724,7 +724,7 @@ void PlatformContextSkia::preSoftwareDraw() const
}
}

void PlatformContextSkia::preHardwareDraw() const
void PlatformContextSkia::prepareForHardwareDraw() const
{
if (!m_useGPU)
return;
Expand Down

0 comments on commit 4b0e4f0

Please sign in to comment.