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