OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 SkPaint paint(immutableState()->fillPaint()); |
Stephen White
2014/03/05 13:39:02
Nit: is it necessary to copy-construct here? Could
Stephen Chennney
2014/03/05 16:17:11
Done.
| |
653 setupPaintForFilling(&paint); | |
654 drawOval(rect, paint); | 610 drawOval(rect, paint); |
655 | 611 |
656 if (strokeStyle() != NoStroke) { | 612 if (strokeStyle() != NoStroke) |
657 paint.reset(); | 613 drawOval(rect, immutableState()->strokePaint()); |
658 setupPaintForStroking(&paint); | |
659 drawOval(rect, paint); | |
660 } | |
661 } | 614 } |
662 | 615 |
663 void GraphicsContext::drawFocusRing(const Path& focusRingPath, int width, int of fset, const Color& color) | 616 void GraphicsContext::drawFocusRing(const Path& focusRingPath, int width, int of fset, const Color& color) |
664 { | 617 { |
665 // FIXME: Implement support for offset. | 618 // FIXME: Implement support for offset. |
666 if (paintingDisabled()) | 619 if (paintingDisabled()) |
667 return; | 620 return; |
668 | 621 |
669 SkPaint paint; | 622 SkPaint paint; |
670 paint.setAntiAlias(true); | 623 paint.setAntiAlias(true); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
770 // This is only used to draw borders. | 723 // This is only used to draw borders. |
771 void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2) | 724 void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2) |
772 { | 725 { |
773 if (paintingDisabled()) | 726 if (paintingDisabled()) |
774 return; | 727 return; |
775 | 728 |
776 StrokeStyle penStyle = strokeStyle(); | 729 StrokeStyle penStyle = strokeStyle(); |
777 if (penStyle == NoStroke) | 730 if (penStyle == NoStroke) |
778 return; | 731 return; |
779 | 732 |
780 SkPaint paint; | |
781 FloatPoint p1 = point1; | 733 FloatPoint p1 = point1; |
782 FloatPoint p2 = point2; | 734 FloatPoint p2 = point2; |
783 bool isVerticalLine = (p1.x() == p2.x()); | 735 bool isVerticalLine = (p1.x() == p2.x()); |
784 int width = roundf(strokeThickness()); | 736 int width = roundf(strokeThickness()); |
785 | 737 |
786 // We know these are vertical or horizontal lines, so the length will just | 738 // 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 - | 739 // 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. | 740 // probably worth the speed up of no square root, which also won't be exact. |
789 FloatSize disp = p2 - p1; | 741 FloatSize disp = p2 - p1; |
790 int length = SkScalarRoundToInt(disp.width() + disp.height()); | 742 int length = SkScalarRoundToInt(disp.width() + disp.height()); |
791 setupPaintForStroking(&paint, length); | 743 SkPaint paint(immutableState()->strokePaint()); |
744 immutableState()->strokeData().setupPaintDashPathEffect(&paint, length); | |
792 | 745 |
793 if (strokeStyle() == DottedStroke || strokeStyle() == DashedStroke) { | 746 if (strokeStyle() == DottedStroke || strokeStyle() == DashedStroke) { |
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 | 749 |
797 SkRect r1, r2; | 750 SkRect r1, r2; |
798 r1.set(p1.x(), p1.y(), p1.x() + width, p1.y() + width); | 751 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); | 752 r2.set(p2.x(), p2.y(), p2.x() + width, p2.y() + width); |
800 | 753 |
801 if (isVerticalLine) { | 754 if (isVerticalLine) { |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
963 r.fTop = WebCoreFloatToSkScalar(floorf(pt.y() + 0.5f)); | 916 r.fTop = WebCoreFloatToSkScalar(floorf(pt.y() + 0.5f)); |
964 r.fRight = r.fLeft + WebCoreFloatToSkScalar(width); | 917 r.fRight = r.fLeft + WebCoreFloatToSkScalar(width); |
965 r.fBottom = r.fTop + SkIntToScalar(thickness); | 918 r.fBottom = r.fTop + SkIntToScalar(thickness); |
966 | 919 |
967 SkPaint paint; | 920 SkPaint paint; |
968 switch (strokeStyle()) { | 921 switch (strokeStyle()) { |
969 case NoStroke: | 922 case NoStroke: |
970 case SolidStroke: | 923 case SolidStroke: |
971 case DoubleStroke: | 924 case DoubleStroke: |
972 case WavyStroke: | 925 case WavyStroke: |
973 setupPaintForFilling(&paint); | 926 paint = immutableState()->fillPaint(); |
974 break; | 927 break; |
975 case DottedStroke: | 928 case DottedStroke: |
976 case DashedStroke: | 929 case DashedStroke: |
977 setupPaintForStroking(&paint); | 930 paint = immutableState()->strokePaint(); |
978 break; | 931 break; |
979 } | 932 } |
980 | 933 |
981 // Text lines are drawn using the stroke color. | 934 // Text lines are drawn using the stroke color. |
982 paint.setColor(effectiveStrokeColor()); | 935 paint.setColor(effectiveStrokeColor()); |
983 drawRect(r, paint); | 936 drawRect(r, paint); |
984 } | 937 } |
985 | 938 |
986 // Draws a filled rectangle with a stroked border. | 939 // Draws a filled rectangle with a stroked border. |
987 void GraphicsContext::drawRect(const IntRect& rect) | 940 void GraphicsContext::drawRect(const IntRect& rect) |
988 { | 941 { |
989 if (paintingDisabled()) | 942 if (paintingDisabled()) |
990 return; | 943 return; |
991 | 944 |
992 ASSERT(!rect.isEmpty()); | 945 ASSERT(!rect.isEmpty()); |
993 if (rect.isEmpty()) | 946 if (rect.isEmpty()) |
994 return; | 947 return; |
995 | 948 |
996 SkRect skRect = rect; | 949 SkRect skRect = rect; |
997 SkPaint paint; | 950 int fillcolorNotTransparent = immutableState()->fillColor().rgb() & 0xFF0000 00; |
998 int fillcolorNotTransparent = m_paintState->m_fillColor.rgb() & 0xFF000000; | 951 if (fillcolorNotTransparent) |
999 if (fillcolorNotTransparent) { | 952 drawRect(skRect, immutableState()->fillPaint()); |
1000 setupPaintForFilling(&paint); | |
1001 drawRect(skRect, paint); | |
1002 } | |
1003 | 953 |
1004 if (m_paintState->m_strokeData.style() != NoStroke && (m_paintState->m_strok eData.color().rgb() & 0xFF000000)) { | 954 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. | 955 // We do a fill of four rects to simulate the stroke of a border. |
1006 paint.reset(); | 956 SkPaint paint(immutableState()->fillPaint()); |
1007 setupPaintForFilling(&paint); | |
1008 // need to jam in the strokeColor | 957 // need to jam in the strokeColor |
1009 paint.setColor(this->effectiveStrokeColor()); | 958 paint.setColor(immutableState()->effectiveStrokeColor()); |
1010 | 959 |
1011 SkRect topBorder = { skRect.fLeft, skRect.fTop, skRect.fRight, skRect.fT op + 1 }; | 960 SkRect topBorder = { skRect.fLeft, skRect.fTop, skRect.fRight, skRect.fT op + 1 }; |
1012 drawRect(topBorder, paint); | 961 drawRect(topBorder, paint); |
1013 SkRect bottomBorder = { skRect.fLeft, skRect.fBottom - 1, skRect.fRight, skRect.fBottom }; | 962 SkRect bottomBorder = { skRect.fLeft, skRect.fBottom - 1, skRect.fRight, skRect.fBottom }; |
1014 drawRect(bottomBorder, paint); | 963 drawRect(bottomBorder, paint); |
1015 SkRect leftBorder = { skRect.fLeft, skRect.fTop + 1, skRect.fLeft + 1, s kRect.fBottom - 1 }; | 964 SkRect leftBorder = { skRect.fLeft, skRect.fTop + 1, skRect.fLeft + 1, s kRect.fBottom - 1 }; |
1016 drawRect(leftBorder, paint); | 965 drawRect(leftBorder, paint); |
1017 SkRect rightBorder = { skRect.fRight - 1, skRect.fTop + 1, skRect.fRight , skRect.fBottom - 1 }; | 966 SkRect rightBorder = { skRect.fRight - 1, skRect.fTop + 1, skRect.fRight , skRect.fBottom - 1 }; |
1018 drawRect(rightBorder, paint); | 967 drawRect(rightBorder, paint); |
1019 } | 968 } |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1237 m_opaqueRegion.didDrawRect(this, rect, *paint, &bitmap); | 1186 m_opaqueRegion.didDrawRect(this, rect, *paint, &bitmap); |
1238 } | 1187 } |
1239 } | 1188 } |
1240 | 1189 |
1241 void GraphicsContext::drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, | 1190 void GraphicsContext::drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, |
1242 const SkRect& dst, const SkPaint* paint) | 1191 const SkRect& dst, const SkPaint* paint) |
1243 { | 1192 { |
1244 if (paintingDisabled()) | 1193 if (paintingDisabled()) |
1245 return; | 1194 return; |
1246 | 1195 |
1247 SkCanvas::DrawBitmapRectFlags flags = m_paintState->m_shouldClampToSourceRec t ? SkCanvas::kNone_DrawBitmapRectFlag : SkCanvas::kBleed_DrawBitmapRectFlag; | 1196 SkCanvas::DrawBitmapRectFlags flags = |
1197 immutableState()->shouldClampToSourceRect() ? SkCanvas::kNone_DrawBitmap RectFlag : SkCanvas::kBleed_DrawBitmapRectFlag; | |
1248 | 1198 |
1249 m_canvas->drawBitmapRectToRect(bitmap, src, dst, paint, flags); | 1199 m_canvas->drawBitmapRectToRect(bitmap, src, dst, paint, flags); |
1250 | 1200 |
1251 if (m_trackOpaqueRegion) | 1201 if (m_trackOpaqueRegion) |
1252 m_opaqueRegion.didDrawRect(this, dst, *paint, &bitmap); | 1202 m_opaqueRegion.didDrawRect(this, dst, *paint, &bitmap); |
1253 } | 1203 } |
1254 | 1204 |
1255 void GraphicsContext::drawOval(const SkRect& oval, const SkPaint& paint) | 1205 void GraphicsContext::drawOval(const SkRect& oval, const SkPaint& paint) |
1256 { | 1206 { |
1257 if (paintingDisabled()) | 1207 if (paintingDisabled()) |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1335 | 1285 |
1336 void GraphicsContext::fillPath(const Path& pathToFill) | 1286 void GraphicsContext::fillPath(const Path& pathToFill) |
1337 { | 1287 { |
1338 if (paintingDisabled() || pathToFill.isEmpty()) | 1288 if (paintingDisabled() || pathToFill.isEmpty()) |
1339 return; | 1289 return; |
1340 | 1290 |
1341 // Use const_cast and temporarily modify the fill type instead of copying th e path. | 1291 // Use const_cast and temporarily modify the fill type instead of copying th e path. |
1342 SkPath& path = const_cast<SkPath&>(pathToFill.skPath()); | 1292 SkPath& path = const_cast<SkPath&>(pathToFill.skPath()); |
1343 SkPath::FillType previousFillType = path.getFillType(); | 1293 SkPath::FillType previousFillType = path.getFillType(); |
1344 | 1294 |
1345 SkPath::FillType temporaryFillType = m_paintState->m_fillRule == RULE_EVENOD D ? SkPath::kEvenOdd_FillType : SkPath::kWinding_FillType; | 1295 SkPath::FillType temporaryFillType = |
1296 immutableState()->fillRule() == RULE_EVENODD ? SkPath::kEvenOdd_FillType : SkPath::kWinding_FillType; | |
1346 path.setFillType(temporaryFillType); | 1297 path.setFillType(temporaryFillType); |
1347 | 1298 |
1348 SkPaint paint; | 1299 drawPath(path, immutableState()->fillPaint()); |
1349 setupPaintForFilling(&paint); | |
1350 drawPath(path, paint); | |
1351 | 1300 |
1352 path.setFillType(previousFillType); | 1301 path.setFillType(previousFillType); |
1353 } | 1302 } |
1354 | 1303 |
1355 void GraphicsContext::fillRect(const FloatRect& rect) | 1304 void GraphicsContext::fillRect(const FloatRect& rect) |
1356 { | 1305 { |
1357 if (paintingDisabled()) | 1306 if (paintingDisabled()) |
1358 return; | 1307 return; |
1359 | 1308 |
1360 SkRect r = rect; | 1309 SkRect r = rect; |
1361 | 1310 |
1362 SkPaint paint; | 1311 drawRect(r, immutableState()->fillPaint()); |
1363 setupPaintForFilling(&paint); | |
1364 drawRect(r, paint); | |
1365 } | 1312 } |
1366 | 1313 |
1367 void GraphicsContext::fillRect(const FloatRect& rect, const Color& color) | 1314 void GraphicsContext::fillRect(const FloatRect& rect, const Color& color) |
1368 { | 1315 { |
1369 if (paintingDisabled()) | 1316 if (paintingDisabled()) |
1370 return; | 1317 return; |
1371 | 1318 |
1372 SkRect r = rect; | 1319 SkRect r = rect; |
1373 SkPaint paint; | 1320 SkPaint paint = immutableState()->fillPaint(); |
Stephen White
2014/03/05 13:39:02
Won't this potentially include a gradient, where i
Stephen Chennney
2014/03/05 16:17:11
Good point. I believe the change is OK because thi
| |
1374 setupPaintCommon(&paint); | |
1375 paint.setColor(color.rgb()); | 1321 paint.setColor(color.rgb()); |
1376 drawRect(r, paint); | 1322 drawRect(r, paint); |
1377 } | 1323 } |
1378 | 1324 |
1379 void GraphicsContext::fillBetweenRoundedRects(const IntRect& outer, const IntSiz e& outerTopLeft, const IntSize& outerTopRight, const IntSize& outerBottomLeft, c onst IntSize& outerBottomRight, | 1325 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) { | 1326 const IntRect& inner, const IntSize& innerTopLeft, const IntSize& innerTopRi ght, const IntSize& innerBottomLeft, const IntSize& innerBottomRight, const Colo r& color) { |
1381 if (paintingDisabled()) | 1327 if (paintingDisabled()) |
1382 return; | 1328 return; |
1383 | 1329 |
1384 SkVector outerRadii[4]; | 1330 SkVector outerRadii[4]; |
1385 SkVector innerRadii[4]; | 1331 SkVector innerRadii[4]; |
1386 setRadii(outerRadii, outerTopLeft, outerTopRight, outerBottomRight, outerBot tomLeft); | 1332 setRadii(outerRadii, outerTopLeft, outerTopRight, outerBottomRight, outerBot tomLeft); |
1387 setRadii(innerRadii, innerTopLeft, innerTopRight, innerBottomRight, innerBot tomLeft); | 1333 setRadii(innerRadii, innerTopLeft, innerTopRight, innerBottomRight, innerBot tomLeft); |
1388 | 1334 |
1389 SkRRect rrOuter; | 1335 SkRRect rrOuter; |
1390 SkRRect rrInner; | 1336 SkRRect rrInner; |
1391 rrOuter.setRectRadii(outer, outerRadii); | 1337 rrOuter.setRectRadii(outer, outerRadii); |
1392 rrInner.setRectRadii(inner, innerRadii); | 1338 rrInner.setRectRadii(inner, innerRadii); |
1393 | 1339 |
1394 SkPaint paint; | 1340 SkPaint paint(immutableState()->fillPaint()); |
1395 setupPaintForFilling(&paint); | |
1396 paint.setColor(color.rgb()); | 1341 paint.setColor(color.rgb()); |
1397 | 1342 |
1398 m_canvas->drawDRRect(rrOuter, rrInner, paint); | 1343 m_canvas->drawDRRect(rrOuter, rrInner, paint); |
1399 | 1344 |
1400 if (m_trackOpaqueRegion) | 1345 if (m_trackOpaqueRegion) |
1401 m_opaqueRegion.didDrawBounded(this, rrOuter.getBounds(), paint); | 1346 m_opaqueRegion.didDrawBounded(this, rrOuter.getBounds(), paint); |
1402 } | 1347 } |
1403 | 1348 |
1404 void GraphicsContext::fillBetweenRoundedRects(const RoundedRect& outer, const Ro undedRect& inner, const Color& color) | 1349 void GraphicsContext::fillBetweenRoundedRects(const RoundedRect& outer, const Ro undedRect& inner, const Color& color) |
1405 { | 1350 { |
(...skipping 17 matching lines...) Expand all Loading... | |
1423 fillRect(rect, color); | 1368 fillRect(rect, color); |
1424 return; | 1369 return; |
1425 } | 1370 } |
1426 | 1371 |
1427 SkVector radii[4]; | 1372 SkVector radii[4]; |
1428 setRadii(radii, topLeft, topRight, bottomRight, bottomLeft); | 1373 setRadii(radii, topLeft, topRight, bottomRight, bottomLeft); |
1429 | 1374 |
1430 SkRRect rr; | 1375 SkRRect rr; |
1431 rr.setRectRadii(rect, radii); | 1376 rr.setRectRadii(rect, radii); |
1432 | 1377 |
1433 SkPaint paint; | 1378 SkPaint paint(immutableState()->fillPaint()); |
1434 setupPaintForFilling(&paint); | |
1435 paint.setColor(color.rgb()); | 1379 paint.setColor(color.rgb()); |
1436 | 1380 |
1437 m_canvas->drawRRect(rr, paint); | 1381 m_canvas->drawRRect(rr, paint); |
1438 | 1382 |
1439 if (m_trackOpaqueRegion) | 1383 if (m_trackOpaqueRegion) |
1440 m_opaqueRegion.didDrawBounded(this, rr.getBounds(), paint); | 1384 m_opaqueRegion.didDrawBounded(this, rr.getBounds(), paint); |
1441 } | 1385 } |
1442 | 1386 |
1443 void GraphicsContext::fillEllipse(const FloatRect& ellipse) | 1387 void GraphicsContext::fillEllipse(const FloatRect& ellipse) |
1444 { | 1388 { |
1445 if (paintingDisabled()) | 1389 if (paintingDisabled()) |
1446 return; | 1390 return; |
1447 | 1391 |
1448 SkRect rect = ellipse; | 1392 SkRect rect = ellipse; |
1449 SkPaint paint; | 1393 drawOval(rect, immutableState()->fillPaint()); |
1450 setupPaintForFilling(&paint); | |
1451 drawOval(rect, paint); | |
1452 } | 1394 } |
1453 | 1395 |
1454 void GraphicsContext::strokePath(const Path& pathToStroke) | 1396 void GraphicsContext::strokePath(const Path& pathToStroke) |
1455 { | 1397 { |
1456 if (paintingDisabled() || pathToStroke.isEmpty()) | 1398 if (paintingDisabled() || pathToStroke.isEmpty()) |
1457 return; | 1399 return; |
1458 | 1400 |
1459 const SkPath& path = pathToStroke.skPath(); | 1401 const SkPath& path = pathToStroke.skPath(); |
1460 SkPaint paint; | 1402 drawPath(path, immutableState()->strokePaint()); |
1461 setupPaintForStroking(&paint); | |
1462 drawPath(path, paint); | |
1463 } | 1403 } |
1464 | 1404 |
1465 void GraphicsContext::strokeRect(const FloatRect& rect, float lineWidth) | 1405 void GraphicsContext::strokeRect(const FloatRect& rect, float lineWidth) |
1466 { | 1406 { |
1467 if (paintingDisabled()) | 1407 if (paintingDisabled()) |
1468 return; | 1408 return; |
1469 | 1409 |
1470 SkPaint paint; | 1410 SkPaint paint(immutableState()->strokePaint()); |
1471 setupPaintForStroking(&paint); | |
1472 paint.setStrokeWidth(WebCoreFloatToSkScalar(lineWidth)); | 1411 paint.setStrokeWidth(WebCoreFloatToSkScalar(lineWidth)); |
1473 // strokerect has special rules for CSS when the rect is degenerate: | 1412 // strokerect has special rules for CSS when the rect is degenerate: |
1474 // if width==0 && height==0, do nothing | 1413 // if width==0 && height==0, do nothing |
1475 // if width==0 || height==0, then just draw line for the other dimension | 1414 // if width==0 || height==0, then just draw line for the other dimension |
1476 SkRect r(rect); | 1415 SkRect r(rect); |
1477 bool validW = r.width() > 0; | 1416 bool validW = r.width() > 0; |
1478 bool validH = r.height() > 0; | 1417 bool validH = r.height() > 0; |
1479 if (validW && validH) { | 1418 if (validW && validH) { |
1480 drawRect(r, paint); | 1419 drawRect(r, paint); |
1481 } else if (validW || validH) { | 1420 } else if (validW || validH) { |
1482 // we are expected to respect the lineJoin, so we can't just call | 1421 // 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. | 1422 // drawLine -- we have to create a path that doubles back on itself. |
1484 SkPath path; | 1423 SkPath path; |
1485 path.moveTo(r.fLeft, r.fTop); | 1424 path.moveTo(r.fLeft, r.fTop); |
1486 path.lineTo(r.fRight, r.fBottom); | 1425 path.lineTo(r.fRight, r.fBottom); |
1487 path.close(); | 1426 path.close(); |
1488 drawPath(path, paint); | 1427 drawPath(path, paint); |
1489 } | 1428 } |
1490 } | 1429 } |
1491 | 1430 |
1492 void GraphicsContext::strokeEllipse(const FloatRect& ellipse) | 1431 void GraphicsContext::strokeEllipse(const FloatRect& ellipse) |
1493 { | 1432 { |
1494 if (paintingDisabled()) | 1433 if (paintingDisabled()) |
1495 return; | 1434 return; |
1496 | 1435 |
1497 SkRect rect(ellipse); | 1436 drawOval(ellipse, immutableState()->strokePaint()); |
1498 SkPaint paint; | |
1499 setupPaintForStroking(&paint); | |
1500 drawOval(rect, paint); | |
1501 } | 1437 } |
1502 | 1438 |
1503 void GraphicsContext::clipRoundedRect(const RoundedRect& rect, SkRegion::Op regi onOp) | 1439 void GraphicsContext::clipRoundedRect(const RoundedRect& rect, SkRegion::Op regi onOp) |
1504 { | 1440 { |
1505 if (paintingDisabled()) | 1441 if (paintingDisabled()) |
1506 return; | 1442 return; |
1507 | 1443 |
1508 if (!rect.isRounded()) { | 1444 if (!rect.isRounded()) { |
1509 clipRect(rect.rect(), NotAntiAliased, regionOp); | 1445 clipRect(rect.rect(), NotAntiAliased, regionOp); |
1510 return; | 1446 return; |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1735 setFillRule(oldFillRule); | 1671 setFillRule(oldFillRule); |
1736 setFillColor(oldFillColor); | 1672 setFillColor(oldFillColor); |
1737 } | 1673 } |
1738 | 1674 |
1739 void GraphicsContext::clearRect(const FloatRect& rect) | 1675 void GraphicsContext::clearRect(const FloatRect& rect) |
1740 { | 1676 { |
1741 if (paintingDisabled()) | 1677 if (paintingDisabled()) |
1742 return; | 1678 return; |
1743 | 1679 |
1744 SkRect r = rect; | 1680 SkRect r = rect; |
1745 SkPaint paint; | 1681 SkPaint paint(immutableState()->fillPaint()); |
1746 setupPaintForFilling(&paint); | |
1747 paint.setXfermodeMode(SkXfermode::kClear_Mode); | 1682 paint.setXfermodeMode(SkXfermode::kClear_Mode); |
1748 drawRect(r, paint); | 1683 drawRect(r, paint); |
1749 } | 1684 } |
1750 | 1685 |
1751 void GraphicsContext::adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2 , float strokeWidth, StrokeStyle penStyle) | 1686 void GraphicsContext::adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2 , float strokeWidth, StrokeStyle penStyle) |
1752 { | 1687 { |
1753 // For odd widths, we add in 0.5 to the appropriate x/y so that the float ar ithmetic | 1688 // 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., | 1689 // 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 | 1690 // (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. | 1691 // 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 Loading... | |
1814 But webkit can sometimes send us non-convex 4-point values, so we mark t he path's | 1749 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. | 1750 convexity as unknown, so it will get computed by skia at draw time. |
1816 See crbug.com 108605 | 1751 See crbug.com 108605 |
1817 */ | 1752 */ |
1818 SkPath::Convexity convexity = SkPath::kConvex_Convexity; | 1753 SkPath::Convexity convexity = SkPath::kConvex_Convexity; |
1819 if (numPoints == 4) | 1754 if (numPoints == 4) |
1820 convexity = SkPath::kUnknown_Convexity; | 1755 convexity = SkPath::kUnknown_Convexity; |
1821 path->setConvexity(convexity); | 1756 path->setConvexity(convexity); |
1822 } | 1757 } |
1823 | 1758 |
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) | 1759 void GraphicsContext::drawOuterPath(const SkPath& path, SkPaint& paint, int widt h) |
1845 { | 1760 { |
1846 #if OS(MACOSX) | 1761 #if OS(MACOSX) |
1847 paint.setAlpha(64); | 1762 paint.setAlpha(64); |
1848 paint.setStrokeWidth(width); | 1763 paint.setStrokeWidth(width); |
1849 paint.setPathEffect(new SkCornerPathEffect((width - 1) * 0.5f))->unref(); | 1764 paint.setPathEffect(new SkCornerPathEffect((width - 1) * 0.5f))->unref(); |
1850 #else | 1765 #else |
1851 paint.setStrokeWidth(1); | 1766 paint.setStrokeWidth(1); |
1852 paint.setPathEffect(new SkCornerPathEffect(1))->unref(); | 1767 paint.setPathEffect(new SkCornerPathEffect(1))->unref(); |
1853 #endif | 1768 #endif |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1985 { | 1900 { |
1986 static const SkPMColor colors[] = { | 1901 static const SkPMColor colors[] = { |
1987 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red | 1902 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red |
1988 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray | 1903 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray |
1989 }; | 1904 }; |
1990 | 1905 |
1991 return colors[index]; | 1906 return colors[index]; |
1992 } | 1907 } |
1993 #endif | 1908 #endif |
1994 | 1909 |
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) | 1910 void GraphicsContext::didDrawTextInRect(const SkRect& textRect) |
2017 { | 1911 { |
2018 if (m_trackTextRegion) { | 1912 if (m_trackTextRegion) { |
2019 TRACE_EVENT0("skia", "PlatformContextSkia::trackTextRegion"); | 1913 TRACE_EVENT0("skia", "PlatformContextSkia::trackTextRegion"); |
2020 m_textRegion.join(textRect); | 1914 m_textRegion.join(textRect); |
2021 } | 1915 } |
2022 } | 1916 } |
2023 | 1917 |
2024 } | 1918 } |
OLD | NEW |