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

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

Issue 2841153002: Relocate GC::DrawLineForDocumentMarker() (Closed)
Patch Set: Created 3 years, 8 months 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
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/GraphicsContext.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1c9b4b1a167d2ff6371797ca85b2b5c43db51086..6615302bc384935ccbf0152db91d034b18c09b9e 100644
--- a/third_party/WebKit/Source/platform/graphics/GraphicsContext.cpp
+++ b/third_party/WebKit/Source/platform/graphics/GraphicsContext.cpp
@@ -47,7 +47,6 @@
#include "third_party/skia/include/core/SkData.h"
#include "third_party/skia/include/core/SkRRect.h"
#include "third_party/skia/include/core/SkRefCnt.h"
-#include "third_party/skia/include/effects/SkGradientShader.h"
#include "third_party/skia/include/effects/SkLumaColorFilter.h"
#include "third_party/skia/include/effects/SkPictureImageFilter.h"
#include "third_party/skia/include/pathops/SkPathOps.h"
@@ -541,138 +540,6 @@ void GraphicsContext::DrawLine(const IntPoint& point1, const IntPoint& point2) {
canvas_->drawLine(p1.X(), p1.Y(), p2.X(), p2.Y(), flags);
}
-namespace {
-
-#if !OS(MACOSX)
-
-sk_sp<PaintRecord> RecordMarker(
- GraphicsContext::DocumentMarkerLineStyle style) {
- SkColor color = (style == GraphicsContext::kDocumentMarkerGrammarLineStyle)
- ? SkColorSetRGB(0xC0, 0xC0, 0xC0)
- : SK_ColorRED;
-
- // Record the path equivalent to this legacy pattern:
- // X o o X o o X
- // o X o o X o
-
- static const float kW = 4;
- static const float kH = 2;
-
- // Adjust the phase such that f' == 0 is "pixel"-centered
- // (for optimal rasterization at native rez).
- SkPath path;
- path.moveTo(kW * -3 / 8, kH * 3 / 4);
- path.cubicTo(kW * -1 / 8, kH * 3 / 4,
- kW * -1 / 8, kH * 1 / 4,
- kW * 1 / 8, kH * 1 / 4);
- path.cubicTo(kW * 3 / 8, kH * 1 / 4,
- kW * 3 / 8, kH * 3 / 4,
- kW * 5 / 8, kH * 3 / 4);
- path.cubicTo(kW * 7 / 8, kH * 3 / 4,
- kW * 7 / 8, kH * 1 / 4,
- kW * 9 / 8, kH * 1 / 4);
-
- PaintFlags flags;
- flags.setAntiAlias(true);
- flags.setColor(color);
- flags.setStyle(PaintFlags::kStroke_Style);
- flags.setStrokeWidth(kH * 1 / 2);
-
- PaintRecorder recorder;
- recorder.beginRecording(kW, kH);
- recorder.getRecordingCanvas()->drawPath(path, flags);
-
- return recorder.finishRecordingAsPicture();
-}
-
-#else // OS(MACOSX)
-
-sk_sp<PaintRecord> RecordMarker(
- GraphicsContext::DocumentMarkerLineStyle style) {
- SkColor color = (style == GraphicsContext::kDocumentMarkerGrammarLineStyle)
- ? SkColorSetRGB(0x6B, 0x6B, 0x6B)
- : SkColorSetRGB(0xFB, 0x2D, 0x1D);
-
- // Match the artwork used by the Mac.
- static const float kW = 4;
- static const float kH = 3;
- static const float kR = 1.5f;
-
- // top->bottom translucent gradient.
- const SkColor colors[2] = {
- SkColorSetARGB(0x48,
- SkColorGetR(color),
- SkColorGetG(color),
- SkColorGetB(color)),
- color
- };
- const SkPoint pts[2] = {
- SkPoint::Make(0, 0),
- SkPoint::Make(0, 2 * kR)
- };
-
- PaintFlags flags;
- flags.setAntiAlias(true);
- flags.setColor(color);
- flags.setShader(SkGradientShader::MakeLinear(
- pts, colors, nullptr, ARRAY_SIZE(colors), SkShader::kClamp_TileMode));
- PaintRecorder recorder;
- recorder.beginRecording(kW, kH);
- recorder.getRecordingCanvas()->drawCircle(kR, kR, kR, flags);
-
- return recorder.finishRecordingAsPicture();
-}
-
-#endif // OS(MACOSX)
-
-} // anonymous ns
-
-void GraphicsContext::DrawLineForDocumentMarker(const FloatPoint& pt,
- float width,
- DocumentMarkerLineStyle style,
- float zoom) {
- if (ContextDisabled())
- return;
-
- DEFINE_STATIC_LOCAL(
- PaintRecord*, spelling_marker,
- (RecordMarker(kDocumentMarkerSpellingLineStyle).release()));
- DEFINE_STATIC_LOCAL(
- PaintRecord*, grammar_marker,
- (RecordMarker(kDocumentMarkerGrammarLineStyle).release()));
- const auto& marker = style == kDocumentMarkerSpellingLineStyle
- ? spelling_marker
- : grammar_marker;
-
- // Position already includes zoom and device scale factor.
- SkScalar origin_x = WebCoreFloatToSkScalar(pt.X());
- SkScalar origin_y = WebCoreFloatToSkScalar(pt.Y());
-
-#if OS(MACOSX)
- // Make sure to draw only complete dots, and finish inside the marked text.
- width -= fmodf(width, marker->cullRect().width() * zoom);
-#else
- // Offset it vertically by 1 so that there's some space under the text.
- origin_y += 1;
-#endif
-
- const auto rect = SkRect::MakeWH(width, marker->cullRect().height() * zoom);
- const auto local_matrix = SkMatrix::MakeScale(zoom, zoom);
-
- PaintFlags flags;
- flags.setAntiAlias(true);
- flags.setShader(WrapSkShader(MakePaintShaderRecord(
- sk_ref_sp(marker), SkShader::kRepeat_TileMode, SkShader::kClamp_TileMode,
- &local_matrix, nullptr)));
-
- // Apply the origin translation as a global transform. This ensures that the
- // shader local matrix depends solely on zoom => Skia can reuse the same
- // cached tile for all markers at a given zoom level.
- PaintCanvasAutoRestore acr(canvas_, true);
- canvas_->translate(origin_x, origin_y);
- canvas_->drawRect(rect, flags);
-}
-
void GraphicsContext::DrawLineForText(const FloatPoint& pt, float width) {
if (ContextDisabled())
return;
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/GraphicsContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698