diff options
author | Steve Block <steveblock@google.com> | 2009-12-15 10:12:09 +0000 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2009-12-17 17:41:10 +0000 |
commit | 643ca7872b450ea4efacab6188849e5aac2ba161 (patch) | |
tree | 6982576c228bcd1a7efe98afed544d840751094c /WebCore/platform/graphics/skia | |
parent | d026980fde6eb3b01c1fe49441174e89cd1be298 (diff) | |
download | external_webkit-643ca7872b450ea4efacab6188849e5aac2ba161.zip external_webkit-643ca7872b450ea4efacab6188849e5aac2ba161.tar.gz external_webkit-643ca7872b450ea4efacab6188849e5aac2ba161.tar.bz2 |
Merge webkit.org at r51976 : Initial merge by git.
Change-Id: Ib0e7e2f0fb4bee5a186610272edf3186f0986b43
Diffstat (limited to 'WebCore/platform/graphics/skia')
5 files changed, 40 insertions, 22 deletions
diff --git a/WebCore/platform/graphics/skia/BitmapImageSingleFrameSkia.h b/WebCore/platform/graphics/skia/BitmapImageSingleFrameSkia.h index 5d85652..9fb6a8b 100644 --- a/WebCore/platform/graphics/skia/BitmapImageSingleFrameSkia.h +++ b/WebCore/platform/graphics/skia/BitmapImageSingleFrameSkia.h @@ -72,7 +72,7 @@ public: } protected: - virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator); + virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, ColorSpace styleColorSpace, CompositeOperator); private: NativeImageSkia m_nativeImage; diff --git a/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp b/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp index 889c41b..f1536a6 100644 --- a/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp +++ b/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp @@ -293,7 +293,10 @@ void GraphicsContext::addInnerRoundedRectClip(const IntRect& rect, int thickness path.addOval(r, SkPath::kCW_Direction); // only perform the inset if we won't invert r if (2 * thickness < rect.width() && 2 * thickness < rect.height()) { - r.inset(SkIntToScalar(thickness), SkIntToScalar(thickness)); + // Adding one to the thickness doesn't make the border too thick as + // it's painted over afterwards. But without this adjustment the + // border appears a little anemic after anti-aliasing. + r.inset(SkIntToScalar(thickness + 1), SkIntToScalar(thickness + 1)); path.addOval(r, SkPath::kCCW_Direction); } platformContext()->clipPathAntiAliased(path); @@ -704,8 +707,6 @@ void GraphicsContext::fillPath() return; const GraphicsContextState& state = m_common->state; - ColorSpace colorSpace = state.fillColorSpace; - path.setFillType(state.fillRule == RULE_EVENODD ? SkPath::kEvenOdd_FillType : SkPath::kWinding_FillType); @@ -727,14 +728,13 @@ void GraphicsContext::fillRect(const FloatRect& rect) } const GraphicsContextState& state = m_common->state; - ColorSpace colorSpace = state.fillColorSpace; SkPaint paint; platformContext()->setupPaintForFilling(&paint); platformContext()->canvas()->drawRect(r, paint); } -void GraphicsContext::fillRect(const FloatRect& rect, const Color& color) +void GraphicsContext::fillRect(const FloatRect& rect, const Color& color, ColorSpace colorSpace) { if (paintingDisabled()) return; @@ -765,7 +765,8 @@ void GraphicsContext::fillRoundedRect(const IntRect& rect, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight, - const Color& color) + const Color& color, + ColorSpace colorSpace) { if (paintingDisabled()) return; @@ -782,7 +783,7 @@ void GraphicsContext::fillRoundedRect(const IntRect& rect, // Not all the radii fit, return a rect. This matches the behavior of // Path::createRoundedRectangle. Without this we attempt to draw a round // shadow for a square box. - fillRect(rect, color); + fillRect(rect, color, colorSpace); return; } @@ -950,7 +951,7 @@ void GraphicsContext::setMiterLimit(float limit) platformContext()->setMiterLimit(limit); } -void GraphicsContext::setPlatformFillColor(const Color& color) +void GraphicsContext::setPlatformFillColor(const Color& color, ColorSpace colorSpace) { if (paintingDisabled()) return; @@ -977,7 +978,8 @@ void GraphicsContext::setPlatformFillPattern(Pattern* pattern) void GraphicsContext::setPlatformShadow(const IntSize& size, int blurInt, - const Color& color) + const Color& color, + ColorSpace colorSpace) { if (paintingDisabled()) return; @@ -1019,7 +1021,7 @@ void GraphicsContext::setPlatformShadow(const IntSize& size, dl->unref(); } -void GraphicsContext::setPlatformStrokeColor(const Color& strokecolor) +void GraphicsContext::setPlatformStrokeColor(const Color& strokecolor, ColorSpace colorSpace) { if (paintingDisabled()) return; @@ -1118,7 +1120,6 @@ void GraphicsContext::strokePath() return; const GraphicsContextState& state = m_common->state; - ColorSpace colorSpace = state.strokeColorSpace; SkPaint paint; platformContext()->setupPaintForStroking(&paint, 0, 0); @@ -1135,7 +1136,6 @@ void GraphicsContext::strokeRect(const FloatRect& rect, float lineWidth) return; const GraphicsContextState& state = m_common->state; - ColorSpace colorSpace = state.strokeColorSpace; SkPaint paint; platformContext()->setupPaintForStroking(&paint, 0, 0); diff --git a/WebCore/platform/graphics/skia/ImageBufferSkia.cpp b/WebCore/platform/graphics/skia/ImageBufferSkia.cpp index a5c8926..c36f1ce 100644 --- a/WebCore/platform/graphics/skia/ImageBufferSkia.cpp +++ b/WebCore/platform/graphics/skia/ImageBufferSkia.cpp @@ -105,13 +105,16 @@ Image* ImageBuffer::image() const void ImageBuffer::platformTransformColorSpace(const Vector<int>& lookUpTable) { const SkBitmap& bitmap = *context()->platformContext()->bitmap(); + if (bitmap.isNull()) + return; + ASSERT(bitmap.config() == SkBitmap::kARGB_8888_Config); SkAutoLockPixels bitmapLock(bitmap); for (int y = 0; y < m_size.height(); ++y) { uint32_t* srcRow = bitmap.getAddr32(0, y); for (int x = 0; x < m_size.width(); ++x) { SkColor color = SkPMColorToColor(srcRow[x]); - srcRow[x] = SkPreMultiplyARGB(lookUpTable[SkColorGetA(color)], + srcRow[x] = SkPreMultiplyARGB(SkColorGetA(color), lookUpTable[SkColorGetR(color)], lookUpTable[SkColorGetG(color)], lookUpTable[SkColorGetB(color)]); @@ -164,11 +167,12 @@ PassRefPtr<ImageData> getImageData(const IntRect& rect, const SkBitmap& bitmap, for (int x = 0; x < numColumns; ++x) { unsigned char* destPixel = &destRow[x * 4]; if (multiplied == Unmultiplied) { - SkColor color = SkPMColorToColor(srcRow[x]); - destPixel[0] = SkColorGetR(color); - destPixel[1] = SkColorGetG(color); - destPixel[2] = SkColorGetB(color); - destPixel[3] = SkColorGetA(color); + SkColor color = srcRow[x]; + unsigned a = SkColorGetA(color); + destPixel[0] = a ? SkColorGetR(color) * 255 / a : 0; + destPixel[1] = a ? SkColorGetG(color) * 255 / a : 0; + destPixel[2] = a ? SkColorGetB(color) * 255 / a : 0; + destPixel[3] = a; } else { // Input and output are both pre-multiplied, we just need to re-arrange the // bytes from the bitmap format to RGBA. diff --git a/WebCore/platform/graphics/skia/ImageSkia.cpp b/WebCore/platform/graphics/skia/ImageSkia.cpp index ecab364..6d8ed22 100644 --- a/WebCore/platform/graphics/skia/ImageSkia.cpp +++ b/WebCore/platform/graphics/skia/ImageSkia.cpp @@ -302,6 +302,7 @@ void Image::drawPattern(GraphicsContext* context, const FloatRect& floatSrcRect, const TransformationMatrix& patternTransform, const FloatPoint& phase, + ColorSpace styleColorSpace, CompositeOperator compositeOp, const FloatRect& destRect) { @@ -405,7 +406,7 @@ void BitmapImage::checkForSolidColor() } void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dstRect, - const FloatRect& srcRect, CompositeOperator compositeOp) + const FloatRect& srcRect, ColorSpace, CompositeOperator compositeOp) { if (!m_source.initialized()) return; @@ -437,6 +438,7 @@ void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dstRect, void BitmapImageSingleFrameSkia::draw(GraphicsContext* ctxt, const FloatRect& dstRect, const FloatRect& srcRect, + ColorSpace styleColorSpace, CompositeOperator compositeOp) { FloatRect normDstRect = normalizeRect(dstRect); diff --git a/WebCore/platform/graphics/skia/PlatformContextSkia.cpp b/WebCore/platform/graphics/skia/PlatformContextSkia.cpp index a079da0..dfffa0d 100644 --- a/WebCore/platform/graphics/skia/PlatformContextSkia.cpp +++ b/WebCore/platform/graphics/skia/PlatformContextSkia.cpp @@ -343,6 +343,15 @@ void PlatformContextSkia::setupPaintForFilling(SkPaint* paint) const paint->setShader(m_state->m_fillShader); } +static SkScalar scalarBound(SkScalar v, SkScalar min, SkScalar max) +{ + if (v < min) + return min; + if (v > max) + return max; + return v; +} + float PlatformContextSkia::setupPaintForStroking(SkPaint* paint, SkRect* rect, int length) const { setupPaintCommon(paint); @@ -351,10 +360,13 @@ float PlatformContextSkia::setupPaintForStroking(SkPaint* paint, SkRect* rect, i paint->setColor(m_state->applyAlpha(m_state->m_strokeColor)); paint->setShader(m_state->m_strokeShader); paint->setStyle(SkPaint::kStroke_Style); - paint->setStrokeWidth(SkFloatToScalar(width)); + // The limits here (512 and 256) were made up but are hopefully large + // enough to be reasonable. They are, empirically, small enough not to + // cause overflows in Skia. + paint->setStrokeWidth(scalarBound(SkFloatToScalar(width), 0, 512)); paint->setStrokeCap(m_state->m_lineCap); paint->setStrokeJoin(m_state->m_lineJoin); - paint->setStrokeMiter(SkFloatToScalar(m_state->m_miterLimit)); + paint->setStrokeMiter(scalarBound(SkFloatToScalar(m_state->m_miterLimit), 0, 256)); if (m_state->m_dash) paint->setPathEffect(m_state->m_dash); |