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