Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1531)

Unified Diff: third_party/WebKit/Source/platform/graphics/GraphicsContext.cpp

Issue 2523673004: [NOT FOR COMMIT] Fully replace SkCanvas uses.
Patch Set: Support Android build. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/graphics/GraphicsContext.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/GraphicsContext.cpp b/third_party/WebKit/Source/platform/graphics/GraphicsContext.cpp
index cb5f3ad5020d4a547ea1cd836f428f1c97085d80..5fe0ab044701b08a4c685b3a05a82b3ccf57f19f 100644
--- a/third_party/WebKit/Source/platform/graphics/GraphicsContext.cpp
+++ b/third_party/WebKit/Source/platform/graphics/GraphicsContext.cpp
@@ -40,8 +40,8 @@
#include "third_party/skia/include/core/SkAnnotation.h"
#include "third_party/skia/include/core/SkColorFilter.h"
#include "third_party/skia/include/core/SkData.h"
-#include "third_party/skia/include/core/SkPicture.h"
-#include "third_party/skia/include/core/SkPictureRecorder.h"
+#include "skia/ext/cdl_picture.h"
+#include "skia/ext/cdl_picture_recorder.h"
#include "third_party/skia/include/core/SkRRect.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/effects/SkLumaColorFilter.h"
@@ -79,8 +79,11 @@ GraphicsContext::GraphicsContext(PaintController& paintController,
m_paintState = m_paintStateStack.back().get();
if (contextDisabled()) {
- DEFINE_STATIC_LOCAL(SkCanvas*, nullCanvas, (SkMakeNullCanvas().release()));
- m_canvas = nullCanvas;
+ // TODO(cdl): Null CdlCanvas.
+ DEFINE_STATIC_LOCAL(SkCanvas*, nullSkCanvas,
+ (SkMakeNullCanvas().release()));
+ DEFINE_STATIC_LOCAL(CdlPassThroughCanvas, nullCanvas, (nullSkCanvas));
+ m_canvas = &nullCanvas;
}
}
@@ -138,12 +141,11 @@ unsigned GraphicsContext::saveCount() const {
}
#endif
-void GraphicsContext::saveLayer(const SkRect* bounds, const SkPaint* paint) {
+void GraphicsContext::saveLayer(const SkRect* bounds, const CdlPaint* paint) {
if (contextDisabled())
return;
ASSERT(m_canvas);
-
m_canvas->saveLayer(bounds, paint);
}
@@ -231,7 +233,7 @@ void GraphicsContext::beginLayer(float opacity,
if (contextDisabled())
return;
- SkPaint layerPaint;
+ CdlPaint layerPaint;
layerPaint.setAlpha(static_cast<unsigned char>(opacity * 255));
layerPaint.setBlendMode(xfermode);
layerPaint.setColorFilter(WebCoreColorFilterToSkiaColorFilter(colorFilter));
@@ -271,29 +273,30 @@ void GraphicsContext::beginRecording(const FloatRect& bounds) {
namespace {
-sk_sp<SkPicture> createEmptyPicture() {
- SkPictureRecorder recorder;
+sk_sp<CdlPicture> createEmptyPicture() {
+ CdlPictureRecorder recorder;
recorder.beginRecording(SkRect::MakeEmpty(), nullptr);
return recorder.finishRecordingAsPicture();
}
} // anonymous namespace
-sk_sp<SkPicture> GraphicsContext::endRecording() {
+sk_sp<CdlPicture> GraphicsContext::endRecording() {
if (contextDisabled()) {
// Clients expect endRecording() to always return a non-null picture.
// Cache an empty SKP to minimize overhead when disabled.
- DEFINE_STATIC_LOCAL(sk_sp<SkPicture>, emptyPicture, (createEmptyPicture()));
+ DEFINE_STATIC_LOCAL(sk_sp<CdlPicture>, emptyPicture,
+ (createEmptyPicture()));
return emptyPicture;
}
- sk_sp<SkPicture> picture = m_pictureRecorder.finishRecordingAsPicture();
+ sk_sp<CdlPicture> picture = m_pictureRecorder.finishRecordingAsPicture();
m_canvas = nullptr;
ASSERT(picture);
return picture;
}
-void GraphicsContext::drawPicture(const SkPicture* picture) {
+void GraphicsContext::drawPicture(const CdlPicture* picture) {
if (contextDisabled() || !picture || picture->cullRect().isEmpty())
return;
@@ -301,7 +304,7 @@ void GraphicsContext::drawPicture(const SkPicture* picture) {
m_canvas->drawPicture(picture);
}
-void GraphicsContext::compositePicture(sk_sp<SkPicture> picture,
+void GraphicsContext::compositePicture(sk_sp<CdlPicture> picture,
const FloatRect& dest,
const FloatRect& src,
SkBlendMode op) {
@@ -309,7 +312,7 @@ void GraphicsContext::compositePicture(sk_sp<SkPicture> picture,
return;
ASSERT(m_canvas);
- SkPaint picturePaint;
+ CdlPaint picturePaint;
picturePaint.setBlendMode(op);
m_canvas->save();
SkRect sourceBounds = src;
@@ -319,7 +322,7 @@ void GraphicsContext::compositePicture(sk_sp<SkPicture> picture,
SkMatrix::kFill_ScaleToFit);
m_canvas->concat(pictureTransform);
picturePaint.setImageFilter(SkPictureImageFilter::MakeForLocalSpace(
- std::move(picture), sourceBounds,
+ ToSkPicture(picture.get()), sourceBounds,
static_cast<SkFilterQuality>(imageInterpolationQuality())));
m_canvas->saveLayer(&sourceBounds, &picturePaint);
m_canvas->restore();
@@ -477,7 +480,7 @@ void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2) {
// probably worth the speed up of no square root, which also won't be exact.
FloatSize disp = p2 - p1;
int length = SkScalarRoundToInt(disp.width() + disp.height());
- SkPaint paint(immutableState()->strokePaint(length));
+ CdlPaint paint(immutableState()->strokePaint(length));
if (getStrokeStyle() == DottedStroke || getStrokeStyle() == DashedStroke) {
// Do a rect fill of our endpoints. This ensures we always have the
@@ -494,7 +497,7 @@ void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2) {
r1.offset(0, -width / 2);
r2.offset(-width, -width / 2);
}
- SkPaint fillPaint;
+ CdlPaint fillPaint;
fillPaint.setColor(paint.getColor());
drawRect(r1, fillPaint);
drawRect(r2, fillPaint);
@@ -623,10 +626,10 @@ void GraphicsContext::drawLineForDocumentMarker(const FloatPoint& pt,
SkMatrix localMatrix;
localMatrix.setTranslate(originX, originY);
- SkPaint paint;
- paint.setShader(SkShader::MakeBitmapShader(
+ CdlPaint paint;
+ paint.setShader(WrapSkShader(SkShader::MakeBitmapShader(
*misspellBitmap[index], SkShader::kRepeat_TileMode,
- SkShader::kRepeat_TileMode, &localMatrix));
+ SkShader::kRepeat_TileMode, &localMatrix)));
SkRect rect;
rect.set(originX, originY,
@@ -649,7 +652,7 @@ void GraphicsContext::drawLineForText(const FloatPoint& pt, float width) {
if (width <= 0)
return;
- SkPaint paint;
+ CdlPaint paint;
switch (getStrokeStyle()) {
case NoStroke:
case SolidStroke:
@@ -698,9 +701,9 @@ void GraphicsContext::drawRect(const IntRect& rect) {
if (immutableState()->getStrokeData().style() != NoStroke &&
immutableState()->strokeColor().alpha()) {
// Stroke a width: 1 inset border
- SkPaint paint(immutableState()->fillPaint());
+ CdlPaint paint(immutableState()->fillPaint());
paint.setColor(strokeColor().rgb());
- paint.setStyle(SkPaint::kStroke_Style);
+ paint.setStyle(CdlPaint::kStroke_Style);
paint.setStrokeWidth(1);
skRect.inset(0.5f, 0.5f);
@@ -711,7 +714,7 @@ void GraphicsContext::drawRect(const IntRect& rect) {
void GraphicsContext::drawText(const Font& font,
const TextRunPaintInfo& runInfo,
const FloatPoint& point,
- const SkPaint& paint) {
+ const CdlPaint& paint) {
if (contextDisabled())
return;
@@ -729,7 +732,7 @@ void GraphicsContext::drawTextPasses(const DrawTextFunc& drawText) {
if ((modeFlags & TextModeStroke) && getStrokeStyle() != NoStroke &&
strokeThickness() > 0) {
- SkPaint paintForStroking(immutableState()->strokePaint());
+ CdlPaint paintForStroking(immutableState()->strokePaint());
if (modeFlags & TextModeFill) {
paintForStroking.setLooper(
0); // shadow was already applied during fill pass
@@ -744,7 +747,7 @@ void GraphicsContext::drawText(const Font& font,
if (contextDisabled())
return;
- drawTextPasses([&font, &runInfo, &point, this](const SkPaint& paint) {
+ drawTextPasses([&font, &runInfo, &point, this](const CdlPaint& paint) {
if (font.drawText(m_canvas, runInfo, point, m_deviceScaleFactor, paint))
m_paintController.setTextPainted();
});
@@ -757,7 +760,7 @@ void GraphicsContext::drawEmphasisMarks(const Font& font,
if (contextDisabled())
return;
- drawTextPasses([&font, &runInfo, &mark, &point, this](const SkPaint& paint) {
+ drawTextPasses([&font, &runInfo, &mark, &point, this](const CdlPaint& paint) {
font.drawEmphasisMarks(m_canvas, runInfo, mark, point, m_deviceScaleFactor,
paint);
});
@@ -772,7 +775,7 @@ void GraphicsContext::drawBidiText(
return;
drawTextPasses([&font, &runInfo, &point, customFontNotReadyAction,
- this](const SkPaint& paint) {
+ this](const CdlPaint& paint) {
if (font.drawBidiText(m_canvas, runInfo, point, customFontNotReadyAction,
m_deviceScaleFactor, paint))
m_paintController.setTextPainted();
@@ -803,7 +806,7 @@ void GraphicsContext::drawImage(
const FloatRect src = srcPtr ? *srcPtr : image->rect();
- SkPaint imagePaint = immutableState()->fillPaint();
+ CdlPaint imagePaint = immutableState()->fillPaint();
imagePaint.setBlendMode(op);
imagePaint.setColor(SK_ColorBLACK);
imagePaint.setFilterQuality(computeFilterQuality(image, dest, src));
@@ -833,7 +836,7 @@ void GraphicsContext::drawImageRRect(
if (dest.isEmpty() || visibleSrc.isEmpty())
return;
- SkPaint imagePaint = immutableState()->fillPaint();
+ CdlPaint imagePaint = immutableState()->fillPaint();
imagePaint.setBlendMode(op);
imagePaint.setColor(SK_ColorBLACK);
imagePaint.setFilterQuality(
@@ -853,7 +856,7 @@ void GraphicsContext::drawImageRRect(
m_canvas->drawRRect(dest, imagePaint);
} else {
// Clip-based fallback.
- SkAutoCanvasRestore autoRestore(m_canvas, true);
+ CdlAutoCanvasRestore autoRestore(m_canvas, true);
m_canvas->clipRRect(dest, SkRegion::kIntersect_Op,
imagePaint.isAntiAlias());
image->draw(m_canvas, imagePaint, dest.rect(), srcRect, respectOrientation,
@@ -923,7 +926,7 @@ void GraphicsContext::drawTiledImage(Image* image,
m_paintController.setImagePainted();
}
-void GraphicsContext::drawOval(const SkRect& oval, const SkPaint& paint) {
+void GraphicsContext::drawOval(const SkRect& oval, const CdlPaint& paint) {
if (contextDisabled())
return;
ASSERT(m_canvas);
@@ -931,7 +934,7 @@ void GraphicsContext::drawOval(const SkRect& oval, const SkPaint& paint) {
m_canvas->drawOval(oval, paint);
}
-void GraphicsContext::drawPath(const SkPath& path, const SkPaint& paint) {
+void GraphicsContext::drawPath(const SkPath& path, const CdlPaint& paint) {
if (contextDisabled())
return;
ASSERT(m_canvas);
@@ -939,7 +942,7 @@ void GraphicsContext::drawPath(const SkPath& path, const SkPaint& paint) {
m_canvas->drawPath(path, paint);
}
-void GraphicsContext::drawRect(const SkRect& rect, const SkPaint& paint) {
+void GraphicsContext::drawRect(const SkRect& rect, const CdlPaint& paint) {
if (contextDisabled())
return;
ASSERT(m_canvas);
@@ -947,7 +950,7 @@ void GraphicsContext::drawRect(const SkRect& rect, const SkPaint& paint) {
m_canvas->drawRect(rect, paint);
}
-void GraphicsContext::drawRRect(const SkRRect& rrect, const SkPaint& paint) {
+void GraphicsContext::drawRRect(const SkRRect& rrect, const CdlPaint& paint) {
if (contextDisabled())
return;
ASSERT(m_canvas);
@@ -975,7 +978,7 @@ void GraphicsContext::fillRect(const FloatRect& rect,
if (contextDisabled())
return;
- SkPaint paint = immutableState()->fillPaint();
+ CdlPaint paint = immutableState()->fillPaint();
paint.setColor(color.rgb());
paint.setBlendMode(xferMode);
@@ -997,7 +1000,7 @@ void GraphicsContext::fillRoundedRect(const FloatRoundedRect& rrect,
return;
}
- SkPaint paint = immutableState()->fillPaint();
+ CdlPaint paint = immutableState()->fillPaint();
paint.setColor(color.rgb());
drawRRect(rrect, paint);
@@ -1068,7 +1071,7 @@ void GraphicsContext::fillDRRect(const FloatRoundedRect& outer,
if (color == fillColor()) {
m_canvas->drawDRRect(outer, inner, immutableState()->fillPaint());
} else {
- SkPaint paint(immutableState()->fillPaint());
+ CdlPaint paint(immutableState()->fillPaint());
paint.setColor(color.rgb());
m_canvas->drawDRRect(outer, inner, paint);
}
@@ -1081,9 +1084,9 @@ void GraphicsContext::fillDRRect(const FloatRoundedRect& outer,
SkRRect strokeRRect = outer;
strokeRRect.inset(strokeWidth / 2, strokeWidth / 2);
- SkPaint strokePaint(immutableState()->fillPaint());
+ CdlPaint strokePaint(immutableState()->fillPaint());
strokePaint.setColor(color.rgb());
- strokePaint.setStyle(SkPaint::kStroke_Style);
+ strokePaint.setStyle(CdlPaint::kStroke_Style);
strokePaint.setStrokeWidth(strokeWidth);
m_canvas->drawRRect(strokeRRect, strokePaint);
@@ -1107,7 +1110,7 @@ void GraphicsContext::strokeRect(const FloatRect& rect, float lineWidth) {
if (contextDisabled())
return;
- SkPaint paint(immutableState()->strokePaint());
+ CdlPaint paint(immutableState()->strokePaint());
paint.setStrokeWidth(WebCoreFloatToSkScalar(lineWidth));
// Reset the dash effect to account for the width
immutableState()->getStrokeData().setupPaintDashPathEffect(&paint, 0);
@@ -1234,7 +1237,8 @@ void GraphicsContext::setURLForRect(const KURL& link, const IntRect& destRect) {
ASSERT(m_canvas);
sk_sp<SkData> url(SkData::MakeWithCString(link.getString().utf8().data()));
- SkAnnotateRectWithURL(m_canvas, destRect, url.get());
+ // TODO(cdl): annotate
+ // SkAnnotateRectWithURL(m_canvas, destRect, url.get());
}
void GraphicsContext::setURLFragmentForRect(const String& destName,
@@ -1244,7 +1248,8 @@ void GraphicsContext::setURLFragmentForRect(const String& destName,
ASSERT(m_canvas);
sk_sp<SkData> skDestName(SkData::MakeWithCString(destName.utf8().data()));
- SkAnnotateLinkToDestination(m_canvas, rect, skDestName.get());
+ // TODO(cdl): annotate
+ // SkAnnotateLinkToDestination(m_canvas, rect, skDestName.get());
}
void GraphicsContext::setURLDestinationLocation(const String& name,
@@ -1254,8 +1259,9 @@ void GraphicsContext::setURLDestinationLocation(const String& name,
ASSERT(m_canvas);
sk_sp<SkData> skName(SkData::MakeWithCString(name.utf8().data()));
- SkAnnotateNamedDestination(
- m_canvas, SkPoint::Make(location.x(), location.y()), skName.get());
+ // TODO(cdl): annotate
+ // SkAnnotateNamedDestination(
+ // m_canvas, SkPoint::Make(location.x(), location.y()), skName.get());
}
void GraphicsContext::concatCTM(const AffineTransform& affine) {
@@ -1269,7 +1275,7 @@ void GraphicsContext::fillRectWithRoundedHole(
if (contextDisabled())
return;
- SkPaint paint(immutableState()->fillPaint());
+ CdlPaint paint(immutableState()->fillPaint());
paint.setColor(color.rgb());
m_canvas->drawDRRect(SkRRect::MakeRect(rect), roundedHoleRect, paint);
}

Powered by Google App Engine
This is Rietveld 408576698