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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/GraphicsContext.cpp

Issue 2700123003: DO NOT COMMIT: Results of running old (current) clang-format on Blink (Closed)
Patch Set: Created 3 years, 10 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
13 * 13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 * THE POSSIBILITY OF SUCH DAMAGE. 24 * THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #include "platform/graphics/GraphicsContext.h" 27 #include "platform/graphics/GraphicsContext.h"
28 28
29 #include <memory>
29 #include "platform/geometry/FloatRect.h" 30 #include "platform/geometry/FloatRect.h"
30 #include "platform/geometry/FloatRoundedRect.h" 31 #include "platform/geometry/FloatRoundedRect.h"
31 #include "platform/geometry/IntRect.h" 32 #include "platform/geometry/IntRect.h"
32 #include "platform/graphics/ColorSpace.h" 33 #include "platform/graphics/ColorSpace.h"
33 #include "platform/graphics/GraphicsContextStateSaver.h" 34 #include "platform/graphics/GraphicsContextStateSaver.h"
34 #include "platform/graphics/ImageBuffer.h" 35 #include "platform/graphics/ImageBuffer.h"
35 #include "platform/graphics/Path.h" 36 #include "platform/graphics/Path.h"
36 #include "platform/graphics/paint/PaintController.h" 37 #include "platform/graphics/paint/PaintController.h"
37 #include "platform/graphics/paint/PaintRecord.h" 38 #include "platform/graphics/paint/PaintRecord.h"
38 #include "platform/graphics/paint/PaintRecorder.h" 39 #include "platform/graphics/paint/PaintRecorder.h"
39 #include "platform/instrumentation/tracing/TraceEvent.h" 40 #include "platform/instrumentation/tracing/TraceEvent.h"
40 #include "platform/weborigin/KURL.h" 41 #include "platform/weborigin/KURL.h"
41 #include "skia/ext/platform_canvas.h" 42 #include "skia/ext/platform_canvas.h"
42 #include "third_party/skia/include/core/SkAnnotation.h" 43 #include "third_party/skia/include/core/SkAnnotation.h"
43 #include "third_party/skia/include/core/SkColorFilter.h" 44 #include "third_party/skia/include/core/SkColorFilter.h"
44 #include "third_party/skia/include/core/SkData.h" 45 #include "third_party/skia/include/core/SkData.h"
45 #include "third_party/skia/include/core/SkRRect.h" 46 #include "third_party/skia/include/core/SkRRect.h"
46 #include "third_party/skia/include/core/SkRefCnt.h" 47 #include "third_party/skia/include/core/SkRefCnt.h"
47 #include "third_party/skia/include/core/SkUnPreMultiply.h" 48 #include "third_party/skia/include/core/SkUnPreMultiply.h"
48 #include "third_party/skia/include/effects/SkGradientShader.h" 49 #include "third_party/skia/include/effects/SkGradientShader.h"
49 #include "third_party/skia/include/effects/SkLumaColorFilter.h" 50 #include "third_party/skia/include/effects/SkLumaColorFilter.h"
50 #include "third_party/skia/include/effects/SkPictureImageFilter.h" 51 #include "third_party/skia/include/effects/SkPictureImageFilter.h"
51 #include "third_party/skia/include/pathops/SkPathOps.h" 52 #include "third_party/skia/include/pathops/SkPathOps.h"
52 #include "third_party/skia/include/utils/SkNullCanvas.h" 53 #include "third_party/skia/include/utils/SkNullCanvas.h"
53 #include "wtf/Assertions.h" 54 #include "wtf/Assertions.h"
54 #include "wtf/MathExtras.h" 55 #include "wtf/MathExtras.h"
55 #include <memory>
56 56
57 namespace blink { 57 namespace blink {
58 58
59 GraphicsContext::GraphicsContext(PaintController& paintController, 59 GraphicsContext::GraphicsContext(PaintController& paintController,
60 DisabledMode disableContextOrPainting, 60 DisabledMode disableContextOrPainting,
61 SkMetaData* metaData, 61 SkMetaData* metaData,
62 ColorBehavior colorBehavior) 62 ColorBehavior colorBehavior)
63 : m_canvas(nullptr), 63 : m_canvas(nullptr),
64 m_paintController(paintController), 64 m_paintController(paintController),
65 m_paintStateStack(), 65 m_paintStateStack(),
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 m_canvas->drawLine(p1.x(), p1.y(), p2.x(), p2.y(), flags); 529 m_canvas->drawLine(p1.x(), p1.y(), p2.x(), p2.y(), flags);
530 } 530 }
531 531
532 namespace { 532 namespace {
533 533
534 #if !OS(MACOSX) 534 #if !OS(MACOSX)
535 535
536 sk_sp<PaintRecord> recordMarker( 536 sk_sp<PaintRecord> recordMarker(
537 GraphicsContext::DocumentMarkerLineStyle style) { 537 GraphicsContext::DocumentMarkerLineStyle style) {
538 SkColor color = (style == GraphicsContext::DocumentMarkerGrammarLineStyle) 538 SkColor color = (style == GraphicsContext::DocumentMarkerGrammarLineStyle)
539 ? SkColorSetRGB(0xC0, 0xC0, 0xC0) 539 ? SkColorSetRGB(0xC0, 0xC0, 0xC0)
540 : SK_ColorRED; 540 : SK_ColorRED;
541 541
542 // Record the path equivalent to this legacy pattern: 542 // Record the path equivalent to this legacy pattern:
543 // X o o X o o X 543 // X o o X o o X
544 // o X o o X o 544 // o X o o X o
545 545
546 static const float kW = 4; 546 static const float kW = 4;
547 static const float kH = 2; 547 static const float kH = 2;
548 548
549 // Adjust the phase such that f' == 0 is "pixel"-centered 549 // Adjust the phase such that f' == 0 is "pixel"-centered
550 // (for optimal rasterization at native rez). 550 // (for optimal rasterization at native rez).
551 SkPath path; 551 SkPath path;
552 path.moveTo(kW * -3 / 8, kH * 3 / 4); 552 path.moveTo(kW * -3 / 8, kH * 3 / 4);
553 path.cubicTo(kW * -1 / 8, kH * 3 / 4, 553 path.cubicTo(kW * -1 / 8, kH * 3 / 4, kW * -1 / 8, kH * 1 / 4, kW * 1 / 8,
554 kW * -1 / 8, kH * 1 / 4, 554 kH * 1 / 4);
555 kW * 1 / 8, kH * 1 / 4); 555 path.cubicTo(kW * 3 / 8, kH * 1 / 4, kW * 3 / 8, kH * 3 / 4, kW * 5 / 8,
556 path.cubicTo(kW * 3 / 8, kH * 1 / 4, 556 kH * 3 / 4);
557 kW * 3 / 8, kH * 3 / 4, 557 path.cubicTo(kW * 7 / 8, kH * 3 / 4, kW * 7 / 8, kH * 1 / 4, kW * 9 / 8,
558 kW * 5 / 8, kH * 3 / 4); 558 kH * 1 / 4);
559 path.cubicTo(kW * 7 / 8, kH * 3 / 4,
560 kW * 7 / 8, kH * 1 / 4,
561 kW * 9 / 8, kH * 1 / 4);
562 559
563 PaintFlags flags; 560 PaintFlags flags;
564 flags.setAntiAlias(true); 561 flags.setAntiAlias(true);
565 flags.setColor(color); 562 flags.setColor(color);
566 flags.setStyle(SkPaint::kStroke_Style); 563 flags.setStyle(SkPaint::kStroke_Style);
567 flags.setStrokeWidth(kH * 1 / 2); 564 flags.setStrokeWidth(kH * 1 / 2);
568 565
569 PaintRecorder recorder; 566 PaintRecorder recorder;
570 recorder.beginRecording(kW, kH); 567 recorder.beginRecording(kW, kH);
571 recorder.getRecordingCanvas()->drawPath(path, flags); 568 recorder.getRecordingCanvas()->drawPath(path, flags);
572 569
573 return recorder.finishRecordingAsPicture(); 570 return recorder.finishRecordingAsPicture();
574 } 571 }
575 572
576 #else // OS(MACOSX) 573 #else // OS(MACOSX)
577 574
578 sk_sp<PaintRecord> recordMarker( 575 sk_sp<PaintRecord> recordMarker(
579 GraphicsContext::DocumentMarkerLineStyle style) { 576 GraphicsContext::DocumentMarkerLineStyle style) {
580 SkColor color = (style == GraphicsContext::DocumentMarkerGrammarLineStyle) 577 SkColor color = (style == GraphicsContext::DocumentMarkerGrammarLineStyle)
581 ? SkColorSetRGB(0x6B, 0x6B, 0x6B) 578 ? SkColorSetRGB(0x6B, 0x6B, 0x6B)
582 : SkColorSetRGB(0xFB, 0x2D, 0x1D); 579 : SkColorSetRGB(0xFB, 0x2D, 0x1D);
583 580
584 // Match the artwork used by the Mac. 581 // Match the artwork used by the Mac.
585 static const float kW = 4; 582 static const float kW = 4;
586 static const float kH = 3; 583 static const float kH = 3;
587 static const float kR = 1.5f; 584 static const float kR = 1.5f;
588 585
589 // top->bottom translucent gradient. 586 // top->bottom translucent gradient.
590 const SkColor colors[2] = { 587 const SkColor colors[2] = {
591 SkColorSetARGB(0x48, 588 SkColorSetARGB(0x48, SkColorGetR(color), SkColorGetG(color),
592 SkColorGetR(color),
593 SkColorGetG(color),
594 SkColorGetB(color)), 589 SkColorGetB(color)),
595 color 590 color};
596 }; 591 const SkPoint pts[2] = {SkPoint::Make(0, 0), SkPoint::Make(0, 2 * kR)};
597 const SkPoint pts[2] = {
598 SkPoint::Make(0, 0),
599 SkPoint::Make(0, 2 * kR)
600 };
601 592
602 PaintFlags flags; 593 PaintFlags flags;
603 flags.setAntiAlias(true); 594 flags.setAntiAlias(true);
604 flags.setColor(color); 595 flags.setColor(color);
605 flags.setShader(SkGradientShader::MakeLinear( 596 flags.setShader(SkGradientShader::MakeLinear(
606 pts, colors, nullptr, ARRAY_SIZE(colors), SkShader::kClamp_TileMode)); 597 pts, colors, nullptr, ARRAY_SIZE(colors), SkShader::kClamp_TileMode));
607 PaintRecorder recorder; 598 PaintRecorder recorder;
608 recorder.beginRecording(kW, kH); 599 recorder.beginRecording(kW, kH);
609 recorder.getRecordingCanvas()->drawCircle(kR, kR, kR, flags); 600 recorder.getRecordingCanvas()->drawCircle(kR, kR, kR, flags);
610 601
611 return recorder.finishRecordingAsPicture(); 602 return recorder.finishRecordingAsPicture();
612 } 603 }
613 604
614 #endif // OS(MACOSX) 605 #endif // OS(MACOSX)
615 606
616 } // anonymous ns 607 } // anonymous ns
617 608
618 void GraphicsContext::drawLineForDocumentMarker(const FloatPoint& pt, 609 void GraphicsContext::drawLineForDocumentMarker(const FloatPoint& pt,
619 float width, 610 float width,
620 DocumentMarkerLineStyle style, 611 DocumentMarkerLineStyle style,
621 float zoom) { 612 float zoom) {
622 if (contextDisabled()) 613 if (contextDisabled())
623 return; 614 return;
624 615
625 DEFINE_STATIC_LOCAL( 616 DEFINE_STATIC_LOCAL(
626 PaintRecord*, spellingMarker, 617 PaintRecord*, spellingMarker,
627 (recordMarker(DocumentMarkerSpellingLineStyle).release())); 618 (recordMarker(DocumentMarkerSpellingLineStyle).release()));
628 DEFINE_STATIC_LOCAL(PaintRecord*, grammarMarker, 619 DEFINE_STATIC_LOCAL(PaintRecord*, grammarMarker,
629 (recordMarker(DocumentMarkerGrammarLineStyle).release())); 620 (recordMarker(DocumentMarkerGrammarLineStyle).release()));
630 const auto& marker = style == DocumentMarkerSpellingLineStyle 621 const auto& marker =
631 ? spellingMarker 622 style == DocumentMarkerSpellingLineStyle ? spellingMarker : grammarMarker;
632 : grammarMarker;
633 623
634 // Position already includes zoom and device scale factor. 624 // Position already includes zoom and device scale factor.
635 SkScalar originX = WebCoreFloatToSkScalar(pt.x()); 625 SkScalar originX = WebCoreFloatToSkScalar(pt.x());
636 SkScalar originY = WebCoreFloatToSkScalar(pt.y()); 626 SkScalar originY = WebCoreFloatToSkScalar(pt.y());
637 627
638 #if OS(MACOSX) 628 #if OS(MACOSX)
639 // Make sure to draw only complete dots, and finish inside the marked text. 629 // Make sure to draw only complete dots, and finish inside the marked text.
640 width -= fmodf(width, marker->cullRect().width() * zoom); 630 width -= fmodf(width, marker->cullRect().width() * zoom);
641 #else 631 #else
642 // Offset it vertically by 1 so that there's some space under the text. 632 // Offset it vertically by 1 so that there's some space under the text.
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
1339 break; 1329 break;
1340 default: 1330 default:
1341 NOTREACHED(); 1331 NOTREACHED();
1342 break; 1332 break;
1343 } 1333 }
1344 1334
1345 return nullptr; 1335 return nullptr;
1346 } 1336 }
1347 1337
1348 } // namespace blink 1338 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698