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

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

Issue 2640983002: Rename paint data structures (Closed)
Patch Set: Rebase Created 3 years, 11 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
(...skipping 16 matching lines...) Expand all
27 #include "platform/graphics/GraphicsContext.h" 27 #include "platform/graphics/GraphicsContext.h"
28 28
29 #include "platform/geometry/FloatRect.h" 29 #include "platform/geometry/FloatRect.h"
30 #include "platform/geometry/FloatRoundedRect.h" 30 #include "platform/geometry/FloatRoundedRect.h"
31 #include "platform/geometry/IntRect.h" 31 #include "platform/geometry/IntRect.h"
32 #include "platform/graphics/ColorSpace.h" 32 #include "platform/graphics/ColorSpace.h"
33 #include "platform/graphics/GraphicsContextStateSaver.h" 33 #include "platform/graphics/GraphicsContextStateSaver.h"
34 #include "platform/graphics/ImageBuffer.h" 34 #include "platform/graphics/ImageBuffer.h"
35 #include "platform/graphics/Path.h" 35 #include "platform/graphics/Path.h"
36 #include "platform/graphics/paint/PaintController.h" 36 #include "platform/graphics/paint/PaintController.h"
37 #include "platform/graphics/paint/PaintRecord.h"
38 #include "platform/graphics/paint/PaintRecorder.h"
37 #include "platform/instrumentation/tracing/TraceEvent.h" 39 #include "platform/instrumentation/tracing/TraceEvent.h"
38 #include "platform/weborigin/KURL.h" 40 #include "platform/weborigin/KURL.h"
39 #include "skia/ext/platform_canvas.h" 41 #include "skia/ext/platform_canvas.h"
40 #include "third_party/skia/include/core/SkAnnotation.h" 42 #include "third_party/skia/include/core/SkAnnotation.h"
41 #include "third_party/skia/include/core/SkColorFilter.h" 43 #include "third_party/skia/include/core/SkColorFilter.h"
42 #include "third_party/skia/include/core/SkData.h" 44 #include "third_party/skia/include/core/SkData.h"
43 #include "third_party/skia/include/core/SkPicture.h"
44 #include "third_party/skia/include/core/SkPictureRecorder.h"
45 #include "third_party/skia/include/core/SkRRect.h" 45 #include "third_party/skia/include/core/SkRRect.h"
46 #include "third_party/skia/include/core/SkRefCnt.h" 46 #include "third_party/skia/include/core/SkRefCnt.h"
47 #include "third_party/skia/include/effects/SkLumaColorFilter.h" 47 #include "third_party/skia/include/effects/SkLumaColorFilter.h"
48 #include "third_party/skia/include/effects/SkPictureImageFilter.h" 48 #include "third_party/skia/include/effects/SkPictureImageFilter.h"
49 #include "third_party/skia/include/pathops/SkPathOps.h" 49 #include "third_party/skia/include/pathops/SkPathOps.h"
50 #include "third_party/skia/include/utils/SkNullCanvas.h" 50 #include "third_party/skia/include/utils/SkNullCanvas.h"
51 #include "wtf/Assertions.h" 51 #include "wtf/Assertions.h"
52 #include "wtf/MathExtras.h" 52 #include "wtf/MathExtras.h"
53 #include <memory> 53 #include <memory>
54 54
(...skipping 19 matching lines...) Expand all
74 m_hasMetaData(!!metaData) { 74 m_hasMetaData(!!metaData) {
75 if (metaData) 75 if (metaData)
76 m_metaData = *metaData; 76 m_metaData = *metaData;
77 77
78 // FIXME: Do some tests to determine how many states are typically used, and 78 // FIXME: Do some tests to determine how many states are typically used, and
79 // allocate several here. 79 // allocate several here.
80 m_paintStateStack.push_back(GraphicsContextState::create()); 80 m_paintStateStack.push_back(GraphicsContextState::create());
81 m_paintState = m_paintStateStack.back().get(); 81 m_paintState = m_paintStateStack.back().get();
82 82
83 if (contextDisabled()) { 83 if (contextDisabled()) {
84 DEFINE_STATIC_LOCAL(SkCanvas*, nullCanvas, (SkMakeNullCanvas().release())); 84 DEFINE_STATIC_LOCAL(SkCanvas*, nullSkCanvas,
85 m_canvas = nullCanvas; 85 (SkMakeNullCanvas().release()));
86 DEFINE_STATIC_LOCAL(PaintCanvasPassThrough, nullCanvas, (nullSkCanvas));
87 m_canvas = &nullCanvas;
86 } 88 }
87 } 89 }
88 90
89 GraphicsContext::~GraphicsContext() { 91 GraphicsContext::~GraphicsContext() {
90 #if DCHECK_IS_ON() 92 #if DCHECK_IS_ON()
91 if (!m_disableDestructionChecks) { 93 if (!m_disableDestructionChecks) {
92 ASSERT(!m_paintStateIndex); 94 ASSERT(!m_paintStateIndex);
93 ASSERT(!m_paintState->saveCount()); 95 ASSERT(!m_paintState->saveCount());
94 ASSERT(!m_layerCount); 96 ASSERT(!m_layerCount);
95 ASSERT(!saveCount()); 97 ASSERT(!saveCount());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 // (on top of its own saveCount), except for the first frame. 135 // (on top of its own saveCount), except for the first frame.
134 unsigned count = m_paintStateIndex; 136 unsigned count = m_paintStateIndex;
135 ASSERT(m_paintStateStack.size() > m_paintStateIndex); 137 ASSERT(m_paintStateStack.size() > m_paintStateIndex);
136 for (unsigned i = 0; i <= m_paintStateIndex; ++i) 138 for (unsigned i = 0; i <= m_paintStateIndex; ++i)
137 count += m_paintStateStack[i]->saveCount(); 139 count += m_paintStateStack[i]->saveCount();
138 140
139 return count; 141 return count;
140 } 142 }
141 #endif 143 #endif
142 144
143 void GraphicsContext::saveLayer(const SkRect* bounds, const SkPaint* paint) { 145 void GraphicsContext::saveLayer(const SkRect* bounds, const PaintFlags* paint) {
144 if (contextDisabled()) 146 if (contextDisabled())
145 return; 147 return;
146 148
147 ASSERT(m_canvas); 149 ASSERT(m_canvas);
148
149 m_canvas->saveLayer(bounds, paint); 150 m_canvas->saveLayer(bounds, paint);
150 } 151 }
151 152
152 void GraphicsContext::restoreLayer() { 153 void GraphicsContext::restoreLayer() {
153 if (contextDisabled()) 154 if (contextDisabled())
154 return; 155 return;
155 156
156 ASSERT(m_canvas); 157 ASSERT(m_canvas);
157 158
158 m_canvas->restore(); 159 m_canvas->restore();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 } 227 }
227 228
228 void GraphicsContext::beginLayer(float opacity, 229 void GraphicsContext::beginLayer(float opacity,
229 SkBlendMode xfermode, 230 SkBlendMode xfermode,
230 const FloatRect* bounds, 231 const FloatRect* bounds,
231 ColorFilter colorFilter, 232 ColorFilter colorFilter,
232 sk_sp<SkImageFilter> imageFilter) { 233 sk_sp<SkImageFilter> imageFilter) {
233 if (contextDisabled()) 234 if (contextDisabled())
234 return; 235 return;
235 236
236 SkPaint layerPaint; 237 PaintFlags layerPaint;
237 layerPaint.setAlpha(static_cast<unsigned char>(opacity * 255)); 238 layerPaint.setAlpha(static_cast<unsigned char>(opacity * 255));
238 layerPaint.setBlendMode(xfermode); 239 layerPaint.setBlendMode(xfermode);
239 layerPaint.setColorFilter(WebCoreColorFilterToSkiaColorFilter(colorFilter)); 240 layerPaint.setColorFilter(WebCoreColorFilterToSkiaColorFilter(colorFilter));
240 layerPaint.setImageFilter(std::move(imageFilter)); 241 layerPaint.setImageFilter(std::move(imageFilter));
241 242
242 if (bounds) { 243 if (bounds) {
243 SkRect skBounds = *bounds; 244 SkRect skBounds = *bounds;
244 saveLayer(&skBounds, &layerPaint); 245 saveLayer(&skBounds, &layerPaint);
245 } else { 246 } else {
246 saveLayer(nullptr, &layerPaint); 247 saveLayer(nullptr, &layerPaint);
(...skipping 20 matching lines...) Expand all
267 return; 268 return;
268 269
269 DCHECK(!m_canvas); 270 DCHECK(!m_canvas);
270 m_canvas = m_pictureRecorder.beginRecording(bounds, nullptr); 271 m_canvas = m_pictureRecorder.beginRecording(bounds, nullptr);
271 if (m_hasMetaData) 272 if (m_hasMetaData)
272 skia::GetMetaData(*m_canvas) = m_metaData; 273 skia::GetMetaData(*m_canvas) = m_metaData;
273 } 274 }
274 275
275 namespace { 276 namespace {
276 277
277 sk_sp<SkPicture> createEmptyPicture() { 278 sk_sp<PaintRecord> createEmptyPicture() {
278 SkPictureRecorder recorder; 279 PaintRecorder recorder;
279 recorder.beginRecording(SkRect::MakeEmpty(), nullptr); 280 recorder.beginRecording(SkRect::MakeEmpty(), nullptr);
280 return recorder.finishRecordingAsPicture(); 281 return recorder.finishRecordingAsPicture();
281 } 282 }
282 283
283 } // anonymous namespace 284 } // anonymous namespace
284 285
285 sk_sp<SkPicture> GraphicsContext::endRecording() { 286 sk_sp<PaintRecord> GraphicsContext::endRecording() {
286 if (contextDisabled()) { 287 if (contextDisabled()) {
287 // Clients expect endRecording() to always return a non-null picture. 288 // Clients expect endRecording() to always return a non-null picture.
288 // Cache an empty SKP to minimize overhead when disabled. 289 // Cache an empty SKP to minimize overhead when disabled.
289 DEFINE_STATIC_LOCAL(sk_sp<SkPicture>, emptyPicture, (createEmptyPicture())); 290 DEFINE_STATIC_LOCAL(sk_sp<PaintRecord>, emptyPicture,
291 (createEmptyPicture()));
290 return emptyPicture; 292 return emptyPicture;
291 } 293 }
292 294
293 sk_sp<SkPicture> picture = m_pictureRecorder.finishRecordingAsPicture(); 295 sk_sp<PaintRecord> picture = m_pictureRecorder.finishRecordingAsPicture();
294 m_canvas = nullptr; 296 m_canvas = nullptr;
295 ASSERT(picture); 297 ASSERT(picture);
296 return picture; 298 return picture;
297 } 299 }
298 300
299 void GraphicsContext::drawPicture(const SkPicture* picture) { 301 void GraphicsContext::drawPicture(const PaintRecord* picture) {
300 if (contextDisabled() || !picture || picture->cullRect().isEmpty()) 302 if (contextDisabled() || !picture || picture->cullRect().isEmpty())
301 return; 303 return;
302 304
303 ASSERT(m_canvas); 305 ASSERT(m_canvas);
304 m_canvas->drawPicture(picture); 306 m_canvas->drawPicture(picture);
305 } 307 }
306 308
307 void GraphicsContext::compositePicture(sk_sp<SkPicture> picture, 309 void GraphicsContext::compositePicture(sk_sp<PaintRecord> picture,
308 const FloatRect& dest, 310 const FloatRect& dest,
309 const FloatRect& src, 311 const FloatRect& src,
310 SkBlendMode op) { 312 SkBlendMode op) {
311 if (contextDisabled() || !picture) 313 if (contextDisabled() || !picture)
312 return; 314 return;
313 ASSERT(m_canvas); 315 ASSERT(m_canvas);
314 316
315 SkPaint picturePaint; 317 PaintFlags picturePaint;
316 picturePaint.setBlendMode(op); 318 picturePaint.setBlendMode(op);
317 m_canvas->save(); 319 m_canvas->save();
318 SkRect sourceBounds = src; 320 SkRect sourceBounds = src;
319 SkRect skBounds = dest; 321 SkRect skBounds = dest;
320 SkMatrix pictureTransform; 322 SkMatrix pictureTransform;
321 pictureTransform.setRectToRect(sourceBounds, skBounds, 323 pictureTransform.setRectToRect(sourceBounds, skBounds,
322 SkMatrix::kFill_ScaleToFit); 324 SkMatrix::kFill_ScaleToFit);
323 m_canvas->concat(pictureTransform); 325 m_canvas->concat(pictureTransform);
324 picturePaint.setImageFilter(SkPictureImageFilter::MakeForLocalSpace( 326 picturePaint.setImageFilter(SkPictureImageFilter::MakeForLocalSpace(
325 std::move(picture), sourceBounds, 327 ToSkPicture(picture), sourceBounds,
326 static_cast<SkFilterQuality>(imageInterpolationQuality()))); 328 static_cast<SkFilterQuality>(imageInterpolationQuality())));
327 m_canvas->saveLayer(&sourceBounds, &picturePaint); 329 m_canvas->saveLayer(&sourceBounds, &picturePaint);
328 m_canvas->restore(); 330 m_canvas->restore();
329 m_canvas->restore(); 331 m_canvas->restore();
330 } 332 }
331 333
332 void GraphicsContext::drawFocusRingPath(const SkPath& path, 334 void GraphicsContext::drawFocusRingPath(const SkPath& path,
333 const Color& color, 335 const Color& color,
334 float width) { 336 float width) {
335 drawPlatformFocusRing(path, m_canvas, color.rgb(), width); 337 drawPlatformFocusRing(path, m_canvas, color.rgb(), width);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 FloatPoint p1 = point1; 475 FloatPoint p1 = point1;
474 FloatPoint p2 = point2; 476 FloatPoint p2 = point2;
475 bool isVerticalLine = (p1.x() == p2.x()); 477 bool isVerticalLine = (p1.x() == p2.x());
476 int width = roundf(strokeThickness()); 478 int width = roundf(strokeThickness());
477 479
478 // We know these are vertical or horizontal lines, so the length will just 480 // We know these are vertical or horizontal lines, so the length will just
479 // be the sum of the displacement component vectors give or take 1 - 481 // be the sum of the displacement component vectors give or take 1 -
480 // probably worth the speed up of no square root, which also won't be exact. 482 // probably worth the speed up of no square root, which also won't be exact.
481 FloatSize disp = p2 - p1; 483 FloatSize disp = p2 - p1;
482 int length = SkScalarRoundToInt(disp.width() + disp.height()); 484 int length = SkScalarRoundToInt(disp.width() + disp.height());
483 SkPaint paint(immutableState()->strokePaint(length)); 485 PaintFlags paint(immutableState()->strokePaint(length));
484 486
485 if (getStrokeStyle() == DottedStroke || getStrokeStyle() == DashedStroke) { 487 if (getStrokeStyle() == DottedStroke || getStrokeStyle() == DashedStroke) {
486 // Do a rect fill of our endpoints. This ensures we always have the 488 // Do a rect fill of our endpoints. This ensures we always have the
487 // appearance of being a border. We then draw the actual dotted/dashed 489 // appearance of being a border. We then draw the actual dotted/dashed
488 // line. 490 // line.
489 SkRect r1, r2; 491 SkRect r1, r2;
490 r1.set(p1.x(), p1.y(), p1.x() + width, p1.y() + width); 492 r1.set(p1.x(), p1.y(), p1.x() + width, p1.y() + width);
491 r2.set(p2.x(), p2.y(), p2.x() + width, p2.y() + width); 493 r2.set(p2.x(), p2.y(), p2.x() + width, p2.y() + width);
492 494
493 if (isVerticalLine) { 495 if (isVerticalLine) {
494 r1.offset(-width / 2, 0); 496 r1.offset(-width / 2, 0);
495 r2.offset(-width / 2, -width); 497 r2.offset(-width / 2, -width);
496 } else { 498 } else {
497 r1.offset(0, -width / 2); 499 r1.offset(0, -width / 2);
498 r2.offset(-width, -width / 2); 500 r2.offset(-width, -width / 2);
499 } 501 }
500 SkPaint fillPaint; 502 PaintFlags fillPaint;
501 fillPaint.setColor(paint.getColor()); 503 fillPaint.setColor(paint.getColor());
502 drawRect(r1, fillPaint); 504 drawRect(r1, fillPaint);
503 drawRect(r2, fillPaint); 505 drawRect(r2, fillPaint);
504 } 506 }
505 507
506 adjustLineToPixelBoundaries(p1, p2, width, penStyle); 508 adjustLineToPixelBoundaries(p1, p2, width, penStyle);
507 m_canvas->drawLine(p1.x(), p1.y(), p2.x(), p2.y(), paint); 509 m_canvas->drawLine(p1.x(), p1.y(), p2.x(), p2.y(), paint);
508 } 510 }
509 511
510 void GraphicsContext::drawLineForDocumentMarker(const FloatPoint& pt, 512 void GraphicsContext::drawLineForDocumentMarker(const FloatPoint& pt,
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 621
620 // Offset it vertically by 1 so that there's some space under the text. 622 // Offset it vertically by 1 so that there's some space under the text.
621 SkScalar originY = WebCoreFloatToSkScalar(pt.y()) + 1; 623 SkScalar originY = WebCoreFloatToSkScalar(pt.y()) + 1;
622 originX *= deviceScaleFactor; 624 originX *= deviceScaleFactor;
623 originY *= deviceScaleFactor; 625 originY *= deviceScaleFactor;
624 #endif 626 #endif
625 627
626 SkMatrix localMatrix; 628 SkMatrix localMatrix;
627 localMatrix.setTranslate(originX, originY); 629 localMatrix.setTranslate(originX, originY);
628 630
629 SkPaint paint; 631 PaintFlags paint;
630 paint.setShader(SkShader::MakeBitmapShader( 632 paint.setShader(WrapSkShader(SkShader::MakeBitmapShader(
631 *misspellBitmap[index], SkShader::kRepeat_TileMode, 633 *misspellBitmap[index], SkShader::kRepeat_TileMode,
632 SkShader::kRepeat_TileMode, &localMatrix)); 634 SkShader::kRepeat_TileMode, &localMatrix)));
633 635
634 SkRect rect; 636 SkRect rect;
635 rect.set(originX, originY, 637 rect.set(originX, originY,
636 originX + WebCoreFloatToSkScalar(width) * deviceScaleFactor, 638 originX + WebCoreFloatToSkScalar(width) * deviceScaleFactor,
637 originY + SkIntToScalar(misspellBitmap[index]->height())); 639 originY + SkIntToScalar(misspellBitmap[index]->height()));
638 640
639 if (deviceScaleFactor == 2) { 641 if (deviceScaleFactor == 2) {
640 save(); 642 save();
641 scale(0.5, 0.5); 643 scale(0.5, 0.5);
642 } 644 }
643 drawRect(rect, paint); 645 drawRect(rect, paint);
644 if (deviceScaleFactor == 2) 646 if (deviceScaleFactor == 2)
645 restore(); 647 restore();
646 } 648 }
647 649
648 void GraphicsContext::drawLineForText(const FloatPoint& pt, float width) { 650 void GraphicsContext::drawLineForText(const FloatPoint& pt, float width) {
649 if (contextDisabled()) 651 if (contextDisabled())
650 return; 652 return;
651 653
652 if (width <= 0) 654 if (width <= 0)
653 return; 655 return;
654 656
655 SkPaint paint; 657 PaintFlags paint;
656 switch (getStrokeStyle()) { 658 switch (getStrokeStyle()) {
657 case NoStroke: 659 case NoStroke:
658 case SolidStroke: 660 case SolidStroke:
659 case DoubleStroke: { 661 case DoubleStroke: {
660 int thickness = SkMax32(static_cast<int>(strokeThickness()), 1); 662 int thickness = SkMax32(static_cast<int>(strokeThickness()), 1);
661 SkRect r; 663 SkRect r;
662 r.fLeft = WebCoreFloatToSkScalar(pt.x()); 664 r.fLeft = WebCoreFloatToSkScalar(pt.x());
663 // Avoid anti-aliasing lines. Currently, these are always horizontal. 665 // Avoid anti-aliasing lines. Currently, these are always horizontal.
664 // Round to nearest pixel to match text and other content. 666 // Round to nearest pixel to match text and other content.
665 r.fTop = WebCoreFloatToSkScalar(floorf(pt.y() + 0.5f)); 667 r.fTop = WebCoreFloatToSkScalar(floorf(pt.y() + 0.5f));
(...skipping 28 matching lines...) Expand all
694 if (rect.isEmpty()) 696 if (rect.isEmpty())
695 return; 697 return;
696 698
697 SkRect skRect = rect; 699 SkRect skRect = rect;
698 if (immutableState()->fillColor().alpha()) 700 if (immutableState()->fillColor().alpha())
699 drawRect(skRect, immutableState()->fillPaint()); 701 drawRect(skRect, immutableState()->fillPaint());
700 702
701 if (immutableState()->getStrokeData().style() != NoStroke && 703 if (immutableState()->getStrokeData().style() != NoStroke &&
702 immutableState()->strokeColor().alpha()) { 704 immutableState()->strokeColor().alpha()) {
703 // Stroke a width: 1 inset border 705 // Stroke a width: 1 inset border
704 SkPaint paint(immutableState()->fillPaint()); 706 PaintFlags paint(immutableState()->fillPaint());
705 paint.setColor(strokeColor().rgb()); 707 paint.setColor(strokeColor().rgb());
706 paint.setStyle(SkPaint::kStroke_Style); 708 paint.setStyle(PaintFlags::kStroke_Style);
707 paint.setStrokeWidth(1); 709 paint.setStrokeWidth(1);
708 710
709 skRect.inset(0.5f, 0.5f); 711 skRect.inset(0.5f, 0.5f);
710 drawRect(skRect, paint); 712 drawRect(skRect, paint);
711 } 713 }
712 } 714 }
713 715
714 void GraphicsContext::drawText(const Font& font, 716 void GraphicsContext::drawText(const Font& font,
715 const TextRunPaintInfo& runInfo, 717 const TextRunPaintInfo& runInfo,
716 const FloatPoint& point, 718 const FloatPoint& point,
717 const SkPaint& paint) { 719 const PaintFlags& paint) {
718 if (contextDisabled()) 720 if (contextDisabled())
719 return; 721 return;
720 722
721 if (font.drawText(m_canvas, runInfo, point, m_deviceScaleFactor, paint)) 723 if (font.drawText(m_canvas, runInfo, point, m_deviceScaleFactor, paint))
722 m_paintController.setTextPainted(); 724 m_paintController.setTextPainted();
723 } 725 }
724 726
725 template <typename DrawTextFunc> 727 template <typename DrawTextFunc>
726 void GraphicsContext::drawTextPasses(const DrawTextFunc& drawText) { 728 void GraphicsContext::drawTextPasses(const DrawTextFunc& drawText) {
727 TextDrawingModeFlags modeFlags = textDrawingMode(); 729 TextDrawingModeFlags modeFlags = textDrawingMode();
728 730
729 if (modeFlags & TextModeFill) { 731 if (modeFlags & TextModeFill) {
730 drawText(immutableState()->fillPaint()); 732 drawText(immutableState()->fillPaint());
731 } 733 }
732 734
733 if ((modeFlags & TextModeStroke) && getStrokeStyle() != NoStroke && 735 if ((modeFlags & TextModeStroke) && getStrokeStyle() != NoStroke &&
734 strokeThickness() > 0) { 736 strokeThickness() > 0) {
735 SkPaint paintForStroking(immutableState()->strokePaint()); 737 PaintFlags paintForStroking(immutableState()->strokePaint());
736 if (modeFlags & TextModeFill) { 738 if (modeFlags & TextModeFill) {
737 paintForStroking.setLooper( 739 paintForStroking.setLooper(
738 0); // shadow was already applied during fill pass 740 0); // shadow was already applied during fill pass
739 } 741 }
740 drawText(paintForStroking); 742 drawText(paintForStroking);
741 } 743 }
742 } 744 }
743 745
744 void GraphicsContext::drawText(const Font& font, 746 void GraphicsContext::drawText(const Font& font,
745 const TextRunPaintInfo& runInfo, 747 const TextRunPaintInfo& runInfo,
746 const FloatPoint& point) { 748 const FloatPoint& point) {
747 if (contextDisabled()) 749 if (contextDisabled())
748 return; 750 return;
749 751
750 drawTextPasses([&font, &runInfo, &point, this](const SkPaint& paint) { 752 drawTextPasses([&font, &runInfo, &point, this](const PaintFlags& paint) {
751 if (font.drawText(m_canvas, runInfo, point, m_deviceScaleFactor, paint)) 753 if (font.drawText(m_canvas, runInfo, point, m_deviceScaleFactor, paint))
752 m_paintController.setTextPainted(); 754 m_paintController.setTextPainted();
753 }); 755 });
754 } 756 }
755 757
756 void GraphicsContext::drawEmphasisMarks(const Font& font, 758 void GraphicsContext::drawEmphasisMarks(const Font& font,
757 const TextRunPaintInfo& runInfo, 759 const TextRunPaintInfo& runInfo,
758 const AtomicString& mark, 760 const AtomicString& mark,
759 const FloatPoint& point) { 761 const FloatPoint& point) {
760 if (contextDisabled()) 762 if (contextDisabled())
761 return; 763 return;
762 764
763 drawTextPasses([&font, &runInfo, &mark, &point, this](const SkPaint& paint) { 765 drawTextPasses([&font, &runInfo, &mark, &point,
766 this](const PaintFlags& paint) {
764 font.drawEmphasisMarks(m_canvas, runInfo, mark, point, m_deviceScaleFactor, 767 font.drawEmphasisMarks(m_canvas, runInfo, mark, point, m_deviceScaleFactor,
765 paint); 768 paint);
766 }); 769 });
767 } 770 }
768 771
769 void GraphicsContext::drawBidiText( 772 void GraphicsContext::drawBidiText(
770 const Font& font, 773 const Font& font,
771 const TextRunPaintInfo& runInfo, 774 const TextRunPaintInfo& runInfo,
772 const FloatPoint& point, 775 const FloatPoint& point,
773 Font::CustomFontNotReadyAction customFontNotReadyAction) { 776 Font::CustomFontNotReadyAction customFontNotReadyAction) {
774 if (contextDisabled()) 777 if (contextDisabled())
775 return; 778 return;
776 779
777 drawTextPasses([&font, &runInfo, &point, customFontNotReadyAction, 780 drawTextPasses([&font, &runInfo, &point, customFontNotReadyAction,
778 this](const SkPaint& paint) { 781 this](const PaintFlags& paint) {
779 if (font.drawBidiText(m_canvas, runInfo, point, customFontNotReadyAction, 782 if (font.drawBidiText(m_canvas, runInfo, point, customFontNotReadyAction,
780 m_deviceScaleFactor, paint)) 783 m_deviceScaleFactor, paint))
781 m_paintController.setTextPainted(); 784 m_paintController.setTextPainted();
782 }); 785 });
783 } 786 }
784 787
785 void GraphicsContext::drawHighlightForText(const Font& font, 788 void GraphicsContext::drawHighlightForText(const Font& font,
786 const TextRun& run, 789 const TextRun& run,
787 const FloatPoint& point, 790 const FloatPoint& point,
788 int h, 791 int h,
(...skipping 10 matching lines...) Expand all
799 Image* image, 802 Image* image,
800 const FloatRect& dest, 803 const FloatRect& dest,
801 const FloatRect* srcPtr, 804 const FloatRect* srcPtr,
802 SkBlendMode op, 805 SkBlendMode op,
803 RespectImageOrientationEnum shouldRespectImageOrientation) { 806 RespectImageOrientationEnum shouldRespectImageOrientation) {
804 if (contextDisabled() || !image) 807 if (contextDisabled() || !image)
805 return; 808 return;
806 809
807 const FloatRect src = srcPtr ? *srcPtr : image->rect(); 810 const FloatRect src = srcPtr ? *srcPtr : image->rect();
808 811
809 SkPaint imagePaint = immutableState()->fillPaint(); 812 PaintFlags imagePaint = immutableState()->fillPaint();
810 imagePaint.setBlendMode(op); 813 imagePaint.setBlendMode(op);
811 imagePaint.setColor(SK_ColorBLACK); 814 imagePaint.setColor(SK_ColorBLACK);
812 imagePaint.setFilterQuality(computeFilterQuality(image, dest, src)); 815 imagePaint.setFilterQuality(computeFilterQuality(image, dest, src));
813 imagePaint.setAntiAlias(shouldAntialias()); 816 imagePaint.setAntiAlias(shouldAntialias());
814 image->draw(m_canvas, imagePaint, dest, src, shouldRespectImageOrientation, 817 image->draw(m_canvas, imagePaint, dest, src, shouldRespectImageOrientation,
815 Image::ClampImageToSourceRect, m_colorBehavior); 818 Image::ClampImageToSourceRect, m_colorBehavior);
816 m_paintController.setImagePainted(); 819 m_paintController.setImagePainted();
817 } 820 }
818 821
819 void GraphicsContext::drawImageRRect( 822 void GraphicsContext::drawImageRRect(
820 Image* image, 823 Image* image,
821 const FloatRoundedRect& dest, 824 const FloatRoundedRect& dest,
822 const FloatRect& srcRect, 825 const FloatRect& srcRect,
823 SkBlendMode op, 826 SkBlendMode op,
824 RespectImageOrientationEnum respectOrientation) { 827 RespectImageOrientationEnum respectOrientation) {
825 if (contextDisabled() || !image) 828 if (contextDisabled() || !image)
826 return; 829 return;
827 830
828 if (!dest.isRounded()) { 831 if (!dest.isRounded()) {
829 drawImage(image, dest.rect(), &srcRect, op, respectOrientation); 832 drawImage(image, dest.rect(), &srcRect, op, respectOrientation);
830 return; 833 return;
831 } 834 }
832 835
833 DCHECK(dest.isRenderable()); 836 DCHECK(dest.isRenderable());
834 837
835 const FloatRect visibleSrc = intersection(srcRect, image->rect()); 838 const FloatRect visibleSrc = intersection(srcRect, image->rect());
836 if (dest.isEmpty() || visibleSrc.isEmpty()) 839 if (dest.isEmpty() || visibleSrc.isEmpty())
837 return; 840 return;
838 841
839 SkPaint imagePaint = immutableState()->fillPaint(); 842 PaintFlags imagePaint = immutableState()->fillPaint();
840 imagePaint.setBlendMode(op); 843 imagePaint.setBlendMode(op);
841 imagePaint.setColor(SK_ColorBLACK); 844 imagePaint.setColor(SK_ColorBLACK);
842 imagePaint.setFilterQuality( 845 imagePaint.setFilterQuality(
843 computeFilterQuality(image, dest.rect(), srcRect)); 846 computeFilterQuality(image, dest.rect(), srcRect));
844 imagePaint.setAntiAlias(shouldAntialias()); 847 imagePaint.setAntiAlias(shouldAntialias());
845 848
846 bool useShader = (visibleSrc == srcRect) && 849 bool useShader = (visibleSrc == srcRect) &&
847 (respectOrientation == DoNotRespectImageOrientation); 850 (respectOrientation == DoNotRespectImageOrientation);
848 if (useShader) { 851 if (useShader) {
849 const SkMatrix localMatrix = SkMatrix::MakeRectToRect( 852 const SkMatrix localMatrix = SkMatrix::MakeRectToRect(
850 visibleSrc, dest.rect(), SkMatrix::kFill_ScaleToFit); 853 visibleSrc, dest.rect(), SkMatrix::kFill_ScaleToFit);
851 useShader = image->applyShader(imagePaint, localMatrix, m_colorBehavior); 854 useShader = image->applyShader(imagePaint, localMatrix, m_colorBehavior);
852 } 855 }
853 856
854 if (useShader) { 857 if (useShader) {
855 // Shader-based fast path. 858 // Shader-based fast path.
856 m_canvas->drawRRect(dest, imagePaint); 859 m_canvas->drawRRect(dest, imagePaint);
857 } else { 860 } else {
858 // Clip-based fallback. 861 // Clip-based fallback.
859 SkAutoCanvasRestore autoRestore(m_canvas, true); 862 PaintCanvasAutoRestore autoRestore(m_canvas, true);
860 m_canvas->clipRRect(dest, imagePaint.isAntiAlias()); 863 m_canvas->clipRRect(dest, imagePaint.isAntiAlias());
861 image->draw(m_canvas, imagePaint, dest.rect(), srcRect, respectOrientation, 864 image->draw(m_canvas, imagePaint, dest.rect(), srcRect, respectOrientation,
862 Image::ClampImageToSourceRect, m_colorBehavior); 865 Image::ClampImageToSourceRect, m_colorBehavior);
863 } 866 }
864 867
865 m_paintController.setImagePainted(); 868 m_paintController.setImagePainted();
866 } 869 }
867 870
868 SkFilterQuality GraphicsContext::computeFilterQuality( 871 SkFilterQuality GraphicsContext::computeFilterQuality(
869 Image* image, 872 Image* image,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 // Just do a scale. 921 // Just do a scale.
919 drawImage(image, dest, &srcRect, op); 922 drawImage(image, dest, &srcRect, op);
920 return; 923 return;
921 } 924 }
922 925
923 image->drawTiledBorder(*this, dest, srcRect, tileScaleFactor, hRule, vRule, 926 image->drawTiledBorder(*this, dest, srcRect, tileScaleFactor, hRule, vRule,
924 op); 927 op);
925 m_paintController.setImagePainted(); 928 m_paintController.setImagePainted();
926 } 929 }
927 930
928 void GraphicsContext::drawOval(const SkRect& oval, const SkPaint& paint) { 931 void GraphicsContext::drawOval(const SkRect& oval, const PaintFlags& paint) {
929 if (contextDisabled()) 932 if (contextDisabled())
930 return; 933 return;
931 ASSERT(m_canvas); 934 ASSERT(m_canvas);
932 935
933 m_canvas->drawOval(oval, paint); 936 m_canvas->drawOval(oval, paint);
934 } 937 }
935 938
936 void GraphicsContext::drawPath(const SkPath& path, const SkPaint& paint) { 939 void GraphicsContext::drawPath(const SkPath& path, const PaintFlags& paint) {
937 if (contextDisabled()) 940 if (contextDisabled())
938 return; 941 return;
939 ASSERT(m_canvas); 942 ASSERT(m_canvas);
940 943
941 m_canvas->drawPath(path, paint); 944 m_canvas->drawPath(path, paint);
942 } 945 }
943 946
944 void GraphicsContext::drawRect(const SkRect& rect, const SkPaint& paint) { 947 void GraphicsContext::drawRect(const SkRect& rect, const PaintFlags& paint) {
945 if (contextDisabled()) 948 if (contextDisabled())
946 return; 949 return;
947 ASSERT(m_canvas); 950 ASSERT(m_canvas);
948 951
949 m_canvas->drawRect(rect, paint); 952 m_canvas->drawRect(rect, paint);
950 } 953 }
951 954
952 void GraphicsContext::drawRRect(const SkRRect& rrect, const SkPaint& paint) { 955 void GraphicsContext::drawRRect(const SkRRect& rrect, const PaintFlags& paint) {
953 if (contextDisabled()) 956 if (contextDisabled())
954 return; 957 return;
955 ASSERT(m_canvas); 958 ASSERT(m_canvas);
956 959
957 m_canvas->drawRRect(rrect, paint); 960 m_canvas->drawRRect(rrect, paint);
958 } 961 }
959 962
960 void GraphicsContext::fillPath(const Path& pathToFill) { 963 void GraphicsContext::fillPath(const Path& pathToFill) {
961 if (contextDisabled() || pathToFill.isEmpty()) 964 if (contextDisabled() || pathToFill.isEmpty())
962 return; 965 return;
963 966
964 drawPath(pathToFill.getSkPath(), immutableState()->fillPaint()); 967 drawPath(pathToFill.getSkPath(), immutableState()->fillPaint());
965 } 968 }
966 969
967 void GraphicsContext::fillRect(const FloatRect& rect) { 970 void GraphicsContext::fillRect(const FloatRect& rect) {
968 if (contextDisabled()) 971 if (contextDisabled())
969 return; 972 return;
970 973
971 drawRect(rect, immutableState()->fillPaint()); 974 drawRect(rect, immutableState()->fillPaint());
972 } 975 }
973 976
974 void GraphicsContext::fillRect(const FloatRect& rect, 977 void GraphicsContext::fillRect(const FloatRect& rect,
975 const Color& color, 978 const Color& color,
976 SkBlendMode xferMode) { 979 SkBlendMode xferMode) {
977 if (contextDisabled()) 980 if (contextDisabled())
978 return; 981 return;
979 982
980 SkPaint paint = immutableState()->fillPaint(); 983 PaintFlags paint = immutableState()->fillPaint();
981 paint.setColor(color.rgb()); 984 paint.setColor(color.rgb());
982 paint.setBlendMode(xferMode); 985 paint.setBlendMode(xferMode);
983 986
984 drawRect(rect, paint); 987 drawRect(rect, paint);
985 } 988 }
986 989
987 void GraphicsContext::fillRoundedRect(const FloatRoundedRect& rrect, 990 void GraphicsContext::fillRoundedRect(const FloatRoundedRect& rrect,
988 const Color& color) { 991 const Color& color) {
989 if (contextDisabled()) 992 if (contextDisabled())
990 return; 993 return;
991 994
992 if (!rrect.isRounded() || !rrect.isRenderable()) { 995 if (!rrect.isRounded() || !rrect.isRenderable()) {
993 fillRect(rrect.rect(), color); 996 fillRect(rrect.rect(), color);
994 return; 997 return;
995 } 998 }
996 999
997 if (color == fillColor()) { 1000 if (color == fillColor()) {
998 drawRRect(rrect, immutableState()->fillPaint()); 1001 drawRRect(rrect, immutableState()->fillPaint());
999 return; 1002 return;
1000 } 1003 }
1001 1004
1002 SkPaint paint = immutableState()->fillPaint(); 1005 PaintFlags paint = immutableState()->fillPaint();
1003 paint.setColor(color.rgb()); 1006 paint.setColor(color.rgb());
1004 1007
1005 drawRRect(rrect, paint); 1008 drawRRect(rrect, paint);
1006 } 1009 }
1007 1010
1008 namespace { 1011 namespace {
1009 1012
1010 bool isSimpleDRRect(const FloatRoundedRect& outer, 1013 bool isSimpleDRRect(const FloatRoundedRect& outer,
1011 const FloatRoundedRect& inner) { 1014 const FloatRoundedRect& inner) {
1012 // A DRRect is "simple" (i.e. can be drawn as a rrect stroke) if 1015 // A DRRect is "simple" (i.e. can be drawn as a rrect stroke) if
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 const FloatRoundedRect& inner, 1066 const FloatRoundedRect& inner,
1064 const Color& color) { 1067 const Color& color) {
1065 if (contextDisabled()) 1068 if (contextDisabled())
1066 return; 1069 return;
1067 ASSERT(m_canvas); 1070 ASSERT(m_canvas);
1068 1071
1069 if (!isSimpleDRRect(outer, inner)) { 1072 if (!isSimpleDRRect(outer, inner)) {
1070 if (color == fillColor()) { 1073 if (color == fillColor()) {
1071 m_canvas->drawDRRect(outer, inner, immutableState()->fillPaint()); 1074 m_canvas->drawDRRect(outer, inner, immutableState()->fillPaint());
1072 } else { 1075 } else {
1073 SkPaint paint(immutableState()->fillPaint()); 1076 PaintFlags paint(immutableState()->fillPaint());
1074 paint.setColor(color.rgb()); 1077 paint.setColor(color.rgb());
1075 m_canvas->drawDRRect(outer, inner, paint); 1078 m_canvas->drawDRRect(outer, inner, paint);
1076 } 1079 }
1077 1080
1078 return; 1081 return;
1079 } 1082 }
1080 1083
1081 // We can draw this as a stroked rrect. 1084 // We can draw this as a stroked rrect.
1082 float strokeWidth = inner.rect().x() - outer.rect().x(); 1085 float strokeWidth = inner.rect().x() - outer.rect().x();
1083 SkRRect strokeRRect = outer; 1086 SkRRect strokeRRect = outer;
1084 strokeRRect.inset(strokeWidth / 2, strokeWidth / 2); 1087 strokeRRect.inset(strokeWidth / 2, strokeWidth / 2);
1085 1088
1086 SkPaint strokePaint(immutableState()->fillPaint()); 1089 PaintFlags strokePaint(immutableState()->fillPaint());
1087 strokePaint.setColor(color.rgb()); 1090 strokePaint.setColor(color.rgb());
1088 strokePaint.setStyle(SkPaint::kStroke_Style); 1091 strokePaint.setStyle(PaintFlags::kStroke_Style);
1089 strokePaint.setStrokeWidth(strokeWidth); 1092 strokePaint.setStrokeWidth(strokeWidth);
1090 1093
1091 m_canvas->drawRRect(strokeRRect, strokePaint); 1094 m_canvas->drawRRect(strokeRRect, strokePaint);
1092 } 1095 }
1093 1096
1094 void GraphicsContext::fillEllipse(const FloatRect& ellipse) { 1097 void GraphicsContext::fillEllipse(const FloatRect& ellipse) {
1095 if (contextDisabled()) 1098 if (contextDisabled())
1096 return; 1099 return;
1097 1100
1098 drawOval(ellipse, immutableState()->fillPaint()); 1101 drawOval(ellipse, immutableState()->fillPaint());
1099 } 1102 }
1100 1103
1101 void GraphicsContext::strokePath(const Path& pathToStroke) { 1104 void GraphicsContext::strokePath(const Path& pathToStroke) {
1102 if (contextDisabled() || pathToStroke.isEmpty()) 1105 if (contextDisabled() || pathToStroke.isEmpty())
1103 return; 1106 return;
1104 1107
1105 drawPath(pathToStroke.getSkPath(), immutableState()->strokePaint()); 1108 drawPath(pathToStroke.getSkPath(), immutableState()->strokePaint());
1106 } 1109 }
1107 1110
1108 void GraphicsContext::strokeRect(const FloatRect& rect, float lineWidth) { 1111 void GraphicsContext::strokeRect(const FloatRect& rect, float lineWidth) {
1109 if (contextDisabled()) 1112 if (contextDisabled())
1110 return; 1113 return;
1111 1114
1112 SkPaint paint(immutableState()->strokePaint()); 1115 PaintFlags paint(immutableState()->strokePaint());
1113 paint.setStrokeWidth(WebCoreFloatToSkScalar(lineWidth)); 1116 paint.setStrokeWidth(WebCoreFloatToSkScalar(lineWidth));
1114 // Reset the dash effect to account for the width 1117 // Reset the dash effect to account for the width
1115 immutableState()->getStrokeData().setupPaintDashPathEffect(&paint, 0); 1118 immutableState()->getStrokeData().setupPaintDashPathEffect(&paint, 0);
1116 // strokerect has special rules for CSS when the rect is degenerate: 1119 // strokerect has special rules for CSS when the rect is degenerate:
1117 // if width==0 && height==0, do nothing 1120 // if width==0 && height==0, do nothing
1118 // if width==0 || height==0, then just draw line for the other dimension 1121 // if width==0 || height==0, then just draw line for the other dimension
1119 SkRect r(rect); 1122 SkRect r(rect);
1120 bool validW = r.width() > 0; 1123 bool validW = r.width() > 0;
1121 bool validH = r.height() > 0; 1124 bool validH = r.height() > 0;
1122 if (validW && validH) { 1125 if (validW && validH) {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 concat(affineTransformToSkMatrix(affine)); 1267 concat(affineTransformToSkMatrix(affine));
1265 } 1268 }
1266 1269
1267 void GraphicsContext::fillRectWithRoundedHole( 1270 void GraphicsContext::fillRectWithRoundedHole(
1268 const FloatRect& rect, 1271 const FloatRect& rect,
1269 const FloatRoundedRect& roundedHoleRect, 1272 const FloatRoundedRect& roundedHoleRect,
1270 const Color& color) { 1273 const Color& color) {
1271 if (contextDisabled()) 1274 if (contextDisabled())
1272 return; 1275 return;
1273 1276
1274 SkPaint paint(immutableState()->fillPaint()); 1277 PaintFlags paint(immutableState()->fillPaint());
1275 paint.setColor(color.rgb()); 1278 paint.setColor(color.rgb());
1276 m_canvas->drawDRRect(SkRRect::MakeRect(rect), roundedHoleRect, paint); 1279 m_canvas->drawDRRect(SkRRect::MakeRect(rect), roundedHoleRect, paint);
1277 } 1280 }
1278 1281
1279 void GraphicsContext::adjustLineToPixelBoundaries(FloatPoint& p1, 1282 void GraphicsContext::adjustLineToPixelBoundaries(FloatPoint& p1,
1280 FloatPoint& p2, 1283 FloatPoint& p2,
1281 float strokeWidth, 1284 float strokeWidth,
1282 StrokeStyle penStyle) { 1285 StrokeStyle penStyle) {
1283 // For odd widths, we add in 0.5 to the appropriate x/y so that the float 1286 // For odd widths, we add in 0.5 to the appropriate x/y so that the float
1284 // arithmetic works out. For example, with a border width of 3, WebKit will 1287 // arithmetic works out. For example, with a border width of 3, WebKit will
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 static const SkPMColor colors[] = { 1417 static const SkPMColor colors[] = {
1415 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red 1418 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red
1416 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray 1419 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray
1417 }; 1420 };
1418 1421
1419 return colors[index]; 1422 return colors[index];
1420 } 1423 }
1421 #endif 1424 #endif
1422 1425
1423 } // namespace blink 1426 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698