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

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

Issue 1331533002: [poc] curve-filter Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix CanvasRenderingContext2D::createPattern crash for #40 Created 4 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 ASSERT(!m_layerCount); 89 ASSERT(!m_layerCount);
90 ASSERT(!saveCount()); 90 ASSERT(!saveCount());
91 } 91 }
92 #endif 92 #endif
93 } 93 }
94 94
95 void GraphicsContext::save() 95 void GraphicsContext::save()
96 { 96 {
97 if (contextDisabled()) 97 if (contextDisabled())
98 return; 98 return;
99 ASSERT(m_canvas);
99 100
100 m_paintState->incrementSaveCount(); 101 m_paintState->incrementSaveCount();
101
102 ASSERT(m_canvas);
103 m_canvas->save(); 102 m_canvas->save();
104 } 103 }
105 104
106 void GraphicsContext::restore() 105 void GraphicsContext::restore()
107 { 106 {
108 if (contextDisabled()) 107 if (contextDisabled())
109 return; 108 return;
109 ASSERT(m_canvas);
110 110
111 if (!m_paintStateIndex && !m_paintState->saveCount()) { 111 if (!m_paintStateIndex && !m_paintState->saveCount()) {
112 WTF_LOG_ERROR("ERROR void GraphicsContext::restore() stack is empty"); 112 WTF_LOG_ERROR("ERROR void GraphicsContext::restore() stack is empty");
113 return; 113 return;
114 } 114 }
115 115
116 if (m_paintState->saveCount()) { 116 if (m_paintState->saveCount()) {
117 m_paintState->decrementSaveCount(); 117 m_paintState->decrementSaveCount();
118 } else { 118 } else {
119 m_paintStateIndex--; 119 m_paintStateIndex--;
120 m_paintState = m_paintStateStack[m_paintStateIndex].get(); 120 m_paintState = m_paintStateStack[m_paintStateIndex].get();
121 } 121 }
122 122
123 ASSERT(m_canvas);
124 m_canvas->restore(); 123 m_canvas->restore();
125 } 124 }
126 125
127 #if ENABLE(ASSERT) 126 #if ENABLE(ASSERT)
128 unsigned GraphicsContext::saveCount() const 127 unsigned GraphicsContext::saveCount() const
129 { 128 {
130 // Each m_paintStateStack entry implies an additional save op 129 // Each m_paintStateStack entry implies an additional save op
131 // (on top of its own saveCount), except for the first frame. 130 // (on top of its own saveCount), except for the first frame.
132 unsigned count = m_paintStateIndex; 131 unsigned count = m_paintStateIndex;
133 ASSERT(m_paintStateStack.size() > m_paintStateIndex); 132 ASSERT(m_paintStateStack.size() > m_paintStateIndex);
134 for (unsigned i = 0; i <= m_paintStateIndex; ++i) 133 for (unsigned i = 0; i <= m_paintStateIndex; ++i)
135 count += m_paintStateStack[i]->saveCount(); 134 count += m_paintStateStack[i]->saveCount();
136 135
137 return count; 136 return count;
138 } 137 }
139 #endif 138 #endif
140 139
141 void GraphicsContext::saveLayer(const SkRect* bounds, const SkPaint* paint) 140 void GraphicsContext::saveLayer(const SkRect* bounds, const SkPaint* paint)
142 { 141 {
143 if (contextDisabled()) 142 if (contextDisabled())
144 return; 143 return;
145
146 ASSERT(m_canvas); 144 ASSERT(m_canvas);
147 145
148 m_canvas->saveLayer(bounds, paint); 146 m_canvas->saveLayer(bounds, paint);
149 } 147 }
150 148
151 void GraphicsContext::restoreLayer() 149 void GraphicsContext::restoreLayer()
152 { 150 {
153 if (contextDisabled()) 151 if (contextDisabled())
154 return; 152 return;
155
156 ASSERT(m_canvas); 153 ASSERT(m_canvas);
157 154
158 m_canvas->restore(); 155 m_canvas->restore();
159 } 156 }
160 157
161 #if ENABLE(ASSERT) 158 #if ENABLE(ASSERT)
162 void GraphicsContext::setInDrawingRecorder(bool val) 159 void GraphicsContext::setInDrawingRecorder(bool val)
163 { 160 {
164 // Nested drawing recorers are not allowed. 161 // Nested drawing recorers are not allowed.
165 ASSERT(!val || !m_inDrawingRecorder); 162 ASSERT(!val || !m_inDrawingRecorder);
166 m_inDrawingRecorder = val; 163 m_inDrawingRecorder = val;
167 } 164 }
168 #endif 165 #endif
169 166
170 void GraphicsContext::setStrokeGradient(PassRefPtr<Gradient> gradient, float alp ha) 167 void GraphicsContext::setStrokeGradient(PassRefPtr<Gradient> gradient, float alp ha)
171 { 168 {
172 if (contextDisabled()) 169 if (contextDisabled())
173 return; 170 return;
174 171
175 ASSERT(gradient); 172 ASSERT(gradient);
176 if (!gradient) { 173 if (!gradient) {
177 setStrokeColor(Color::black); 174 setStrokeColor(Color::black);
178 return; 175 return;
179 } 176 }
177
180 mutableState()->setStrokeGradient(gradient, alpha); 178 mutableState()->setStrokeGradient(gradient, alpha);
181 } 179 }
182 180
183 void GraphicsContext::setFillGradient(PassRefPtr<Gradient> gradient, float alpha ) 181 void GraphicsContext::setFillGradient(PassRefPtr<Gradient> gradient, float alpha )
184 { 182 {
185 if (contextDisabled()) 183 if (contextDisabled())
186 return; 184 return;
187 185
188 ASSERT(gradient); 186 ASSERT(gradient);
189 if (!gradient) { 187 if (!gradient) {
(...skipping 15 matching lines...) Expand all
205 if (!color.alpha()) { 203 if (!color.alpha()) {
206 if (shadowMode == DrawShadowOnly) { 204 if (shadowMode == DrawShadowOnly) {
207 // shadow only, but there is no shadow: use an empty draw looper to disable rendering of the source primitive 205 // shadow only, but there is no shadow: use an empty draw looper to disable rendering of the source primitive
208 setDrawLooper(drawLooperBuilder.release()); 206 setDrawLooper(drawLooperBuilder.release());
209 return; 207 return;
210 } 208 }
211 clearDrawLooper(); 209 clearDrawLooper();
212 return; 210 return;
213 } 211 }
214 212
215 drawLooperBuilder->addShadow(offset, blur, color, shadowTransformMode, shado wAlphaMode); 213 drawLooperBuilder->addShadow(offset, blur, Color::toDeviceColor(color), shad owTransformMode, shadowAlphaMode);
216 if (shadowMode == DrawShadowAndForeground) { 214 if (shadowMode == DrawShadowAndForeground) {
217 drawLooperBuilder->addUnmodifiedContent(); 215 drawLooperBuilder->addUnmodifiedContent();
218 } 216 }
219 setDrawLooper(drawLooperBuilder.release()); 217 setDrawLooper(drawLooperBuilder.release());
220 } 218 }
221 219
222 void GraphicsContext::setDrawLooper(PassOwnPtr<DrawLooperBuilder> drawLooperBuil der) 220 void GraphicsContext::setDrawLooper(PassOwnPtr<DrawLooperBuilder> drawLooperBuil der)
223 { 221 {
224 if (contextDisabled()) 222 if (contextDisabled())
225 return; 223 return;
(...skipping 21 matching lines...) Expand all
247 // We only support one active color filter at the moment. If (when) this bec omes a problem, 245 // We only support one active color filter at the moment. If (when) this bec omes a problem,
248 // we should switch to using color filter chains (Skia work in progress). 246 // we should switch to using color filter chains (Skia work in progress).
249 ASSERT(!stateToSet->colorFilter()); 247 ASSERT(!stateToSet->colorFilter());
250 stateToSet->setColorFilter(WebCoreColorFilterToSkiaColorFilter(colorFilter)) ; 248 stateToSet->setColorFilter(WebCoreColorFilterToSkiaColorFilter(colorFilter)) ;
251 } 249 }
252 250
253 void GraphicsContext::concat(const SkMatrix& matrix) 251 void GraphicsContext::concat(const SkMatrix& matrix)
254 { 252 {
255 if (contextDisabled()) 253 if (contextDisabled())
256 return; 254 return;
257
258 ASSERT(m_canvas); 255 ASSERT(m_canvas);
259 256
260 m_canvas->concat(matrix); 257 m_canvas->concat(matrix);
261 } 258 }
262 259
263 void GraphicsContext::beginLayer(float opacity, SkXfermode::Mode xfermode, const FloatRect* bounds, ColorFilter colorFilter, SkImageFilter* imageFilter) 260 void GraphicsContext::beginLayer(float opacity, SkXfermode::Mode xfermode, const FloatRect* bounds, ColorFilter colorFilter, SkImageFilter* imageFilter)
264 { 261 {
265 if (contextDisabled()) 262 if (contextDisabled())
266 return; 263 return;
267 264
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 { 346 {
350 if (contextDisabled()) 347 if (contextDisabled())
351 return; 348 return;
352 349
353 ASSERT(numPoints > 2); 350 ASSERT(numPoints > 2);
354 351
355 SkPath path; 352 SkPath path;
356 setPathFromPoints(&path, numPoints, points); 353 setPathFromPoints(&path, numPoints, points);
357 354
358 SkPaint paint(immutableState()->fillPaint()); 355 SkPaint paint(immutableState()->fillPaint());
356 paint.setColor(Color::toDeviceColor(color).rgb());
359 paint.setAntiAlias(shouldAntialias); 357 paint.setAntiAlias(shouldAntialias);
360 paint.setColor(color.rgb());
361 358
362 drawPath(path, paint); 359 drawPath(path, paint);
363 } 360 }
364 361
365 void GraphicsContext::drawFocusRingPath(const SkPath& path, const Color& color, int width) 362 void GraphicsContext::drawFocusRingPath(const SkPath& path, const Color& color, int width)
366 { 363 {
367 drawPlatformFocusRing(path, m_canvas, color.rgb(), width); 364 drawPlatformFocusRing(path, m_canvas, Color::toDeviceColor(color).rgb(), wid th);
368 } 365 }
369 366
370 void GraphicsContext::drawFocusRingRect(const SkRect& rect, const Color& color, int width) 367 void GraphicsContext::drawFocusRingRect(const SkRect& rect, const Color& color, int width)
371 { 368 {
372 drawPlatformFocusRing(rect, m_canvas, color.rgb(), width); 369 drawPlatformFocusRing(rect, m_canvas, Color::toDeviceColor(color).rgb(), wid th);
373 } 370 }
374 371
375 void GraphicsContext::drawFocusRing(const Path& focusRingPath, int width, int of fset, const Color& color) 372 void GraphicsContext::drawFocusRing(const Path& focusRingPath, int width, int of fset, const Color& color)
376 { 373 {
377 // FIXME: Implement support for offset. 374 // FIXME: Implement support for offset.
378 if (contextDisabled()) 375 if (contextDisabled())
379 return; 376 return;
380 377
381 drawFocusRingPath(focusRingPath.skPath(), color, width); 378 drawFocusRingPath(focusRingPath.skPath(), color, width);
382 } 379 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 clipRoundedRect(rect); 461 clipRoundedRect(rect);
465 if (shadowSpread < 0) 462 if (shadowSpread < 0)
466 roundedHole.expandRadii(-shadowSpread); 463 roundedHole.expandRadii(-shadowSpread);
467 else 464 else
468 roundedHole.shrinkRadii(shadowSpread); 465 roundedHole.shrinkRadii(shadowSpread);
469 } else { 466 } else {
470 clip(rect.rect()); 467 clip(rect.rect());
471 } 468 }
472 469
473 OwnPtr<DrawLooperBuilder> drawLooperBuilder = DrawLooperBuilder::create(); 470 OwnPtr<DrawLooperBuilder> drawLooperBuilder = DrawLooperBuilder::create();
474 drawLooperBuilder->addShadow(FloatSize(shadowOffset), shadowBlur, shadowColo r, 471 drawLooperBuilder->addShadow(FloatSize(shadowOffset), shadowBlur, Color::toD eviceColor(shadowColor),
475 DrawLooperBuilder::ShadowRespectsTransforms, DrawLooperBuilder::ShadowIg noresAlpha); 472 DrawLooperBuilder::ShadowRespectsTransforms, DrawLooperBuilder::ShadowIg noresAlpha);
476 setDrawLooper(drawLooperBuilder.release()); 473 setDrawLooper(drawLooperBuilder.release());
474
477 fillRectWithRoundedHole(outerRect, roundedHole, fillColor); 475 fillRectWithRoundedHole(outerRect, roundedHole, fillColor);
478 } 476 }
479 477
480 void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2) 478 void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2)
481 { 479 {
482 if (contextDisabled()) 480 if (contextDisabled())
483 return; 481 return;
484 ASSERT(m_canvas); 482 ASSERT(m_canvas);
485 483
486 StrokeStyle penStyle = strokeStyle(); 484 StrokeStyle penStyle = strokeStyle();
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 int thickness = SkMax32(static_cast<int>(strokeThickness()), 1); 668 int thickness = SkMax32(static_cast<int>(strokeThickness()), 1);
671 SkRect r; 669 SkRect r;
672 r.fLeft = WebCoreFloatToSkScalar(pt.x()); 670 r.fLeft = WebCoreFloatToSkScalar(pt.x());
673 // Avoid anti-aliasing lines. Currently, these are always horizontal. 671 // Avoid anti-aliasing lines. Currently, these are always horizontal.
674 // Round to nearest pixel to match text and other content. 672 // Round to nearest pixel to match text and other content.
675 r.fTop = WebCoreFloatToSkScalar(floorf(pt.y() + 0.5f)); 673 r.fTop = WebCoreFloatToSkScalar(floorf(pt.y() + 0.5f));
676 r.fRight = r.fLeft + WebCoreFloatToSkScalar(width); 674 r.fRight = r.fLeft + WebCoreFloatToSkScalar(width);
677 r.fBottom = r.fTop + SkIntToScalar(thickness); 675 r.fBottom = r.fTop + SkIntToScalar(thickness);
678 paint = immutableState()->fillPaint(); 676 paint = immutableState()->fillPaint();
679 // Text lines are drawn using the stroke color. 677 // Text lines are drawn using the stroke color.
680 paint.setColor(strokeColor().rgb()); 678 paint.setColor(Color::toDeviceColor(strokeColor()).rgb());
681 drawRect(r, paint); 679 drawRect(r, paint);
682 return; 680 return;
683 } 681 }
684 case DottedStroke: 682 case DottedStroke:
685 case DashedStroke: { 683 case DashedStroke: {
686 int y = floorf(pt.y() + std::max<float>(strokeThickness() / 2.0f, 0.5f)) ; 684 int y = floorf(pt.y() + std::max<float>(strokeThickness() / 2.0f, 0.5f)) ;
687 drawLine(IntPoint(pt.x(), y), IntPoint(pt.x() + width, y)); 685 drawLine(IntPoint(pt.x(), y), IntPoint(pt.x() + width, y));
688 return; 686 return;
689 } 687 }
690 } 688 }
(...skipping 13 matching lines...) Expand all
704 702
705 SkRect skRect = rect; 703 SkRect skRect = rect;
706 int fillcolorNotTransparent = immutableState()->fillColor().rgb() & 0xFF0000 00; 704 int fillcolorNotTransparent = immutableState()->fillColor().rgb() & 0xFF0000 00;
707 if (fillcolorNotTransparent) 705 if (fillcolorNotTransparent)
708 drawRect(skRect, immutableState()->fillPaint()); 706 drawRect(skRect, immutableState()->fillPaint());
709 707
710 if (immutableState()->strokeData().style() != NoStroke 708 if (immutableState()->strokeData().style() != NoStroke
711 && immutableState()->strokeColor().alpha()) { 709 && immutableState()->strokeColor().alpha()) {
712 // Stroke a width: 1 inset border 710 // Stroke a width: 1 inset border
713 SkPaint paint(immutableState()->fillPaint()); 711 SkPaint paint(immutableState()->fillPaint());
714 paint.setColor(strokeColor().rgb()); 712 paint.setColor(Color::toDeviceColor(strokeColor()).rgb());
715 paint.setStyle(SkPaint::kStroke_Style); 713 paint.setStyle(SkPaint::kStroke_Style);
716 paint.setStrokeWidth(1); 714 paint.setStrokeWidth(1);
717 715
718 skRect.inset(0.5f, 0.5f); 716 skRect.inset(0.5f, 0.5f);
719 drawRect(skRect, paint); 717 drawRect(skRect, paint);
720 } 718 }
721 } 719 }
722 720
723 void GraphicsContext::drawText(const Font& font, const TextRunPaintInfo& runInfo , const FloatPoint& point, const SkPaint& paint) 721 void GraphicsContext::drawText(const Font& font, const TextRunPaintInfo& runInfo , const FloatPoint& point, const SkPaint& paint)
724 { 722 {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 drawImage(image, FloatRect(r), FloatRect(FloatPoint(), FloatSize(image->size ())), op, shouldRespectImageOrientation); 792 drawImage(image, FloatRect(r), FloatRect(FloatPoint(), FloatSize(image->size ())), op, shouldRespectImageOrientation);
795 } 793 }
796 794
797 void GraphicsContext::drawImage(Image* image, const FloatRect& dest, const Float Rect& src, SkXfermode::Mode op, RespectImageOrientationEnum shouldRespectImageOr ientation) 795 void GraphicsContext::drawImage(Image* image, const FloatRect& dest, const Float Rect& src, SkXfermode::Mode op, RespectImageOrientationEnum shouldRespectImageOr ientation)
798 { 796 {
799 if (contextDisabled() || !image) 797 if (contextDisabled() || !image)
800 return; 798 return;
801 799
802 SkPaint imagePaint = immutableState()->fillPaint(); 800 SkPaint imagePaint = immutableState()->fillPaint();
803 imagePaint.setXfermodeMode(op); 801 imagePaint.setXfermodeMode(op);
804 imagePaint.setColor(SK_ColorBLACK); 802 imagePaint.setColor(SK_ColorBLACK); // FIXME: not color correct.
805 imagePaint.setFilterQuality(computeFilterQuality(image, dest, src)); 803 imagePaint.setFilterQuality(computeFilterQuality(image, dest, src));
806 imagePaint.setAntiAlias(shouldAntialias()); 804 imagePaint.setAntiAlias(shouldAntialias());
807 image->draw(m_canvas, imagePaint, dest, src, shouldRespectImageOrientation, Image::ClampImageToSourceRect); 805 image->draw(m_canvas, imagePaint, dest, src, shouldRespectImageOrientation, Image::ClampImageToSourceRect);
808 m_paintController.setImagePainted(); 806 m_paintController.setImagePainted();
809 } 807 }
810 808
811 SkFilterQuality GraphicsContext::computeFilterQuality(Image* image, const FloatR ect& dest, const FloatRect& src) const 809 SkFilterQuality GraphicsContext::computeFilterQuality(Image* image, const FloatR ect& dest, const FloatRect& src) const
812 { 810 {
813 InterpolationQuality resampling; 811 InterpolationQuality resampling;
814 if (printing()) { 812 if (printing()) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 909
912 drawRect(rect, immutableState()->fillPaint()); 910 drawRect(rect, immutableState()->fillPaint());
913 } 911 }
914 912
915 void GraphicsContext::fillRect(const FloatRect& rect, const Color& color, SkXfer mode::Mode xferMode) 913 void GraphicsContext::fillRect(const FloatRect& rect, const Color& color, SkXfer mode::Mode xferMode)
916 { 914 {
917 if (contextDisabled()) 915 if (contextDisabled())
918 return; 916 return;
919 917
920 SkPaint paint = immutableState()->fillPaint(); 918 SkPaint paint = immutableState()->fillPaint();
921 paint.setColor(color.rgb()); 919 paint.setColor(Color::toDeviceColor(color).rgb());
922 paint.setXfermodeMode(xferMode); 920 paint.setXfermodeMode(xferMode);
923
924 drawRect(rect, paint); 921 drawRect(rect, paint);
925 } 922 }
926 923
927 void GraphicsContext::fillRoundedRect(const FloatRoundedRect& rrect, const Color & color) 924 void GraphicsContext::fillRoundedRect(const FloatRoundedRect& rrect, const Color & color)
928 { 925 {
929 if (contextDisabled()) 926 if (contextDisabled())
930 return; 927 return;
931 928
932 if (!rrect.isRounded() || !rrect.isRenderable()) { 929 if (!rrect.isRounded() || !rrect.isRenderable()) {
933 fillRect(rrect.rect(), color); 930 fillRect(rrect.rect(), color);
934 return; 931 return;
935 } 932 }
936 933
937 if (color == fillColor()) { 934 if (color == fillColor()) {
938 drawRRect(rrect, immutableState()->fillPaint()); 935 drawRRect(rrect, immutableState()->fillPaint());
939 return; 936 return;
940 } 937 }
941 938
942 SkPaint paint = immutableState()->fillPaint(); 939 SkPaint paint = immutableState()->fillPaint();
943 paint.setColor(color.rgb()); 940 paint.setColor(Color::toDeviceColor(color).rgb());
944 941
945 drawRRect(rrect, paint); 942 drawRRect(rrect, paint);
946 } 943 }
947 944
948 namespace { 945 namespace {
949 946
950 bool isSimpleDRRect(const FloatRoundedRect& outer, const FloatRoundedRect& inner ) 947 bool isSimpleDRRect(const FloatRoundedRect& outer, const FloatRoundedRect& inner )
951 { 948 {
952 // A DRRect is "simple" (i.e. can be drawn as a rrect stroke) if 949 // A DRRect is "simple" (i.e. can be drawn as a rrect stroke) if
953 // 1) all sides have the same width 950 // 1) all sides have the same width
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 { 986 {
990 if (contextDisabled()) 987 if (contextDisabled())
991 return; 988 return;
992 ASSERT(m_canvas); 989 ASSERT(m_canvas);
993 990
994 if (!isSimpleDRRect(outer, inner)) { 991 if (!isSimpleDRRect(outer, inner)) {
995 if (color == fillColor()) { 992 if (color == fillColor()) {
996 m_canvas->drawDRRect(outer, inner, immutableState()->fillPaint()); 993 m_canvas->drawDRRect(outer, inner, immutableState()->fillPaint());
997 } else { 994 } else {
998 SkPaint paint(immutableState()->fillPaint()); 995 SkPaint paint(immutableState()->fillPaint());
999 paint.setColor(color.rgb()); 996 paint.setColor(Color::toDeviceColor(color).rgb());
1000 m_canvas->drawDRRect(outer, inner, paint); 997 m_canvas->drawDRRect(outer, inner, paint);
1001 } 998 }
1002 999
1003 return; 1000 return;
1004 } 1001 }
1005 1002
1006 // We can draw this as a stroked rrect. 1003 // We can draw this as a stroked rrect.
1007 float strokeWidth = inner.rect().x() - outer.rect().x(); 1004 float strokeWidth = inner.rect().x() - outer.rect().x();
1008 SkRRect strokeRRect = outer; 1005 SkRRect strokeRRect = outer;
1009 strokeRRect.inset(strokeWidth / 2, strokeWidth / 2); 1006 strokeRRect.inset(strokeWidth / 2, strokeWidth / 2);
1010 1007
1011 SkPaint strokePaint(immutableState()->fillPaint()); 1008 SkPaint strokePaint(immutableState()->fillPaint());
1012 strokePaint.setColor(color.rgb()); 1009 strokePaint.setColor(Color::toDeviceColor(color).rgb());
1013 strokePaint.setStyle(SkPaint::kStroke_Style); 1010 strokePaint.setStyle(SkPaint::kStroke_Style);
1014 strokePaint.setStrokeWidth(strokeWidth); 1011 strokePaint.setStrokeWidth(strokeWidth);
1015 1012
1016 m_canvas->drawRRect(strokeRRect, strokePaint); 1013 m_canvas->drawRRect(strokeRRect, strokePaint);
1017 } 1014 }
1018 1015
1019 void GraphicsContext::fillEllipse(const FloatRect& ellipse) 1016 void GraphicsContext::fillEllipse(const FloatRect& ellipse)
1020 { 1017 {
1021 if (contextDisabled()) 1018 if (contextDisabled())
1022 return; 1019 return;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 { 1201 {
1205 concat(affineTransformToSkMatrix(affine)); 1202 concat(affineTransformToSkMatrix(affine));
1206 } 1203 }
1207 1204
1208 void GraphicsContext::fillRectWithRoundedHole(const FloatRect& rect, const Float RoundedRect& roundedHoleRect, const Color& color) 1205 void GraphicsContext::fillRectWithRoundedHole(const FloatRect& rect, const Float RoundedRect& roundedHoleRect, const Color& color)
1209 { 1206 {
1210 if (contextDisabled()) 1207 if (contextDisabled())
1211 return; 1208 return;
1212 1209
1213 SkPaint paint(immutableState()->fillPaint()); 1210 SkPaint paint(immutableState()->fillPaint());
1214 paint.setColor(color.rgb()); 1211 paint.setColor(Color::toDeviceColor(color).rgb());
1215 m_canvas->drawDRRect(SkRRect::MakeRect(rect), roundedHoleRect, paint); 1212 m_canvas->drawDRRect(SkRRect::MakeRect(rect), roundedHoleRect, paint);
1216 } 1213 }
1217 1214
1218 void GraphicsContext::adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2 , float strokeWidth, StrokeStyle penStyle) 1215 void GraphicsContext::adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2 , float strokeWidth, StrokeStyle penStyle)
1219 { 1216 {
1220 // For odd widths, we add in 0.5 to the appropriate x/y so that the float ar ithmetic 1217 // For odd widths, we add in 0.5 to the appropriate x/y so that the float ar ithmetic
1221 // works out. For example, with a border width of 3, WebKit will pass us (y 1+y2)/2, e.g., 1218 // works out. For example, with a border width of 3, WebKit will pass us (y 1+y2)/2, e.g.,
1222 // (50+53)/2 = 103/2 = 51 when we want 51.5. It is always true that an even width gave 1219 // (50+53)/2 = 103/2 = 51 when we want 51.5. It is always true that an even width gave
1223 // us a perfect position, but an odd width gave us a position that is off by exactly 0.5. 1220 // us a perfect position, but an odd width gave us a position that is off by exactly 0.5.
1224 if (penStyle == DottedStroke || penStyle == DashedStroke) { 1221 if (penStyle == DottedStroke || penStyle == DashedStroke) {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 static const SkPMColor colors[] = { 1357 static const SkPMColor colors[] = {
1361 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red 1358 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red
1362 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray 1359 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray
1363 }; 1360 };
1364 1361
1365 return colors[index]; 1362 return colors[index];
1366 } 1363 }
1367 #endif 1364 #endif
1368 1365
1369 } // namespace blink 1366 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698