summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/graphics/skia
diff options
context:
space:
mode:
authorFeng Qian <fqian@google.com>2009-06-17 12:12:20 -0700
committerFeng Qian <fqian@google.com>2009-06-17 12:12:20 -0700
commit5f1ab04193ad0130ca8204aadaceae083aca9881 (patch)
tree5a92cd389e2cfe7fb67197ce14b38469462379f8 /WebCore/platform/graphics/skia
parent194315e5a908cc8ed67d597010544803eef1ac59 (diff)
downloadexternal_webkit-5f1ab04193ad0130ca8204aadaceae083aca9881.zip
external_webkit-5f1ab04193ad0130ca8204aadaceae083aca9881.tar.gz
external_webkit-5f1ab04193ad0130ca8204aadaceae083aca9881.tar.bz2
Get WebKit r44544.
Diffstat (limited to 'WebCore/platform/graphics/skia')
-rw-r--r--WebCore/platform/graphics/skia/GradientSkia.cpp4
-rw-r--r--WebCore/platform/graphics/skia/GraphicsContextSkia.cpp40
-rw-r--r--WebCore/platform/graphics/skia/ImageBufferSkia.cpp1
-rw-r--r--WebCore/platform/graphics/skia/ImageSkia.cpp16
-rw-r--r--WebCore/platform/graphics/skia/PathSkia.cpp12
-rw-r--r--WebCore/platform/graphics/skia/PlatformContextSkia.cpp13
-rw-r--r--WebCore/platform/graphics/skia/PlatformContextSkia.h1
-rw-r--r--WebCore/platform/graphics/skia/SkiaFontWin.cpp12
-rw-r--r--WebCore/platform/graphics/skia/SkiaFontWin.h6
-rw-r--r--WebCore/platform/graphics/skia/SkiaUtils.cpp9
10 files changed, 70 insertions, 44 deletions
diff --git a/WebCore/platform/graphics/skia/GradientSkia.cpp b/WebCore/platform/graphics/skia/GradientSkia.cpp
index 2d2000c..ac7366c 100644
--- a/WebCore/platform/graphics/skia/GradientSkia.cpp
+++ b/WebCore/platform/graphics/skia/GradientSkia.cpp
@@ -60,12 +60,14 @@ static SkColor makeSkColor(float a, float r, float g, float b)
// ends as necessary.
static size_t totalStopsNeeded(const Gradient::ColorStop* stopData, size_t count)
{
+ // N.B.: The tests in this function should kept in sync with the ones in
+ // fillStops(), or badness happens.
const Gradient::ColorStop* stop = stopData;
size_t countUsed = count;
if (count < 1 || stop->stop > 0.0)
countUsed++;
stop += count - 1;
- if (count < 2 || stop->stop < 1.0)
+ if (count < 1 || stop->stop < 1.0)
countUsed++;
return countUsed;
}
diff --git a/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp b/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp
index 376fa4b..33ca23a 100644
--- a/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp
+++ b/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp
@@ -449,10 +449,8 @@ void GraphicsContext::drawConvexPolygon(size_t numPoints,
return;
SkPaint paint;
- if (fillColor().alpha() > 0) {
- platformContext()->setupPaintForFilling(&paint);
- platformContext()->canvas()->drawPath(path, paint);
- }
+ platformContext()->setupPaintForFilling(&paint);
+ platformContext()->canvas()->drawPath(path, paint);
if (strokeStyle() != NoStroke) {
paint.reset();
@@ -472,10 +470,8 @@ void GraphicsContext::drawEllipse(const IntRect& elipseRect)
return;
SkPaint paint;
- if (fillColor().alpha() > 0) {
- platformContext()->setupPaintForFilling(&paint);
- platformContext()->canvas()->drawOval(rect, paint);
- }
+ platformContext()->setupPaintForFilling(&paint);
+ platformContext()->canvas()->drawOval(rect, paint);
if (strokeStyle() != NoStroke) {
paint.reset();
@@ -685,9 +681,6 @@ void GraphicsContext::fillPath()
const GraphicsContextState& state = m_common->state;
ColorSpace colorSpace = state.fillColorSpace;
- if (colorSpace == SolidColorSpace && !fillColor().alpha())
- return;
-
path.setFillType(state.fillRule == RULE_EVENODD ?
SkPath::kEvenOdd_FillType : SkPath::kWinding_FillType);
@@ -718,9 +711,6 @@ void GraphicsContext::fillRect(const FloatRect& rect)
const GraphicsContextState& state = m_common->state;
ColorSpace colorSpace = state.fillColorSpace;
- if (colorSpace == SolidColorSpace && !fillColor().alpha())
- return;
-
SkPaint paint;
platformContext()->setupPaintForFilling(&paint);
@@ -739,9 +729,6 @@ void GraphicsContext::fillRect(const FloatRect& rect, const Color& color)
if (paintingDisabled())
return;
- if (!color.alpha())
- return;
-
SkRect r = rect;
if (!isRectSkiaSafe(getCTM(), r)) {
// Special case when the rectangle overflows fixed point. This is a
@@ -907,8 +894,13 @@ void GraphicsContext::setLineDash(const DashArray& dashes, float dashOffset)
// FIXME: This is lifted directly off SkiaSupport, lines 49-74
// so it is not guaranteed to work correctly.
size_t dashLength = dashes.size();
- if (!dashLength)
+ if (!dashLength) {
+ // If no dash is set, revert to solid stroke
+ // FIXME: do we need to set NoStroke in some cases?
+ platformContext()->setStrokeStyle(SolidStroke);
+ platformContext()->setDashPathEffect(0);
return;
+ }
size_t count = (dashLength % 2) == 0 ? dashLength : dashLength * 2;
SkScalar* intervals = new SkScalar[count];
@@ -962,6 +954,12 @@ void GraphicsContext::setPlatformShadow(const IntSize& size,
if (paintingDisabled())
return;
+ // Detect when there's no effective shadow and clear the looper.
+ if (size.width() == 0 && size.height() == 0 && blurInt == 0) {
+ platformContext()->setDrawLooper(NULL);
+ return;
+ }
+
double width = size.width();
double height = size.height();
double blur = blurInt;
@@ -1076,9 +1074,6 @@ void GraphicsContext::strokePath()
const GraphicsContextState& state = m_common->state;
ColorSpace colorSpace = state.strokeColorSpace;
- if (colorSpace == SolidColorSpace && !strokeColor().alpha())
- return;
-
SkPaint paint;
platformContext()->setupPaintForStroking(&paint, 0, 0);
@@ -1103,9 +1098,6 @@ void GraphicsContext::strokeRect(const FloatRect& rect, float lineWidth)
const GraphicsContextState& state = m_common->state;
ColorSpace colorSpace = state.strokeColorSpace;
- if (colorSpace == SolidColorSpace && !strokeColor().alpha())
- return;
-
SkPaint paint;
platformContext()->setupPaintForStroking(&paint, 0, 0);
paint.setStrokeWidth(WebCoreFloatToSkScalar(lineWidth));
diff --git a/WebCore/platform/graphics/skia/ImageBufferSkia.cpp b/WebCore/platform/graphics/skia/ImageBufferSkia.cpp
index 5e90491..600882d 100644
--- a/WebCore/platform/graphics/skia/ImageBufferSkia.cpp
+++ b/WebCore/platform/graphics/skia/ImageBufferSkia.cpp
@@ -36,7 +36,6 @@
#include "BitmapImageSingleFrameSkia.h"
#include "GraphicsContext.h"
#include "ImageData.h"
-#include "NotImplemented.h"
#include "PlatformContextSkia.h"
#include "PNGImageEncoder.h"
#include "SkiaUtils.h"
diff --git a/WebCore/platform/graphics/skia/ImageSkia.cpp b/WebCore/platform/graphics/skia/ImageSkia.cpp
index d7f2830..cb089bb 100644
--- a/WebCore/platform/graphics/skia/ImageSkia.cpp
+++ b/WebCore/platform/graphics/skia/ImageSkia.cpp
@@ -38,7 +38,6 @@
#include "GraphicsContext.h"
#include "Logging.h"
#include "NativeImageSkia.h"
-#include "NotImplemented.h"
#include "PlatformContextSkia.h"
#include "PlatformString.h"
#include "SkiaUtils.h"
@@ -226,6 +225,12 @@ static void paintSkBitmap(PlatformContextSkia* platformContext, const NativeImag
SkPaint paint;
paint.setPorterDuffXfermode(compOp);
paint.setFilterBitmap(true);
+ int alpha = roundf(platformContext->getAlpha() * 256);
+ if (alpha > 255)
+ alpha = 255;
+ else if (alpha < 0)
+ alpha = 0;
+ paint.setAlpha(alpha);
skia::PlatformCanvas* canvas = platformContext->canvas();
@@ -305,7 +310,8 @@ void Image::drawPattern(GraphicsContext* context,
CompositeOperator compositeOp,
const FloatRect& destRect)
{
- if (destRect.isEmpty() || floatSrcRect.isEmpty())
+ FloatRect normSrcRect = normalizeRect(floatSrcRect);
+ if (destRect.isEmpty() || normSrcRect.isEmpty())
return; // nothing to draw
NativeImageSkia* bitmap = nativeImageForCurrentFrame();
@@ -316,7 +322,7 @@ void Image::drawPattern(GraphicsContext* context,
// it will internally reference the old bitmap's pixels, adjusting the row
// stride so the extra pixels appear as padding to the subsetted bitmap.
SkBitmap srcSubset;
- SkIRect srcRect = enclosingIntRect(floatSrcRect);
+ SkIRect srcRect = enclosingIntRect(normSrcRect);
bitmap->extractSubset(&srcSubset, srcRect);
SkBitmap resampled;
@@ -363,9 +369,9 @@ void Image::drawPattern(GraphicsContext* context,
// origin of the destination rect, which is what WebKit expects. Skia uses
// the coordinate system origin as the base for the patter. If WebKit wants
// a shifted image, it will shift it from there using the patternTransform.
- float adjustedX = phase.x() + floatSrcRect.x() *
+ float adjustedX = phase.x() + normSrcRect.x() *
narrowPrecisionToFloat(patternTransform.a());
- float adjustedY = phase.y() + floatSrcRect.y() *
+ float adjustedY = phase.y() + normSrcRect.y() *
narrowPrecisionToFloat(patternTransform.d());
matrix.postTranslate(SkFloatToScalar(adjustedX),
SkFloatToScalar(adjustedY));
diff --git a/WebCore/platform/graphics/skia/PathSkia.cpp b/WebCore/platform/graphics/skia/PathSkia.cpp
index 2700da8..9d9df52 100644
--- a/WebCore/platform/graphics/skia/PathSkia.cpp
+++ b/WebCore/platform/graphics/skia/PathSkia.cpp
@@ -81,9 +81,15 @@ void Path::translate(const FloatSize& size)
FloatRect Path::boundingRect() const
{
+ // FIXME: This #ifdef can go away once we're firmly using the new Skia.
+ // During the transition, this makes the code compatible with both versions.
+#ifdef SK_USE_OLD_255_TO_256
+ return m_path->getBounds();
+#else
SkRect rect;
m_path->computeBounds(&rect, SkPath::kExact_BoundsType);
return rect;
+#endif
}
void Path::moveTo(const FloatPoint& point)
@@ -275,9 +281,15 @@ static FloatRect boundingBoxForCurrentStroke(const GraphicsContext* context)
context->platformContext()->setupPaintForStroking(&paint, 0, 0);
SkPath boundingPath;
paint.getFillPath(context->platformContext()->currentPathInLocalCoordinates(), &boundingPath);
+ // FIXME: This #ifdef can go away once we're firmly using the new Skia.
+ // During the transition, this makes the code compatible with both versions.
+#ifdef SK_USE_OLD_255_TO_256
+ return boundingPath.getBounds();
+#else
SkRect r;
boundingPath.computeBounds(&r, SkPath::kExact_BoundsType);
return r;
+#endif
}
FloatRect Path::strokeBoundingRect(StrokeStyleApplier* applier)
diff --git a/WebCore/platform/graphics/skia/PlatformContextSkia.cpp b/WebCore/platform/graphics/skia/PlatformContextSkia.cpp
index 6c633f2..74b2bfe 100644
--- a/WebCore/platform/graphics/skia/PlatformContextSkia.cpp
+++ b/WebCore/platform/graphics/skia/PlatformContextSkia.cpp
@@ -277,13 +277,13 @@ void PlatformContextSkia::drawRect(SkRect rect)
if (oldFillColor != m_state->m_strokeColor)
setFillColor(m_state->m_strokeColor);
setupPaintForFilling(&paint);
- SkRect topBorder = { rect.fLeft, rect.fTop, rect.width(), 1 };
+ SkRect topBorder = { rect.fLeft, rect.fTop, rect.fRight, rect.fTop + 1 };
canvas()->drawRect(topBorder, paint);
- SkRect bottomBorder = { rect.fLeft, rect.fBottom - 1, rect.width(), 1 };
+ SkRect bottomBorder = { rect.fLeft, rect.fBottom - 1, rect.fRight, rect.fBottom };
canvas()->drawRect(bottomBorder, paint);
- SkRect leftBorder = { rect.fLeft, rect.fTop + 1, 1, rect.height() - 2 };
+ SkRect leftBorder = { rect.fLeft, rect.fTop + 1, rect.fLeft + 1, rect.fBottom - 1 };
canvas()->drawRect(leftBorder, paint);
- SkRect rightBorder = { rect.fRight - 1, rect.fTop + 1, 1, rect.height() - 2 };
+ SkRect rightBorder = { rect.fRight - 1, rect.fTop + 1, rect.fRight, rect.fBottom - 1 };
canvas()->drawRect(rightBorder, paint);
if (oldFillColor != m_state->m_strokeColor)
setFillColor(oldFillColor);
@@ -428,6 +428,11 @@ int PlatformContextSkia::getTextDrawingMode() const
return m_state->m_textDrawingMode;
}
+float PlatformContextSkia::getAlpha() const
+{
+ return m_state->m_alpha;
+}
+
void PlatformContextSkia::setTextDrawingMode(int mode)
{
// cTextClip is never used, so we assert that it isn't set:
diff --git a/WebCore/platform/graphics/skia/PlatformContextSkia.h b/WebCore/platform/graphics/skia/PlatformContextSkia.h
index 8850a6a..25495aa 100644
--- a/WebCore/platform/graphics/skia/PlatformContextSkia.h
+++ b/WebCore/platform/graphics/skia/PlatformContextSkia.h
@@ -130,6 +130,7 @@ public:
WebCore::StrokeStyle getStrokeStyle() const;
float getStrokeThickness() const;
int getTextDrawingMode() const;
+ float getAlpha() const;
void beginPath();
void addPath(const SkPath&);
diff --git a/WebCore/platform/graphics/skia/SkiaFontWin.cpp b/WebCore/platform/graphics/skia/SkiaFontWin.cpp
index d0cd4c5..7f12508 100644
--- a/WebCore/platform/graphics/skia/SkiaFontWin.cpp
+++ b/WebCore/platform/graphics/skia/SkiaFontWin.cpp
@@ -220,6 +220,16 @@ void SkiaWinOutlineCache::removePathsForFont(HFONT hfont)
deleteOutline(outlineCache.find(*i));
}
+bool windowsCanHandleDrawTextShadow(WebCore::GraphicsContext *context)
+{
+ IntSize shadowSize;
+ int shadowBlur;
+ Color shadowColor;
+
+ bool hasShadow = context->getShadow(shadowSize, shadowBlur, shadowColor);
+ return (hasShadow && (shadowBlur == 0) && (shadowColor.alpha() == 255) && (context->fillColor().alpha() == 255));
+}
+
bool windowsCanHandleTextDrawing(GraphicsContext* context)
{
// Check for non-translation transforms. Sometimes zooms will look better in
@@ -244,7 +254,7 @@ bool windowsCanHandleTextDrawing(GraphicsContext* context)
return false;
// Check for shadow effects.
- if (context->platformContext()->getDrawLooper())
+ if (context->platformContext()->getDrawLooper() && (!windowsCanHandleDrawTextShadow(context)))
return false;
return true;
diff --git a/WebCore/platform/graphics/skia/SkiaFontWin.h b/WebCore/platform/graphics/skia/SkiaFontWin.h
index 0e0c953..0bad30f 100644
--- a/WebCore/platform/graphics/skia/SkiaFontWin.h
+++ b/WebCore/platform/graphics/skia/SkiaFontWin.h
@@ -68,8 +68,12 @@ private:
// Remember that Skia's text drawing origin is the baseline, like WebKit, not
// the top, like Windows.
+// Returns true if the fillColor and shadowColor are opaque and the text-shadow
+// is not blurred.
+bool windowsCanHandleDrawTextShadow(GraphicsContext*);
+
// Returns true if advanced font rendering is recommended.
-bool windowsCanHandleTextDrawing(GraphicsContext* context);
+bool windowsCanHandleTextDrawing(GraphicsContext*);
// Note that the offsets parameter is optional. If not NULL it represents a
// per glyph offset (such as returned by ScriptPlace Windows API function).
diff --git a/WebCore/platform/graphics/skia/SkiaUtils.cpp b/WebCore/platform/graphics/skia/SkiaUtils.cpp
index 55cba37..4242e7d 100644
--- a/WebCore/platform/graphics/skia/SkiaUtils.cpp
+++ b/WebCore/platform/graphics/skia/SkiaUtils.cpp
@@ -47,7 +47,7 @@ static const struct CompositOpToPorterDuffMode {
uint8_t mPorterDuffMode;
} gMapCompositOpsToPorterDuffModes[] = {
{ CompositeClear, SkPorterDuff::kClear_Mode },
- { CompositeCopy, SkPorterDuff::kSrcOver_Mode }, // TODO
+ { CompositeCopy, SkPorterDuff::kSrc_Mode },
{ CompositeSourceOver, SkPorterDuff::kSrcOver_Mode },
{ CompositeSourceIn, SkPorterDuff::kSrcIn_Mode },
{ CompositeSourceOut, SkPorterDuff::kSrcOut_Mode },
@@ -59,7 +59,7 @@ static const struct CompositOpToPorterDuffMode {
{ CompositeXOR, SkPorterDuff::kXor_Mode },
{ CompositePlusDarker, SkPorterDuff::kDarken_Mode },
{ CompositeHighlight, SkPorterDuff::kSrcOver_Mode }, // TODO
- { CompositePlusLighter, SkPorterDuff::kLighten_Mode }
+ { CompositePlusLighter, SkPorterDuff::kAdd_Mode }
};
SkPorterDuff::Mode WebCoreCompositeToSkiaComposite(CompositeOperator op)
@@ -135,12 +135,7 @@ bool SkPathContainsPoint(SkPath* originalPath, const FloatPoint& point, SkPath::
int scale = 1;
SkRect bounds;
-#if PLATFORM(SGL)
- // this is the API from skia/trunk
bounds = originalPath->getBounds();
-#else
- originalPath->computeBounds(&bounds, SkPath::kFast_BoundsType);
-#endif
// We can immediately return false if the point is outside the bounding rect
if (!bounds.contains(SkFloatToScalar(point.x()), SkFloatToScalar(point.y())))