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

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

Issue 2690583002: Make cc/paint have concrete types (Closed)
Patch Set: PaintRecord as typedef, fixup playback calls Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(PaintCanvasPassThrough, nullCanvas, (nullSkCanvas)); 85 DEFINE_STATIC_LOCAL(PaintCanvas, 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
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, nullptr); 270 m_canvas = m_paintRecorder.beginRecording(bounds);
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(), nullptr); 279 recorder.beginRecording(SkRect::MakeEmpty());
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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 path.cubicTo(kW * 3 / 8, kH * 1 / 4, 564 path.cubicTo(kW * 3 / 8, kH * 1 / 4,
565 kW * 3 / 8, kH * 3 / 4, 565 kW * 3 / 8, kH * 3 / 4,
566 kW * 5 / 8, kH * 3 / 4); 566 kW * 5 / 8, kH * 3 / 4);
567 path.cubicTo(kW * 7 / 8, kH * 3 / 4, 567 path.cubicTo(kW * 7 / 8, kH * 3 / 4,
568 kW * 7 / 8, kH * 1 / 4, 568 kW * 7 / 8, kH * 1 / 4,
569 kW * 9 / 8, kH * 1 / 4); 569 kW * 9 / 8, kH * 1 / 4);
570 570
571 PaintFlags flags; 571 PaintFlags flags;
572 flags.setAntiAlias(true); 572 flags.setAntiAlias(true);
573 flags.setColor(color); 573 flags.setColor(color);
574 flags.setStyle(SkPaint::kStroke_Style); 574 flags.setStyle(PaintFlags::kStroke_Style);
575 flags.setStrokeWidth(kH * 1 / 2); 575 flags.setStrokeWidth(kH * 1 / 2);
576 576
577 PaintRecorder recorder; 577 PaintRecorder recorder;
578 recorder.beginRecording(kW, kH); 578 recorder.beginRecording(kW, kH);
579 recorder.getRecordingCanvas()->drawPath(path, flags); 579 recorder.getRecordingCanvas()->drawPath(path, flags);
580 580
581 return recorder.finishRecordingAsPicture(); 581 return recorder.finishRecordingAsPicture();
582 } 582 }
583 583
584 #else // OS(MACOSX) 584 #else // OS(MACOSX)
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 #else 649 #else
650 // Offset it vertically by 1 so that there's some space under the text. 650 // Offset it vertically by 1 so that there's some space under the text.
651 originY += 1; 651 originY += 1;
652 #endif 652 #endif
653 653
654 const auto rect = SkRect::MakeWH(width, marker->cullRect().height() * zoom); 654 const auto rect = SkRect::MakeWH(width, marker->cullRect().height() * zoom);
655 const auto localMatrix = SkMatrix::MakeScale(zoom, zoom); 655 const auto localMatrix = SkMatrix::MakeScale(zoom, zoom);
656 656
657 PaintFlags flags; 657 PaintFlags flags;
658 flags.setAntiAlias(true); 658 flags.setAntiAlias(true);
659 flags.setShader(WrapSkShader(SkShader::MakePictureShader( 659 flags.setShader(WrapSkShader(
660 sk_ref_sp(marker), SkShader::kRepeat_TileMode, SkShader::kClamp_TileMode, 660 MakePaintShaderRecord(sk_ref_sp(marker), SkShader::kRepeat_TileMode,
661 &localMatrix, nullptr))); 661 SkShader::kClamp_TileMode, &localMatrix, nullptr)));
662 662
663 // Apply the origin translation as a global transform. This ensures that the 663 // Apply the origin translation as a global transform. This ensures that the
664 // shader local matrix depends solely on zoom => Skia can reuse the same 664 // shader local matrix depends solely on zoom => Skia can reuse the same
665 // cached tile for all markers at a given zoom level. 665 // cached tile for all markers at a given zoom level.
666 PaintCanvasAutoRestore acr(m_canvas, true); 666 PaintCanvasAutoRestore acr(m_canvas, true);
667 m_canvas->translate(originX, originY); 667 m_canvas->translate(originX, originY);
668 m_canvas->drawRect(rect, flags); 668 m_canvas->drawRect(rect, flags);
669 } 669 }
670 670
671 void GraphicsContext::drawLineForText(const FloatPoint& pt, float width) { 671 void GraphicsContext::drawLineForText(const FloatPoint& pt, float width) {
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 1253
1254 m_canvas->scale(WebCoreFloatToSkScalar(x), WebCoreFloatToSkScalar(y)); 1254 m_canvas->scale(WebCoreFloatToSkScalar(x), WebCoreFloatToSkScalar(y));
1255 } 1255 }
1256 1256
1257 void GraphicsContext::setURLForRect(const KURL& link, const IntRect& destRect) { 1257 void GraphicsContext::setURLForRect(const KURL& link, const IntRect& destRect) {
1258 if (contextDisabled()) 1258 if (contextDisabled())
1259 return; 1259 return;
1260 DCHECK(m_canvas); 1260 DCHECK(m_canvas);
1261 1261
1262 sk_sp<SkData> url(SkData::MakeWithCString(link.getString().utf8().data())); 1262 sk_sp<SkData> url(SkData::MakeWithCString(link.getString().utf8().data()));
1263 SkAnnotateRectWithURL(m_canvas, destRect, url.get()); 1263 PaintCanvasAnnotateRectWithURL(m_canvas, destRect, url.get());
1264 } 1264 }
1265 1265
1266 void GraphicsContext::setURLFragmentForRect(const String& destName, 1266 void GraphicsContext::setURLFragmentForRect(const String& destName,
1267 const IntRect& rect) { 1267 const IntRect& rect) {
1268 if (contextDisabled()) 1268 if (contextDisabled())
1269 return; 1269 return;
1270 DCHECK(m_canvas); 1270 DCHECK(m_canvas);
1271 1271
1272 sk_sp<SkData> skDestName(SkData::MakeWithCString(destName.utf8().data())); 1272 sk_sp<SkData> skDestName(SkData::MakeWithCString(destName.utf8().data()));
1273 SkAnnotateLinkToDestination(m_canvas, rect, skDestName.get()); 1273 PaintCanvasAnnotateLinkToDestination(m_canvas, rect, skDestName.get());
1274 } 1274 }
1275 1275
1276 void GraphicsContext::setURLDestinationLocation(const String& name, 1276 void GraphicsContext::setURLDestinationLocation(const String& name,
1277 const IntPoint& location) { 1277 const IntPoint& location) {
1278 if (contextDisabled()) 1278 if (contextDisabled())
1279 return; 1279 return;
1280 DCHECK(m_canvas); 1280 DCHECK(m_canvas);
1281 1281
1282 sk_sp<SkData> skName(SkData::MakeWithCString(name.utf8().data())); 1282 sk_sp<SkData> skName(SkData::MakeWithCString(name.utf8().data()));
1283 SkAnnotateNamedDestination( 1283 PaintCanvasAnnotateNamedDestination(
1284 m_canvas, SkPoint::Make(location.x(), location.y()), skName.get()); 1284 m_canvas, SkPoint::Make(location.x(), location.y()), skName.get());
1285 } 1285 }
1286 1286
1287 void GraphicsContext::concatCTM(const AffineTransform& affine) { 1287 void GraphicsContext::concatCTM(const AffineTransform& affine) {
1288 concat(affineTransformToSkMatrix(affine)); 1288 concat(affineTransformToSkMatrix(affine));
1289 } 1289 }
1290 1290
1291 void GraphicsContext::fillRectWithRoundedHole( 1291 void GraphicsContext::fillRectWithRoundedHole(
1292 const FloatRect& rect, 1292 const FloatRect& rect,
1293 const FloatRoundedRect& roundedHoleRect, 1293 const FloatRoundedRect& roundedHoleRect,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 break; 1347 break;
1348 default: 1348 default:
1349 NOTREACHED(); 1349 NOTREACHED();
1350 break; 1350 break;
1351 } 1351 }
1352 1352
1353 return nullptr; 1353 return nullptr;
1354 } 1354 }
1355 1355
1356 } // namespace blink 1356 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698