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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 m_metaData = *metaData; | 76 m_metaData = *metaData; |
77 | 77 |
78 // FIXME: Do some tests to determine how many states are typically used, and | 78 // FIXME: Do some tests to determine how many states are typically used, and |
79 // allocate several here. | 79 // allocate several here. |
80 m_paintStateStack.push_back(GraphicsContextState::create()); | 80 m_paintStateStack.push_back(GraphicsContextState::create()); |
81 m_paintState = m_paintStateStack.back().get(); | 81 m_paintState = m_paintStateStack.back().get(); |
82 | 82 |
83 if (contextDisabled()) { | 83 if (contextDisabled()) { |
84 DEFINE_STATIC_LOCAL(SkCanvas*, nullSkCanvas, | 84 DEFINE_STATIC_LOCAL(SkCanvas*, nullSkCanvas, |
85 (SkMakeNullCanvas().release())); | 85 (SkMakeNullCanvas().release())); |
86 DEFINE_STATIC_LOCAL(PaintCanvasPassThrough, nullCanvas, (nullSkCanvas)); | 86 DEFINE_STATIC_LOCAL(PaintCanvas, nullCanvas, (nullSkCanvas)); |
87 m_canvas = &nullCanvas; | 87 m_canvas = &nullCanvas; |
88 } | 88 } |
89 } | 89 } |
90 | 90 |
91 GraphicsContext::~GraphicsContext() { | 91 GraphicsContext::~GraphicsContext() { |
92 #if DCHECK_IS_ON() | 92 #if DCHECK_IS_ON() |
93 if (!m_disableDestructionChecks) { | 93 if (!m_disableDestructionChecks) { |
94 DCHECK(!m_paintStateIndex); | 94 DCHECK(!m_paintStateIndex); |
95 DCHECK(!m_paintState->saveCount()); | 95 DCHECK(!m_paintState->saveCount()); |
96 DCHECK(!m_layerCount); | 96 DCHECK(!m_layerCount); |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 path.cubicTo(kW * 3 / 8, kH * 1 / 4, | 554 path.cubicTo(kW * 3 / 8, kH * 1 / 4, |
555 kW * 3 / 8, kH * 3 / 4, | 555 kW * 3 / 8, kH * 3 / 4, |
556 kW * 5 / 8, kH * 3 / 4); | 556 kW * 5 / 8, kH * 3 / 4); |
557 path.cubicTo(kW * 7 / 8, kH * 3 / 4, | 557 path.cubicTo(kW * 7 / 8, kH * 3 / 4, |
558 kW * 7 / 8, kH * 1 / 4, | 558 kW * 7 / 8, kH * 1 / 4, |
559 kW * 9 / 8, kH * 1 / 4); | 559 kW * 9 / 8, kH * 1 / 4); |
560 | 560 |
561 PaintFlags flags; | 561 PaintFlags flags; |
562 flags.setAntiAlias(true); | 562 flags.setAntiAlias(true); |
563 flags.setColor(color); | 563 flags.setColor(color); |
564 flags.setStyle(SkPaint::kStroke_Style); | 564 flags.setStyle(PaintFlags::kStroke_Style); |
565 flags.setStrokeWidth(kH * 1 / 2); | 565 flags.setStrokeWidth(kH * 1 / 2); |
566 | 566 |
567 PaintRecorder recorder; | 567 PaintRecorder recorder; |
568 recorder.beginRecording(kW, kH); | 568 recorder.beginRecording(kW, kH); |
569 recorder.getRecordingCanvas()->drawPath(path, flags); | 569 recorder.getRecordingCanvas()->drawPath(path, flags); |
570 | 570 |
571 return recorder.finishRecordingAsPicture(); | 571 return recorder.finishRecordingAsPicture(); |
572 } | 572 } |
573 | 573 |
574 #else // OS(MACOSX) | 574 #else // OS(MACOSX) |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 #else | 639 #else |
640 // Offset it vertically by 1 so that there's some space under the text. | 640 // Offset it vertically by 1 so that there's some space under the text. |
641 originY += 1; | 641 originY += 1; |
642 #endif | 642 #endif |
643 | 643 |
644 const auto rect = SkRect::MakeWH(width, marker->cullRect().height() * zoom); | 644 const auto rect = SkRect::MakeWH(width, marker->cullRect().height() * zoom); |
645 const auto localMatrix = SkMatrix::MakeScale(zoom, zoom); | 645 const auto localMatrix = SkMatrix::MakeScale(zoom, zoom); |
646 | 646 |
647 PaintFlags flags; | 647 PaintFlags flags; |
648 flags.setAntiAlias(true); | 648 flags.setAntiAlias(true); |
649 flags.setShader(WrapSkShader(SkShader::MakePictureShader( | 649 flags.setShader(WrapSkShader( |
650 sk_ref_sp(marker), SkShader::kRepeat_TileMode, SkShader::kClamp_TileMode, | 650 MakePaintShaderRecord(sk_ref_sp(marker), SkShader::kRepeat_TileMode, |
651 &localMatrix, nullptr))); | 651 SkShader::kClamp_TileMode, &localMatrix, nullptr))); |
652 | 652 |
653 // Apply the origin translation as a global transform. This ensures that the | 653 // Apply the origin translation as a global transform. This ensures that the |
654 // shader local matrix depends solely on zoom => Skia can reuse the same | 654 // shader local matrix depends solely on zoom => Skia can reuse the same |
655 // cached tile for all markers at a given zoom level. | 655 // cached tile for all markers at a given zoom level. |
656 PaintCanvasAutoRestore acr(m_canvas, true); | 656 PaintCanvasAutoRestore acr(m_canvas, true); |
657 m_canvas->translate(originX, originY); | 657 m_canvas->translate(originX, originY); |
658 m_canvas->drawRect(rect, flags); | 658 m_canvas->drawRect(rect, flags); |
659 } | 659 } |
660 | 660 |
661 void GraphicsContext::drawLineForText(const FloatPoint& pt, float width) { | 661 void GraphicsContext::drawLineForText(const FloatPoint& pt, float width) { |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1243 | 1243 |
1244 m_canvas->scale(WebCoreFloatToSkScalar(x), WebCoreFloatToSkScalar(y)); | 1244 m_canvas->scale(WebCoreFloatToSkScalar(x), WebCoreFloatToSkScalar(y)); |
1245 } | 1245 } |
1246 | 1246 |
1247 void GraphicsContext::setURLForRect(const KURL& link, const IntRect& destRect) { | 1247 void GraphicsContext::setURLForRect(const KURL& link, const IntRect& destRect) { |
1248 if (contextDisabled()) | 1248 if (contextDisabled()) |
1249 return; | 1249 return; |
1250 DCHECK(m_canvas); | 1250 DCHECK(m_canvas); |
1251 | 1251 |
1252 sk_sp<SkData> url(SkData::MakeWithCString(link.getString().utf8().data())); | 1252 sk_sp<SkData> url(SkData::MakeWithCString(link.getString().utf8().data())); |
1253 SkAnnotateRectWithURL(m_canvas, destRect, url.get()); | 1253 PaintCanvasAnnotateRectWithURL(m_canvas, destRect, url.get()); |
1254 } | 1254 } |
1255 | 1255 |
1256 void GraphicsContext::setURLFragmentForRect(const String& destName, | 1256 void GraphicsContext::setURLFragmentForRect(const String& destName, |
1257 const IntRect& rect) { | 1257 const IntRect& rect) { |
1258 if (contextDisabled()) | 1258 if (contextDisabled()) |
1259 return; | 1259 return; |
1260 DCHECK(m_canvas); | 1260 DCHECK(m_canvas); |
1261 | 1261 |
1262 sk_sp<SkData> skDestName(SkData::MakeWithCString(destName.utf8().data())); | 1262 sk_sp<SkData> skDestName(SkData::MakeWithCString(destName.utf8().data())); |
1263 SkAnnotateLinkToDestination(m_canvas, rect, skDestName.get()); | 1263 PaintCanvasAnnotateLinkToDestination(m_canvas, rect, skDestName.get()); |
1264 } | 1264 } |
1265 | 1265 |
1266 void GraphicsContext::setURLDestinationLocation(const String& name, | 1266 void GraphicsContext::setURLDestinationLocation(const String& name, |
1267 const IntPoint& location) { | 1267 const IntPoint& location) { |
1268 if (contextDisabled()) | 1268 if (contextDisabled()) |
1269 return; | 1269 return; |
1270 DCHECK(m_canvas); | 1270 DCHECK(m_canvas); |
1271 | 1271 |
1272 sk_sp<SkData> skName(SkData::MakeWithCString(name.utf8().data())); | 1272 sk_sp<SkData> skName(SkData::MakeWithCString(name.utf8().data())); |
1273 SkAnnotateNamedDestination( | 1273 PaintCanvasAnnotateNamedDestination( |
1274 m_canvas, SkPoint::Make(location.x(), location.y()), skName.get()); | 1274 m_canvas, SkPoint::Make(location.x(), location.y()), skName.get()); |
1275 } | 1275 } |
1276 | 1276 |
1277 void GraphicsContext::concatCTM(const AffineTransform& affine) { | 1277 void GraphicsContext::concatCTM(const AffineTransform& affine) { |
1278 concat(affineTransformToSkMatrix(affine)); | 1278 concat(affineTransformToSkMatrix(affine)); |
1279 } | 1279 } |
1280 | 1280 |
1281 void GraphicsContext::fillRectWithRoundedHole( | 1281 void GraphicsContext::fillRectWithRoundedHole( |
1282 const FloatRect& rect, | 1282 const FloatRect& rect, |
1283 const FloatRoundedRect& roundedHoleRect, | 1283 const FloatRoundedRect& roundedHoleRect, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1337 break; | 1337 break; |
1338 default: | 1338 default: |
1339 NOTREACHED(); | 1339 NOTREACHED(); |
1340 break; | 1340 break; |
1341 } | 1341 } |
1342 | 1342 |
1343 return nullptr; | 1343 return nullptr; |
1344 } | 1344 } |
1345 | 1345 |
1346 } // namespace blink | 1346 } // namespace blink |
OLD | NEW |