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

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

Issue 169283008: Maintain SkPaint in GraphicsContextState. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: A couple more optimizations. Created 6 years, 9 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 | Annotate | Revision Log
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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 { 131 {
132 // FIXME: Do some tests to determine how many states are typically used, and allocate 132 // FIXME: Do some tests to determine how many states are typically used, and allocate
133 // several here. 133 // several here.
134 m_paintStateStack.append(GraphicsContextState::create()); 134 m_paintStateStack.append(GraphicsContextState::create());
135 m_paintState = m_paintStateStack.last().get(); 135 m_paintState = m_paintStateStack.last().get();
136 } 136 }
137 137
138 GraphicsContext::~GraphicsContext() 138 GraphicsContext::~GraphicsContext()
139 { 139 {
140 ASSERT(!m_paintStateIndex); 140 ASSERT(!m_paintStateIndex);
141 ASSERT(!m_paintState->m_saveCount); 141 ASSERT(!m_paintState->saveCount());
142 ASSERT(!m_annotationCount); 142 ASSERT(!m_annotationCount);
143 ASSERT(!m_layerCount); 143 ASSERT(!m_layerCount);
144 ASSERT(m_recordingStateStack.isEmpty()); 144 ASSERT(m_recordingStateStack.isEmpty());
145 } 145 }
146 146
147 void GraphicsContext::save() 147 void GraphicsContext::save()
148 { 148 {
149 if (paintingDisabled()) 149 if (paintingDisabled())
150 return; 150 return;
151 151
152 m_paintState->m_saveCount++; 152 m_paintState->incrementSaveCount();
153 153
154 m_canvasStateStack.append(CanvasSaveState(m_canvasSaveFlags, m_canvas->getSa veCount())); 154 m_canvasStateStack.append(CanvasSaveState(m_canvasSaveFlags, m_canvas->getSa veCount()));
155 m_canvasSaveFlags |= SkCanvas::kMatrixClip_SaveFlag; 155 m_canvasSaveFlags |= SkCanvas::kMatrixClip_SaveFlag;
156 } 156 }
157 157
158 void GraphicsContext::restore() 158 void GraphicsContext::restore()
159 { 159 {
160 if (paintingDisabled()) 160 if (paintingDisabled())
161 return; 161 return;
162 162
163 if (!m_paintStateIndex && !m_paintState->m_saveCount) { 163 if (!m_paintStateIndex && !m_paintState->saveCount()) {
164 WTF_LOG_ERROR("ERROR void GraphicsContext::restore() stack is empty"); 164 WTF_LOG_ERROR("ERROR void GraphicsContext::restore() stack is empty");
165 return; 165 return;
166 } 166 }
167 167
168 if (m_paintState->m_saveCount) { 168 if (m_paintState->saveCount()) {
169 m_paintState->m_saveCount--; 169 m_paintState->decrementSaveCount();
170 } else { 170 } else {
171 m_paintStateIndex--; 171 m_paintStateIndex--;
172 m_paintState = m_paintStateStack[m_paintStateIndex].get(); 172 m_paintState = m_paintStateStack[m_paintStateIndex].get();
173 } 173 }
174 174
175 CanvasSaveState savedState = m_canvasStateStack.last(); 175 CanvasSaveState savedState = m_canvasStateStack.last();
176 m_canvasStateStack.removeLast(); 176 m_canvasStateStack.removeLast();
177 m_canvasSaveFlags = savedState.m_flags; 177 m_canvasSaveFlags = savedState.m_flags;
178 m_canvas->restoreToCount(savedState.m_restoreCount); 178 m_canvas->restoreToCount(savedState.m_restoreCount);
179 } 179 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 return; 229 return;
230 230
231 canvas()->endCommentGroup(); 231 canvas()->endCommentGroup();
232 232
233 ASSERT(m_annotationCount > 0); 233 ASSERT(m_annotationCount > 0);
234 #if !ASSERT_DISABLED 234 #if !ASSERT_DISABLED
235 --m_annotationCount; 235 --m_annotationCount;
236 #endif 236 #endif
237 } 237 }
238 238
239 void GraphicsContext::setStrokeColor(const Color& color)
240 {
241 GraphicsContextState* stateToSet = mutableState();
242 stateToSet->m_strokeData.setColor(color);
243 stateToSet->m_strokeData.clearGradient();
244 stateToSet->m_strokeData.clearPattern();
245 }
246
247 void GraphicsContext::setStrokePattern(PassRefPtr<Pattern> pattern) 239 void GraphicsContext::setStrokePattern(PassRefPtr<Pattern> pattern)
248 { 240 {
249 if (paintingDisabled()) 241 if (paintingDisabled())
250 return; 242 return;
251 243
252 ASSERT(pattern); 244 ASSERT(pattern);
253 if (!pattern) { 245 if (!pattern) {
254 setStrokeColor(Color::black); 246 setStrokeColor(Color::black);
255 return; 247 return;
256 } 248 }
257 GraphicsContextState* stateToSet = mutableState(); 249 mutableState()->setStrokePattern(pattern);
258 stateToSet->m_strokeData.clearGradient();
259 stateToSet->m_strokeData.setPattern(pattern);
260 } 250 }
261 251
262 void GraphicsContext::setStrokeGradient(PassRefPtr<Gradient> gradient) 252 void GraphicsContext::setStrokeGradient(PassRefPtr<Gradient> gradient)
263 { 253 {
264 if (paintingDisabled()) 254 if (paintingDisabled())
265 return; 255 return;
266 256
267 ASSERT(gradient); 257 ASSERT(gradient);
268 if (!gradient) { 258 if (!gradient) {
269 setStrokeColor(Color::black); 259 setStrokeColor(Color::black);
270 return; 260 return;
271 } 261 }
272 GraphicsContextState* stateToSet = mutableState(); 262 mutableState()->setStrokeGradient(gradient);
273 stateToSet->m_strokeData.setGradient(gradient);
274 stateToSet->m_strokeData.clearPattern();
275 }
276
277 void GraphicsContext::setFillColor(const Color& color)
278 {
279 GraphicsContextState* stateToSet = mutableState();
280 stateToSet->m_fillColor = color;
281 stateToSet->m_fillGradient.clear();
282 stateToSet->m_fillPattern.clear();
283 } 263 }
284 264
285 void GraphicsContext::setFillPattern(PassRefPtr<Pattern> pattern) 265 void GraphicsContext::setFillPattern(PassRefPtr<Pattern> pattern)
286 { 266 {
287 if (paintingDisabled()) 267 if (paintingDisabled())
288 return; 268 return;
289 269
290 ASSERT(pattern); 270 ASSERT(pattern);
291 if (!pattern) { 271 if (!pattern) {
292 setFillColor(Color::black); 272 setFillColor(Color::black);
293 return; 273 return;
294 } 274 }
295 275
296 GraphicsContextState* stateToSet = mutableState(); 276 mutableState()->setFillPattern(pattern);
297 stateToSet->m_fillGradient.clear();
298 stateToSet->m_fillPattern = pattern;
299 } 277 }
300 278
301 void GraphicsContext::setFillGradient(PassRefPtr<Gradient> gradient) 279 void GraphicsContext::setFillGradient(PassRefPtr<Gradient> gradient)
302 { 280 {
303 if (paintingDisabled()) 281 if (paintingDisabled())
304 return; 282 return;
305 283
306 ASSERT(gradient); 284 ASSERT(gradient);
307 if (!gradient) { 285 if (!gradient) {
308 setFillColor(Color::black); 286 setFillColor(Color::black);
309 return; 287 return;
310 } 288 }
311 289
312 GraphicsContextState* stateToSet = mutableState(); 290 mutableState()->setFillGradient(gradient);
313 stateToSet->m_fillGradient = gradient;
314 stateToSet->m_fillPattern.clear();
315 } 291 }
316 292
317 void GraphicsContext::setShadow(const FloatSize& offset, float blur, const Color & color, 293 void GraphicsContext::setShadow(const FloatSize& offset, float blur, const Color & color,
318 DrawLooper::ShadowTransformMode shadowTransformMode, 294 DrawLooper::ShadowTransformMode shadowTransformMode,
319 DrawLooper::ShadowAlphaMode shadowAlphaMode) 295 DrawLooper::ShadowAlphaMode shadowAlphaMode)
320 { 296 {
321 if (paintingDisabled()) 297 if (paintingDisabled())
322 return; 298 return;
323 299
324 if (!color.alpha() || (!offset.width() && !offset.height() && !blur)) { 300 if (!color.alpha() || (!offset.width() && !offset.height() && !blur)) {
325 clearShadow(); 301 clearShadow();
326 return; 302 return;
327 } 303 }
328 304
329 DrawLooper drawLooper; 305 DrawLooper drawLooper;
330 drawLooper.addShadow(offset, blur, color, shadowTransformMode, shadowAlphaMo de); 306 drawLooper.addShadow(offset, blur, color, shadowTransformMode, shadowAlphaMo de);
331 drawLooper.addUnmodifiedContent(); 307 drawLooper.addUnmodifiedContent();
332 setDrawLooper(drawLooper); 308 setDrawLooper(drawLooper);
333 } 309 }
334 310
335 void GraphicsContext::setDrawLooper(const DrawLooper& drawLooper) 311 void GraphicsContext::setDrawLooper(const DrawLooper& drawLooper)
336 { 312 {
337 if (paintingDisabled()) 313 if (paintingDisabled())
338 return; 314 return;
339 315
340 mutableState()->m_looper = drawLooper.skDrawLooper(); 316 mutableState()->setDrawLooper(drawLooper);
341 } 317 }
342 318
343 void GraphicsContext::clearDrawLooper() 319 void GraphicsContext::clearDrawLooper()
344 { 320 {
345 if (paintingDisabled()) 321 if (paintingDisabled())
346 return; 322 return;
347 323
348 mutableState()->m_looper.clear(); 324 mutableState()->clearDrawLooper();
349 } 325 }
350 326
351 int GraphicsContext::getNormalizedAlpha() const 327 bool GraphicsContext::hasShadow() const
352 { 328 {
353 int alpha = roundf(immutableState()->m_alpha * 256); 329 return !!immutableState()->drawLooper();
354 if (alpha > 255)
355 alpha = 255;
356 else if (alpha < 0)
357 alpha = 0;
358 return alpha;
359 } 330 }
360 331
361 FloatRect GraphicsContext::getClipBounds() const 332 FloatRect GraphicsContext::getClipBounds() const
362 { 333 {
363 if (paintingDisabled()) 334 if (paintingDisabled())
364 return FloatRect(); 335 return FloatRect();
365 SkRect rect; 336 SkRect rect;
366 if (!m_canvas->getClipBounds(&rect)) 337 if (!m_canvas->getClipBounds(&rect))
367 return FloatRect(); 338 return FloatRect();
368 return FloatRect(rect); 339 return FloatRect(rect);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 // collapsed. Therefore, subpixel text is disabled when we are drawing 391 // collapsed. Therefore, subpixel text is disabled when we are drawing
421 // onto a layer. 392 // onto a layer.
422 if (paintingDisabled() || isDrawingToLayer() || !isCertainlyOpaque()) 393 if (paintingDisabled() || isDrawingToLayer() || !isCertainlyOpaque())
423 return false; 394 return false;
424 395
425 return shouldSmoothFonts(); 396 return shouldSmoothFonts();
426 } 397 }
427 398
428 void GraphicsContext::setCompositeOperation(CompositeOperator compositeOperation , WebBlendMode blendMode) 399 void GraphicsContext::setCompositeOperation(CompositeOperator compositeOperation , WebBlendMode blendMode)
429 { 400 {
430 GraphicsContextState* stateToSet = mutableState(); 401 mutableState()->setCompositeOperation(compositeOperation, blendMode);
431 stateToSet->m_compositeOperator = compositeOperation;
432 stateToSet->m_blendMode = blendMode;
433 stateToSet->m_xferMode = WebCoreCompositeToSkiaComposite(compositeOperation, blendMode);
434 } 402 }
435 403
436 SkColorFilter* GraphicsContext::colorFilter() 404 SkColorFilter* GraphicsContext::colorFilter()
437 { 405 {
438 return immutableState()->m_colorFilter.get(); 406 return immutableState()->colorFilter();
439 } 407 }
440 408
441 void GraphicsContext::setColorFilter(ColorFilter colorFilter) 409 void GraphicsContext::setColorFilter(ColorFilter colorFilter)
442 { 410 {
443 GraphicsContextState* stateToSet = mutableState(); 411 GraphicsContextState* stateToSet = mutableState();
444 412
445 // We only support one active color filter at the moment. If (when) this bec omes a problem, 413 // We only support one active color filter at the moment. If (when) this bec omes a problem,
446 // we should switch to using color filter chains (Skia work in progress). 414 // we should switch to using color filter chains (Skia work in progress).
447 ASSERT(!stateToSet->m_colorFilter); 415 ASSERT(!stateToSet->colorFilter());
448 stateToSet->m_colorFilter = WebCoreColorFilterToSkiaColorFilter(colorFilter) ; 416 stateToSet->setColorFilter(WebCoreColorFilterToSkiaColorFilter(colorFilter)) ;
449 } 417 }
450 418
451 bool GraphicsContext::readPixels(SkBitmap* bitmap, int x, int y, SkCanvas::Confi g8888 config8888) 419 bool GraphicsContext::readPixels(SkBitmap* bitmap, int x, int y, SkCanvas::Confi g8888 config8888)
452 { 420 {
453 if (paintingDisabled()) 421 if (paintingDisabled())
454 return false; 422 return false;
455 423
456 return m_canvas->readPixels(bitmap, x, y, config8888); 424 return m_canvas->readPixels(bitmap, x, y, config8888);
457 } 425 }
458 426
(...skipping 16 matching lines...) Expand all
475 if (matrix.isIdentity()) 443 if (matrix.isIdentity())
476 return true; 444 return true;
477 445
478 realizeCanvasSave(SkCanvas::kMatrix_SaveFlag); 446 realizeCanvasSave(SkCanvas::kMatrix_SaveFlag);
479 447
480 return m_canvas->concat(matrix); 448 return m_canvas->concat(matrix);
481 } 449 }
482 450
483 void GraphicsContext::beginTransparencyLayer(float opacity, const FloatRect* bou nds) 451 void GraphicsContext::beginTransparencyLayer(float opacity, const FloatRect* bou nds)
484 { 452 {
485 beginLayer(opacity, immutableState()->m_compositeOperator, bounds); 453 beginLayer(opacity, immutableState()->compositeOperator(), bounds);
486 } 454 }
487 455
488 void GraphicsContext::beginLayer(float opacity, CompositeOperator op, const Floa tRect* bounds, ColorFilter colorFilter, ImageFilter* imageFilter) 456 void GraphicsContext::beginLayer(float opacity, CompositeOperator op, const Floa tRect* bounds, ColorFilter colorFilter, ImageFilter* imageFilter)
489 { 457 {
490 if (paintingDisabled()) 458 if (paintingDisabled())
491 return; 459 return;
492 460
493 // We need the "alpha" layer flag here because the base layer is opaque 461 // We need the "alpha" layer flag here because the base layer is opaque
494 // (the surface of the page) but layers on top may have transparent parts. 462 // (the surface of the page) but layers on top may have transparent parts.
495 // Without explicitly setting the alpha flag, the layer will inherit the 463 // Without explicitly setting the alpha flag, the layer will inherit the
496 // opaque setting of the base and some things won't work properly. 464 // opaque setting of the base and some things won't work properly.
497 SkCanvas::SaveFlags saveFlags = static_cast<SkCanvas::SaveFlags>(SkCanvas::k HasAlphaLayer_SaveFlag | SkCanvas::kFullColorLayer_SaveFlag); 465 SkCanvas::SaveFlags saveFlags = static_cast<SkCanvas::SaveFlags>(SkCanvas::k HasAlphaLayer_SaveFlag | SkCanvas::kFullColorLayer_SaveFlag);
498 466
499 SkPaint layerPaint; 467 SkPaint layerPaint;
500 layerPaint.setAlpha(static_cast<unsigned char>(opacity * 255)); 468 layerPaint.setAlpha(static_cast<unsigned char>(opacity * 255));
501 layerPaint.setXfermode(WebCoreCompositeToSkiaComposite(op, m_paintState->m_b lendMode).get()); 469 layerPaint.setXfermode(WebCoreCompositeToSkiaComposite(op, m_paintState->ble ndMode()).get());
502 layerPaint.setColorFilter(WebCoreColorFilterToSkiaColorFilter(colorFilter).g et()); 470 layerPaint.setColorFilter(WebCoreColorFilterToSkiaColorFilter(colorFilter).g et());
503 layerPaint.setImageFilter(imageFilter); 471 layerPaint.setImageFilter(imageFilter);
504 472
505 // Filters will adjust the clip to accomodate for filter bounds, but 473 // Filters will adjust the clip to accomodate for filter bounds, but
506 // need the kClipToLayer_SaveFlag to do so. We also save the clip here, so 474 // need the kClipToLayer_SaveFlag to do so. We also save the clip here, so
507 // it is restored back before the filtered layer is drawn in restore(). 475 // it is restored back before the filtered layer is drawn in restore().
508 // The matrix also needs to be saved, in order to be correctly passed to 476 // The matrix also needs to be saved, in order to be correctly passed to
509 // the filter CTM during restore(). 477 // the filter CTM during restore().
510 if (imageFilter) 478 if (imageFilter)
511 saveFlags = SkCanvas::kARGB_ClipLayer_SaveFlag; 479 saveFlags = SkCanvas::kARGB_ClipLayer_SaveFlag;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 562
595 if (bounds.x() || bounds.y()) 563 if (bounds.x() || bounds.y())
596 m_canvas->translate(-bounds.x(), -bounds.y()); 564 m_canvas->translate(-bounds.x(), -bounds.y());
597 } 565 }
598 566
599 void GraphicsContext::setupPaintForFilling(SkPaint* paint) const 567 void GraphicsContext::setupPaintForFilling(SkPaint* paint) const
600 { 568 {
601 if (paintingDisabled()) 569 if (paintingDisabled())
602 return; 570 return;
603 571
604 setupPaintCommon(paint); 572 *paint = immutableState()->fillPaint();
605
606 setupShader(paint, immutableState()->m_fillGradient.get(), immutableState()- >m_fillPattern.get(), immutableState()->m_fillColor.rgb());
607 } 573 }
608 574
609 float GraphicsContext::setupPaintForStroking(SkPaint* paint, int length) const 575 void GraphicsContext::setupPaintForStroking(SkPaint* paint) const
610 { 576 {
611 if (paintingDisabled()) 577 if (paintingDisabled())
612 return 0.0f; 578 return;
613 579
614 setupPaintCommon(paint); 580 *paint = immutableState()->strokePaint();
615
616 setupShader(paint, immutableState()->m_strokeData.gradient(), immutableState ()->m_strokeData.pattern(),
617 immutableState()->m_strokeData.color().rgb());
618
619 return immutableState()->m_strokeData.setupPaint(paint, length);
620 } 581 }
621 582
622 void GraphicsContext::drawConvexPolygon(size_t numPoints, const FloatPoint* poin ts, bool shouldAntialias) 583 void GraphicsContext::drawConvexPolygon(size_t numPoints, const FloatPoint* poin ts, bool shouldAntialias)
623 { 584 {
624 if (paintingDisabled()) 585 if (paintingDisabled())
625 return; 586 return;
626 587
627 if (numPoints <= 1) 588 if (numPoints <= 1)
628 return; 589 return;
629 590
630 SkPath path; 591 SkPath path;
631 setPathFromConvexPoints(&path, numPoints, points); 592 setPathFromConvexPoints(&path, numPoints, points);
632 593
633 SkPaint paint; 594 SkPaint paint(immutableState()->fillPaint());
634 setupPaintForFilling(&paint);
635 paint.setAntiAlias(shouldAntialias); 595 paint.setAntiAlias(shouldAntialias);
636 drawPath(path, paint); 596 drawPath(path, paint);
637 597
638 if (strokeStyle() != NoStroke) { 598 if (strokeStyle() != NoStroke)
639 paint.reset(); 599 drawPath(path, immutableState()->strokePaint());
640 setupPaintForStroking(&paint);
641 drawPath(path, paint);
642 }
643 } 600 }
644 601
645 // This method is only used to draw the little circles used in lists. 602 // This method is only used to draw the little circles used in lists.
646 void GraphicsContext::drawEllipse(const IntRect& elipseRect) 603 void GraphicsContext::drawEllipse(const IntRect& elipseRect)
647 { 604 {
648 if (paintingDisabled()) 605 if (paintingDisabled())
649 return; 606 return;
650 607
651 SkRect rect = elipseRect; 608 SkRect rect = elipseRect;
652 SkPaint paint; 609 drawOval(rect, immutableState()->fillPaint());
653 setupPaintForFilling(&paint);
654 drawOval(rect, paint);
655 610
656 if (strokeStyle() != NoStroke) { 611 if (strokeStyle() != NoStroke)
657 paint.reset(); 612 drawOval(rect, immutableState()->strokePaint());
658 setupPaintForStroking(&paint);
659 drawOval(rect, paint);
660 }
661 } 613 }
662 614
663 void GraphicsContext::drawFocusRing(const Path& focusRingPath, int width, int of fset, const Color& color) 615 void GraphicsContext::drawFocusRing(const Path& focusRingPath, int width, int of fset, const Color& color)
664 { 616 {
665 // FIXME: Implement support for offset. 617 // FIXME: Implement support for offset.
666 if (paintingDisabled()) 618 if (paintingDisabled())
667 return; 619 return;
668 620
669 SkPaint paint; 621 SkPaint paint;
670 paint.setAntiAlias(true); 622 paint.setAntiAlias(true);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 // This is only used to draw borders. 722 // This is only used to draw borders.
771 void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2) 723 void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2)
772 { 724 {
773 if (paintingDisabled()) 725 if (paintingDisabled())
774 return; 726 return;
775 727
776 StrokeStyle penStyle = strokeStyle(); 728 StrokeStyle penStyle = strokeStyle();
777 if (penStyle == NoStroke) 729 if (penStyle == NoStroke)
778 return; 730 return;
779 731
780 SkPaint paint;
781 FloatPoint p1 = point1; 732 FloatPoint p1 = point1;
782 FloatPoint p2 = point2; 733 FloatPoint p2 = point2;
783 bool isVerticalLine = (p1.x() == p2.x()); 734 bool isVerticalLine = (p1.x() == p2.x());
784 int width = roundf(strokeThickness()); 735 int width = roundf(strokeThickness());
785 736
786 // We know these are vertical or horizontal lines, so the length will just 737 // We know these are vertical or horizontal lines, so the length will just
787 // be the sum of the displacement component vectors give or take 1 - 738 // be the sum of the displacement component vectors give or take 1 -
788 // probably worth the speed up of no square root, which also won't be exact. 739 // probably worth the speed up of no square root, which also won't be exact.
789 FloatSize disp = p2 - p1; 740 FloatSize disp = p2 - p1;
790 int length = SkScalarRoundToInt(disp.width() + disp.height()); 741 int length = SkScalarRoundToInt(disp.width() + disp.height());
791 setupPaintForStroking(&paint, length); 742 SkPaint paint(immutableState()->strokePaint());
792 743
793 if (strokeStyle() == DottedStroke || strokeStyle() == DashedStroke) { 744 if (strokeStyle() == DottedStroke || strokeStyle() == DashedStroke) {
745 immutableState()->strokeData().setupPaintDashPathEffect(&paint, length);
746
794 // Do a rect fill of our endpoints. This ensures we always have the 747 // Do a rect fill of our endpoints. This ensures we always have the
795 // appearance of being a border. We then draw the actual dotted/dashed line. 748 // appearance of being a border. We then draw the actual dotted/dashed line.
796
797 SkRect r1, r2; 749 SkRect r1, r2;
798 r1.set(p1.x(), p1.y(), p1.x() + width, p1.y() + width); 750 r1.set(p1.x(), p1.y(), p1.x() + width, p1.y() + width);
799 r2.set(p2.x(), p2.y(), p2.x() + width, p2.y() + width); 751 r2.set(p2.x(), p2.y(), p2.x() + width, p2.y() + width);
800 752
801 if (isVerticalLine) { 753 if (isVerticalLine) {
802 r1.offset(-width / 2, 0); 754 r1.offset(-width / 2, 0);
803 r2.offset(-width / 2, -width); 755 r2.offset(-width / 2, -width);
804 } else { 756 } else {
805 r1.offset(0, -width / 2); 757 r1.offset(0, -width / 2);
806 r2.offset(-width, -width / 2); 758 r2.offset(-width, -width / 2);
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 r.fTop = WebCoreFloatToSkScalar(floorf(pt.y() + 0.5f)); 915 r.fTop = WebCoreFloatToSkScalar(floorf(pt.y() + 0.5f));
964 r.fRight = r.fLeft + WebCoreFloatToSkScalar(width); 916 r.fRight = r.fLeft + WebCoreFloatToSkScalar(width);
965 r.fBottom = r.fTop + SkIntToScalar(thickness); 917 r.fBottom = r.fTop + SkIntToScalar(thickness);
966 918
967 SkPaint paint; 919 SkPaint paint;
968 switch (strokeStyle()) { 920 switch (strokeStyle()) {
969 case NoStroke: 921 case NoStroke:
970 case SolidStroke: 922 case SolidStroke:
971 case DoubleStroke: 923 case DoubleStroke:
972 case WavyStroke: 924 case WavyStroke:
973 setupPaintForFilling(&paint); 925 paint = immutableState()->fillPaint();
974 break; 926 break;
975 case DottedStroke: 927 case DottedStroke:
976 case DashedStroke: 928 case DashedStroke:
977 setupPaintForStroking(&paint); 929 paint = immutableState()->strokePaint();
978 break; 930 break;
979 } 931 }
980 932
981 // Text lines are drawn using the stroke color. 933 // Text lines are drawn using the stroke color.
982 paint.setColor(effectiveStrokeColor()); 934 paint.setColor(effectiveStrokeColor());
983 drawRect(r, paint); 935 drawRect(r, paint);
984 } 936 }
985 937
986 // Draws a filled rectangle with a stroked border. 938 // Draws a filled rectangle with a stroked border.
987 void GraphicsContext::drawRect(const IntRect& rect) 939 void GraphicsContext::drawRect(const IntRect& rect)
988 { 940 {
989 if (paintingDisabled()) 941 if (paintingDisabled())
990 return; 942 return;
991 943
992 ASSERT(!rect.isEmpty()); 944 ASSERT(!rect.isEmpty());
993 if (rect.isEmpty()) 945 if (rect.isEmpty())
994 return; 946 return;
995 947
996 SkRect skRect = rect; 948 SkRect skRect = rect;
997 SkPaint paint; 949 int fillcolorNotTransparent = immutableState()->fillColor().rgb() & 0xFF0000 00;
998 int fillcolorNotTransparent = m_paintState->m_fillColor.rgb() & 0xFF000000; 950 if (fillcolorNotTransparent)
999 if (fillcolorNotTransparent) { 951 drawRect(skRect, immutableState()->fillPaint());
1000 setupPaintForFilling(&paint);
1001 drawRect(skRect, paint);
1002 }
1003 952
1004 if (m_paintState->m_strokeData.style() != NoStroke && (m_paintState->m_strok eData.color().rgb() & 0xFF000000)) { 953 if (immutableState()->strokeData().style() != NoStroke && (immutableState()- >strokeData().color().rgb() & 0xFF000000)) {
1005 // We do a fill of four rects to simulate the stroke of a border. 954 // We do a fill of four rects to simulate the stroke of a border.
1006 paint.reset(); 955 SkPaint paint(immutableState()->fillPaint());
1007 setupPaintForFilling(&paint);
1008 // need to jam in the strokeColor 956 // need to jam in the strokeColor
1009 paint.setColor(this->effectiveStrokeColor()); 957 paint.setColor(immutableState()->effectiveStrokeColor());
1010 958
1011 SkRect topBorder = { skRect.fLeft, skRect.fTop, skRect.fRight, skRect.fT op + 1 }; 959 SkRect topBorder = { skRect.fLeft, skRect.fTop, skRect.fRight, skRect.fT op + 1 };
1012 drawRect(topBorder, paint); 960 drawRect(topBorder, paint);
1013 SkRect bottomBorder = { skRect.fLeft, skRect.fBottom - 1, skRect.fRight, skRect.fBottom }; 961 SkRect bottomBorder = { skRect.fLeft, skRect.fBottom - 1, skRect.fRight, skRect.fBottom };
1014 drawRect(bottomBorder, paint); 962 drawRect(bottomBorder, paint);
1015 SkRect leftBorder = { skRect.fLeft, skRect.fTop + 1, skRect.fLeft + 1, s kRect.fBottom - 1 }; 963 SkRect leftBorder = { skRect.fLeft, skRect.fTop + 1, skRect.fLeft + 1, s kRect.fBottom - 1 };
1016 drawRect(leftBorder, paint); 964 drawRect(leftBorder, paint);
1017 SkRect rightBorder = { skRect.fRight - 1, skRect.fTop + 1, skRect.fRight , skRect.fBottom - 1 }; 965 SkRect rightBorder = { skRect.fRight - 1, skRect.fTop + 1, skRect.fRight , skRect.fBottom - 1 };
1018 drawRect(rightBorder, paint); 966 drawRect(rightBorder, paint);
1019 } 967 }
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 m_opaqueRegion.didDrawRect(this, rect, *paint, &bitmap); 1185 m_opaqueRegion.didDrawRect(this, rect, *paint, &bitmap);
1238 } 1186 }
1239 } 1187 }
1240 1188
1241 void GraphicsContext::drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, 1189 void GraphicsContext::drawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
1242 const SkRect& dst, const SkPaint* paint) 1190 const SkRect& dst, const SkPaint* paint)
1243 { 1191 {
1244 if (paintingDisabled()) 1192 if (paintingDisabled())
1245 return; 1193 return;
1246 1194
1247 SkCanvas::DrawBitmapRectFlags flags = m_paintState->m_shouldClampToSourceRec t ? SkCanvas::kNone_DrawBitmapRectFlag : SkCanvas::kBleed_DrawBitmapRectFlag; 1195 SkCanvas::DrawBitmapRectFlags flags =
1196 immutableState()->shouldClampToSourceRect() ? SkCanvas::kNone_DrawBitmap RectFlag : SkCanvas::kBleed_DrawBitmapRectFlag;
1248 1197
1249 m_canvas->drawBitmapRectToRect(bitmap, src, dst, paint, flags); 1198 m_canvas->drawBitmapRectToRect(bitmap, src, dst, paint, flags);
1250 1199
1251 if (m_trackOpaqueRegion) 1200 if (m_trackOpaqueRegion)
1252 m_opaqueRegion.didDrawRect(this, dst, *paint, &bitmap); 1201 m_opaqueRegion.didDrawRect(this, dst, *paint, &bitmap);
1253 } 1202 }
1254 1203
1255 void GraphicsContext::drawOval(const SkRect& oval, const SkPaint& paint) 1204 void GraphicsContext::drawOval(const SkRect& oval, const SkPaint& paint)
1256 { 1205 {
1257 if (paintingDisabled()) 1206 if (paintingDisabled())
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1335 1284
1336 void GraphicsContext::fillPath(const Path& pathToFill) 1285 void GraphicsContext::fillPath(const Path& pathToFill)
1337 { 1286 {
1338 if (paintingDisabled() || pathToFill.isEmpty()) 1287 if (paintingDisabled() || pathToFill.isEmpty())
1339 return; 1288 return;
1340 1289
1341 // Use const_cast and temporarily modify the fill type instead of copying th e path. 1290 // Use const_cast and temporarily modify the fill type instead of copying th e path.
1342 SkPath& path = const_cast<SkPath&>(pathToFill.skPath()); 1291 SkPath& path = const_cast<SkPath&>(pathToFill.skPath());
1343 SkPath::FillType previousFillType = path.getFillType(); 1292 SkPath::FillType previousFillType = path.getFillType();
1344 1293
1345 SkPath::FillType temporaryFillType = m_paintState->m_fillRule == RULE_EVENOD D ? SkPath::kEvenOdd_FillType : SkPath::kWinding_FillType; 1294 SkPath::FillType temporaryFillType =
1295 immutableState()->fillRule() == RULE_EVENODD ? SkPath::kEvenOdd_FillType : SkPath::kWinding_FillType;
1346 path.setFillType(temporaryFillType); 1296 path.setFillType(temporaryFillType);
1347 1297
1348 SkPaint paint; 1298 drawPath(path, immutableState()->fillPaint());
1349 setupPaintForFilling(&paint);
1350 drawPath(path, paint);
1351 1299
1352 path.setFillType(previousFillType); 1300 path.setFillType(previousFillType);
1353 } 1301 }
1354 1302
1355 void GraphicsContext::fillRect(const FloatRect& rect) 1303 void GraphicsContext::fillRect(const FloatRect& rect)
1356 { 1304 {
1357 if (paintingDisabled()) 1305 if (paintingDisabled())
1358 return; 1306 return;
1359 1307
1360 SkRect r = rect; 1308 SkRect r = rect;
1361 1309
1362 SkPaint paint; 1310 drawRect(r, immutableState()->fillPaint());
1363 setupPaintForFilling(&paint);
1364 drawRect(r, paint);
1365 } 1311 }
1366 1312
1367 void GraphicsContext::fillRect(const FloatRect& rect, const Color& color) 1313 void GraphicsContext::fillRect(const FloatRect& rect, const Color& color)
1368 { 1314 {
1369 if (paintingDisabled()) 1315 if (paintingDisabled())
1370 return; 1316 return;
1371 1317
1372 SkRect r = rect; 1318 SkRect r = rect;
1373 SkPaint paint; 1319 SkPaint paint = immutableState()->fillPaint();
1374 setupPaintCommon(&paint);
1375 paint.setColor(color.rgb()); 1320 paint.setColor(color.rgb());
1376 drawRect(r, paint); 1321 drawRect(r, paint);
1377 } 1322 }
1378 1323
1379 void GraphicsContext::fillBetweenRoundedRects(const IntRect& outer, const IntSiz e& outerTopLeft, const IntSize& outerTopRight, const IntSize& outerBottomLeft, c onst IntSize& outerBottomRight, 1324 void GraphicsContext::fillBetweenRoundedRects(const IntRect& outer, const IntSiz e& outerTopLeft, const IntSize& outerTopRight, const IntSize& outerBottomLeft, c onst IntSize& outerBottomRight,
1380 const IntRect& inner, const IntSize& innerTopLeft, const IntSize& innerTopRi ght, const IntSize& innerBottomLeft, const IntSize& innerBottomRight, const Colo r& color) { 1325 const IntRect& inner, const IntSize& innerTopLeft, const IntSize& innerTopRi ght, const IntSize& innerBottomLeft, const IntSize& innerBottomRight, const Colo r& color) {
1381 if (paintingDisabled()) 1326 if (paintingDisabled())
1382 return; 1327 return;
1383 1328
1384 SkVector outerRadii[4]; 1329 SkVector outerRadii[4];
1385 SkVector innerRadii[4]; 1330 SkVector innerRadii[4];
1386 setRadii(outerRadii, outerTopLeft, outerTopRight, outerBottomRight, outerBot tomLeft); 1331 setRadii(outerRadii, outerTopLeft, outerTopRight, outerBottomRight, outerBot tomLeft);
1387 setRadii(innerRadii, innerTopLeft, innerTopRight, innerBottomRight, innerBot tomLeft); 1332 setRadii(innerRadii, innerTopLeft, innerTopRight, innerBottomRight, innerBot tomLeft);
1388 1333
1389 SkRRect rrOuter; 1334 SkRRect rrOuter;
1390 SkRRect rrInner; 1335 SkRRect rrInner;
1391 rrOuter.setRectRadii(outer, outerRadii); 1336 rrOuter.setRectRadii(outer, outerRadii);
1392 rrInner.setRectRadii(inner, innerRadii); 1337 rrInner.setRectRadii(inner, innerRadii);
1393 1338
1394 SkPaint paint; 1339 SkPaint paint(immutableState()->fillPaint());
1395 setupPaintForFilling(&paint);
1396 paint.setColor(color.rgb()); 1340 paint.setColor(color.rgb());
1397 1341
1398 m_canvas->drawDRRect(rrOuter, rrInner, paint); 1342 m_canvas->drawDRRect(rrOuter, rrInner, paint);
1399 1343
1400 if (m_trackOpaqueRegion) 1344 if (m_trackOpaqueRegion)
1401 m_opaqueRegion.didDrawBounded(this, rrOuter.getBounds(), paint); 1345 m_opaqueRegion.didDrawBounded(this, rrOuter.getBounds(), paint);
1402 } 1346 }
1403 1347
1404 void GraphicsContext::fillBetweenRoundedRects(const RoundedRect& outer, const Ro undedRect& inner, const Color& color) 1348 void GraphicsContext::fillBetweenRoundedRects(const RoundedRect& outer, const Ro undedRect& inner, const Color& color)
1405 { 1349 {
(...skipping 17 matching lines...) Expand all
1423 fillRect(rect, color); 1367 fillRect(rect, color);
1424 return; 1368 return;
1425 } 1369 }
1426 1370
1427 SkVector radii[4]; 1371 SkVector radii[4];
1428 setRadii(radii, topLeft, topRight, bottomRight, bottomLeft); 1372 setRadii(radii, topLeft, topRight, bottomRight, bottomLeft);
1429 1373
1430 SkRRect rr; 1374 SkRRect rr;
1431 rr.setRectRadii(rect, radii); 1375 rr.setRectRadii(rect, radii);
1432 1376
1433 SkPaint paint; 1377 SkPaint paint(immutableState()->fillPaint());
1434 setupPaintForFilling(&paint);
1435 paint.setColor(color.rgb()); 1378 paint.setColor(color.rgb());
1436 1379
1437 m_canvas->drawRRect(rr, paint); 1380 m_canvas->drawRRect(rr, paint);
1438 1381
1439 if (m_trackOpaqueRegion) 1382 if (m_trackOpaqueRegion)
1440 m_opaqueRegion.didDrawBounded(this, rr.getBounds(), paint); 1383 m_opaqueRegion.didDrawBounded(this, rr.getBounds(), paint);
1441 } 1384 }
1442 1385
1443 void GraphicsContext::fillEllipse(const FloatRect& ellipse) 1386 void GraphicsContext::fillEllipse(const FloatRect& ellipse)
1444 { 1387 {
1445 if (paintingDisabled()) 1388 if (paintingDisabled())
1446 return; 1389 return;
1447 1390
1448 SkRect rect = ellipse; 1391 SkRect rect = ellipse;
1449 SkPaint paint; 1392 drawOval(rect, immutableState()->fillPaint());
1450 setupPaintForFilling(&paint);
1451 drawOval(rect, paint);
1452 } 1393 }
1453 1394
1454 void GraphicsContext::strokePath(const Path& pathToStroke) 1395 void GraphicsContext::strokePath(const Path& pathToStroke)
1455 { 1396 {
1456 if (paintingDisabled() || pathToStroke.isEmpty()) 1397 if (paintingDisabled() || pathToStroke.isEmpty())
1457 return; 1398 return;
1458 1399
1459 const SkPath& path = pathToStroke.skPath(); 1400 const SkPath& path = pathToStroke.skPath();
1460 SkPaint paint; 1401 drawPath(path, immutableState()->strokePaint());
1461 setupPaintForStroking(&paint);
1462 drawPath(path, paint);
1463 } 1402 }
1464 1403
1465 void GraphicsContext::strokeRect(const FloatRect& rect, float lineWidth) 1404 void GraphicsContext::strokeRect(const FloatRect& rect, float lineWidth)
1466 { 1405 {
1467 if (paintingDisabled()) 1406 if (paintingDisabled())
1468 return; 1407 return;
1469 1408
1470 SkPaint paint; 1409 SkPaint paint(immutableState()->strokePaint());
1471 setupPaintForStroking(&paint);
1472 paint.setStrokeWidth(WebCoreFloatToSkScalar(lineWidth)); 1410 paint.setStrokeWidth(WebCoreFloatToSkScalar(lineWidth));
1473 // strokerect has special rules for CSS when the rect is degenerate: 1411 // strokerect has special rules for CSS when the rect is degenerate:
1474 // if width==0 && height==0, do nothing 1412 // if width==0 && height==0, do nothing
1475 // if width==0 || height==0, then just draw line for the other dimension 1413 // if width==0 || height==0, then just draw line for the other dimension
1476 SkRect r(rect); 1414 SkRect r(rect);
1477 bool validW = r.width() > 0; 1415 bool validW = r.width() > 0;
1478 bool validH = r.height() > 0; 1416 bool validH = r.height() > 0;
1479 if (validW && validH) { 1417 if (validW && validH) {
1480 drawRect(r, paint); 1418 drawRect(r, paint);
1481 } else if (validW || validH) { 1419 } else if (validW || validH) {
1482 // we are expected to respect the lineJoin, so we can't just call 1420 // we are expected to respect the lineJoin, so we can't just call
1483 // drawLine -- we have to create a path that doubles back on itself. 1421 // drawLine -- we have to create a path that doubles back on itself.
1484 SkPath path; 1422 SkPath path;
1485 path.moveTo(r.fLeft, r.fTop); 1423 path.moveTo(r.fLeft, r.fTop);
1486 path.lineTo(r.fRight, r.fBottom); 1424 path.lineTo(r.fRight, r.fBottom);
1487 path.close(); 1425 path.close();
1488 drawPath(path, paint); 1426 drawPath(path, paint);
1489 } 1427 }
1490 } 1428 }
1491 1429
1492 void GraphicsContext::strokeEllipse(const FloatRect& ellipse) 1430 void GraphicsContext::strokeEllipse(const FloatRect& ellipse)
1493 { 1431 {
1494 if (paintingDisabled()) 1432 if (paintingDisabled())
1495 return; 1433 return;
1496 1434
1497 SkRect rect(ellipse); 1435 drawOval(ellipse, immutableState()->strokePaint());
1498 SkPaint paint;
1499 setupPaintForStroking(&paint);
1500 drawOval(rect, paint);
1501 } 1436 }
1502 1437
1503 void GraphicsContext::clipRoundedRect(const RoundedRect& rect, SkRegion::Op regi onOp) 1438 void GraphicsContext::clipRoundedRect(const RoundedRect& rect, SkRegion::Op regi onOp)
1504 { 1439 {
1505 if (paintingDisabled()) 1440 if (paintingDisabled())
1506 return; 1441 return;
1507 1442
1508 if (!rect.isRounded()) { 1443 if (!rect.isRounded()) {
1509 clipRect(rect.rect(), NotAntiAliased, regionOp); 1444 clipRect(rect.rect(), NotAntiAliased, regionOp);
1510 return; 1445 return;
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1735 setFillRule(oldFillRule); 1670 setFillRule(oldFillRule);
1736 setFillColor(oldFillColor); 1671 setFillColor(oldFillColor);
1737 } 1672 }
1738 1673
1739 void GraphicsContext::clearRect(const FloatRect& rect) 1674 void GraphicsContext::clearRect(const FloatRect& rect)
1740 { 1675 {
1741 if (paintingDisabled()) 1676 if (paintingDisabled())
1742 return; 1677 return;
1743 1678
1744 SkRect r = rect; 1679 SkRect r = rect;
1745 SkPaint paint; 1680 SkPaint paint(immutableState()->fillPaint());
1746 setupPaintForFilling(&paint);
1747 paint.setXfermodeMode(SkXfermode::kClear_Mode); 1681 paint.setXfermodeMode(SkXfermode::kClear_Mode);
1748 drawRect(r, paint); 1682 drawRect(r, paint);
1749 } 1683 }
1750 1684
1751 void GraphicsContext::adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2 , float strokeWidth, StrokeStyle penStyle) 1685 void GraphicsContext::adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2 , float strokeWidth, StrokeStyle penStyle)
1752 { 1686 {
1753 // For odd widths, we add in 0.5 to the appropriate x/y so that the float ar ithmetic 1687 // For odd widths, we add in 0.5 to the appropriate x/y so that the float ar ithmetic
1754 // works out. For example, with a border width of 3, WebKit will pass us (y 1+y2)/2, e.g., 1688 // works out. For example, with a border width of 3, WebKit will pass us (y 1+y2)/2, e.g.,
1755 // (50+53)/2 = 103/2 = 51 when we want 51.5. It is always true that an even width gave 1689 // (50+53)/2 = 103/2 = 51 when we want 51.5. It is always true that an even width gave
1756 // us a perfect position, but an odd width gave us a position that is off by exactly 0.5. 1690 // us a perfect position, but an odd width gave us a position that is off by exactly 0.5.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1814 But webkit can sometimes send us non-convex 4-point values, so we mark t he path's 1748 But webkit can sometimes send us non-convex 4-point values, so we mark t he path's
1815 convexity as unknown, so it will get computed by skia at draw time. 1749 convexity as unknown, so it will get computed by skia at draw time.
1816 See crbug.com 108605 1750 See crbug.com 108605
1817 */ 1751 */
1818 SkPath::Convexity convexity = SkPath::kConvex_Convexity; 1752 SkPath::Convexity convexity = SkPath::kConvex_Convexity;
1819 if (numPoints == 4) 1753 if (numPoints == 4)
1820 convexity = SkPath::kUnknown_Convexity; 1754 convexity = SkPath::kUnknown_Convexity;
1821 path->setConvexity(convexity); 1755 path->setConvexity(convexity);
1822 } 1756 }
1823 1757
1824 void GraphicsContext::setupPaintCommon(SkPaint* paint) const
1825 {
1826 #if defined(SK_DEBUG)
1827 {
1828 SkPaint defaultPaint;
1829 SkASSERT(*paint == defaultPaint);
1830 }
1831 #endif
1832
1833 paint->setAntiAlias(m_paintState->m_shouldAntialias);
1834
1835 if (!SkXfermode::IsMode(m_paintState->m_xferMode.get(), SkXfermode::kSrcOver _Mode))
1836 paint->setXfermode(m_paintState->m_xferMode.get());
1837
1838 if (m_paintState->m_looper)
1839 paint->setLooper(m_paintState->m_looper.get());
1840
1841 paint->setColorFilter(m_paintState->m_colorFilter.get());
1842 }
1843
1844 void GraphicsContext::drawOuterPath(const SkPath& path, SkPaint& paint, int widt h) 1758 void GraphicsContext::drawOuterPath(const SkPath& path, SkPaint& paint, int widt h)
1845 { 1759 {
1846 #if OS(MACOSX) 1760 #if OS(MACOSX)
1847 paint.setAlpha(64); 1761 paint.setAlpha(64);
1848 paint.setStrokeWidth(width); 1762 paint.setStrokeWidth(width);
1849 paint.setPathEffect(new SkCornerPathEffect((width - 1) * 0.5f))->unref(); 1763 paint.setPathEffect(new SkCornerPathEffect((width - 1) * 0.5f))->unref();
1850 #else 1764 #else
1851 paint.setStrokeWidth(1); 1765 paint.setStrokeWidth(1);
1852 paint.setPathEffect(new SkCornerPathEffect(1))->unref(); 1766 paint.setPathEffect(new SkCornerPathEffect(1))->unref();
1853 #endif 1767 #endif
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1985 { 1899 {
1986 static const SkPMColor colors[] = { 1900 static const SkPMColor colors[] = {
1987 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red 1901 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red
1988 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray 1902 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray
1989 }; 1903 };
1990 1904
1991 return colors[index]; 1905 return colors[index];
1992 } 1906 }
1993 #endif 1907 #endif
1994 1908
1995 void GraphicsContext::setupShader(SkPaint* paint, Gradient* grad, Pattern* pat, SkColor color) const
1996 {
1997 RefPtr<SkShader> shader;
1998
1999 if (grad) {
2000 shader = grad->shader();
2001 color = SK_ColorBLACK;
2002 } else if (pat) {
2003 shader = pat->shader();
2004 color = SK_ColorBLACK;
2005 paint->setFilterBitmap(imageInterpolationQuality() != InterpolationNone) ;
2006 }
2007
2008 paint->setColor(m_paintState->applyAlpha(color));
2009
2010 if (!shader)
2011 return;
2012
2013 paint->setShader(shader.get());
2014 }
2015
2016 void GraphicsContext::didDrawTextInRect(const SkRect& textRect) 1909 void GraphicsContext::didDrawTextInRect(const SkRect& textRect)
2017 { 1910 {
2018 if (m_trackTextRegion) { 1911 if (m_trackTextRegion) {
2019 TRACE_EVENT0("skia", "PlatformContextSkia::trackTextRegion"); 1912 TRACE_EVENT0("skia", "PlatformContextSkia::trackTextRegion");
2020 m_textRegion.join(textRect); 1913 m_textRegion.join(textRect);
2021 } 1914 }
2022 } 1915 }
2023 1916
2024 } 1917 }
OLDNEW
« no previous file with comments | « Source/platform/graphics/GraphicsContext.h ('k') | Source/platform/graphics/GraphicsContextState.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698