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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 { | 70 { |
71 if (metaData) | 71 if (metaData) |
72 m_metaData = *metaData; | 72 m_metaData = *metaData; |
73 | 73 |
74 // FIXME: Do some tests to determine how many states are typically used, and allocate | 74 // FIXME: Do some tests to determine how many states are typically used, and allocate |
75 // several here. | 75 // several here. |
76 m_paintStateStack.append(GraphicsContextState::create()); | 76 m_paintStateStack.append(GraphicsContextState::create()); |
77 m_paintState = m_paintStateStack.last().get(); | 77 m_paintState = m_paintStateStack.last().get(); |
78 | 78 |
79 if (contextDisabled()) { | 79 if (contextDisabled()) { |
80 DEFINE_STATIC_REF(SkCanvas, nullCanvas, (adoptRef(SkCreateNullCanvas())) ); | 80 DEFINE_STATIC_LOCAL(SkCanvas*, nullCanvas, (SkCreateNullCanvas())); |
81 m_canvas = nullCanvas; | 81 m_canvas = nullCanvas; |
82 } | 82 } |
83 } | 83 } |
84 | 84 |
85 GraphicsContext::~GraphicsContext() | 85 GraphicsContext::~GraphicsContext() |
86 { | 86 { |
87 #if DCHECK_IS_ON() | 87 #if DCHECK_IS_ON() |
88 if (!m_disableDestructionChecks) { | 88 if (!m_disableDestructionChecks) { |
89 ASSERT(!m_paintStateIndex); | 89 ASSERT(!m_paintStateIndex); |
90 ASSERT(!m_paintState->saveCount()); | 90 ASSERT(!m_paintState->saveCount()); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 } | 229 } |
230 | 230 |
231 void GraphicsContext::beginLayer(float opacity, SkXfermode::Mode xfermode, const FloatRect* bounds, ColorFilter colorFilter, sk_sp<SkImageFilter> imageFilter) | 231 void GraphicsContext::beginLayer(float opacity, SkXfermode::Mode xfermode, const FloatRect* bounds, ColorFilter colorFilter, sk_sp<SkImageFilter> imageFilter) |
232 { | 232 { |
233 if (contextDisabled()) | 233 if (contextDisabled()) |
234 return; | 234 return; |
235 | 235 |
236 SkPaint layerPaint; | 236 SkPaint layerPaint; |
237 layerPaint.setAlpha(static_cast<unsigned char>(opacity * 255)); | 237 layerPaint.setAlpha(static_cast<unsigned char>(opacity * 255)); |
238 layerPaint.setXfermodeMode(xfermode); | 238 layerPaint.setXfermodeMode(xfermode); |
239 layerPaint.setColorFilter(toSkSp(WebCoreColorFilterToSkiaColorFilter(colorFi lter))); | 239 layerPaint.setColorFilter(WebCoreColorFilterToSkiaColorFilter(colorFilter)); |
240 layerPaint.setImageFilter(std::move(imageFilter)); | 240 layerPaint.setImageFilter(std::move(imageFilter)); |
241 | 241 |
242 if (bounds) { | 242 if (bounds) { |
243 SkRect skBounds = *bounds; | 243 SkRect skBounds = *bounds; |
244 saveLayer(&skBounds, &layerPaint); | 244 saveLayer(&skBounds, &layerPaint); |
245 } else { | 245 } else { |
246 saveLayer(nullptr, &layerPaint); | 246 saveLayer(nullptr, &layerPaint); |
247 } | 247 } |
248 | 248 |
249 #if DCHECK_IS_ON() | 249 #if DCHECK_IS_ON() |
(...skipping 16 matching lines...) Expand all Loading... | |
266 if (contextDisabled()) | 266 if (contextDisabled()) |
267 return; | 267 return; |
268 | 268 |
269 m_canvas = m_pictureRecorder.beginRecording(bounds, nullptr); | 269 m_canvas = m_pictureRecorder.beginRecording(bounds, nullptr); |
270 if (m_hasMetaData) | 270 if (m_hasMetaData) |
271 skia::GetMetaData(*m_canvas) = m_metaData; | 271 skia::GetMetaData(*m_canvas) = m_metaData; |
272 } | 272 } |
273 | 273 |
274 namespace { | 274 namespace { |
275 | 275 |
276 PassRefPtr<SkPicture> createEmptyPicture() | 276 sk_sp<SkPicture> createEmptyPicture() |
277 { | 277 { |
278 SkPictureRecorder recorder; | 278 SkPictureRecorder recorder; |
279 recorder.beginRecording(SkRect::MakeEmpty(), nullptr); | 279 recorder.beginRecording(SkRect::MakeEmpty(), nullptr); |
280 return fromSkSp(recorder.finishRecordingAsPicture()); | 280 return recorder.finishRecordingAsPicture(); |
281 } | 281 } |
282 | 282 |
283 } // anonymous namespace | 283 } // anonymous namespace |
284 | 284 |
285 PassRefPtr<SkPicture> GraphicsContext::endRecording() | 285 sk_sp<SkPicture> GraphicsContext::endRecording() |
286 { | 286 { |
287 if (contextDisabled()) { | 287 if (contextDisabled()) { |
288 // Clients expect endRecording() to always return a non-null picture. | 288 // Clients expect endRecording() to always return a non-null picture. |
289 // Cache an empty SKP to minimize overhead when disabled. | 289 // Cache an empty SKP to minimize overhead when disabled. |
290 DEFINE_STATIC_REF(SkPicture, emptyPicture, createEmptyPicture()); | 290 DEFINE_STATIC_LOCAL(sk_sp<SkPicture>, emptyPicture, (createEmptyPicture( ))); |
291 return emptyPicture; | 291 return emptyPicture; |
292 } | 292 } |
293 | 293 |
294 RefPtr<SkPicture> picture = fromSkSp(m_pictureRecorder.finishRecordingAsPict ure()); | 294 sk_sp<SkPicture> picture = m_pictureRecorder.finishRecordingAsPicture(); |
295 m_canvas = nullptr; | 295 m_canvas = nullptr; |
296 ASSERT(picture); | 296 ASSERT(picture); |
297 return picture.release(); | 297 return picture; |
298 } | 298 } |
299 | 299 |
300 void GraphicsContext::drawPicture(const SkPicture* picture) | 300 void GraphicsContext::drawPicture(const SkPicture* picture) |
301 { | 301 { |
302 if (contextDisabled() || !picture || picture->cullRect().isEmpty()) | 302 if (contextDisabled() || !picture || picture->cullRect().isEmpty()) |
303 return; | 303 return; |
304 | 304 |
305 ASSERT(m_canvas); | 305 ASSERT(m_canvas); |
306 m_canvas->drawPicture(picture); | 306 m_canvas->drawPicture(picture); |
307 } | 307 } |
308 | 308 |
309 void GraphicsContext::compositePicture(PassRefPtr<SkPicture> picture, const Floa tRect& dest, const FloatRect& src, SkXfermode::Mode op) | 309 void GraphicsContext::compositePicture(sk_sp<SkPicture> picture, const FloatRect & dest, const FloatRect& src, SkXfermode::Mode op) |
310 { | 310 { |
311 if (contextDisabled() || !picture) | 311 if (contextDisabled() || !picture) |
312 return; | 312 return; |
313 ASSERT(m_canvas); | 313 ASSERT(m_canvas); |
314 | 314 |
315 SkPaint picturePaint; | 315 SkPaint picturePaint; |
316 picturePaint.setXfermodeMode(op); | 316 picturePaint.setXfermodeMode(op); |
317 m_canvas->save(); | 317 m_canvas->save(); |
318 SkRect sourceBounds = src; | 318 SkRect sourceBounds = src; |
319 SkRect skBounds = dest; | 319 SkRect skBounds = dest; |
320 SkMatrix pictureTransform; | 320 SkMatrix pictureTransform; |
321 pictureTransform.setRectToRect(sourceBounds, skBounds, SkMatrix::kFill_Scale ToFit); | 321 pictureTransform.setRectToRect(sourceBounds, skBounds, SkMatrix::kFill_Scale ToFit); |
322 m_canvas->concat(pictureTransform); | 322 m_canvas->concat(pictureTransform); |
323 picturePaint.setImageFilter(SkPictureImageFilter::MakeForLocalSpace(toSkSp(p icture), sourceBounds, static_cast<SkFilterQuality>(imageInterpolationQuality()) )); | 323 picturePaint.setImageFilter(SkPictureImageFilter::MakeForLocalSpace(picture, sourceBounds, static_cast<SkFilterQuality>(imageInterpolationQuality()))); |
f(malita)
2016/09/01 03:55:38
std::move(picture)
Łukasz Anforowicz
2016/09/01 20:50:58
Done.
| |
324 m_canvas->saveLayer(&sourceBounds, &picturePaint); | 324 m_canvas->saveLayer(&sourceBounds, &picturePaint); |
325 m_canvas->restore(); | 325 m_canvas->restore(); |
326 m_canvas->restore(); | 326 m_canvas->restore(); |
327 } | 327 } |
328 | 328 |
329 void GraphicsContext::drawFocusRingPath(const SkPath& path, const Color& color, int width) | 329 void GraphicsContext::drawFocusRingPath(const SkPath& path, const Color& color, int width) |
330 { | 330 { |
331 drawPlatformFocusRing(path, m_canvas, color.rgb(), width); | 331 drawPlatformFocusRing(path, m_canvas, color.rgb(), width); |
332 } | 332 } |
333 | 333 |
(...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1219 p1.setX(p1.x() + 0.5f); | 1219 p1.setX(p1.x() + 0.5f); |
1220 p2.setX(p2.x() + 0.5f); | 1220 p2.setX(p2.x() + 0.5f); |
1221 } else { | 1221 } else { |
1222 // We're a horizontal line. Adjust our y. | 1222 // We're a horizontal line. Adjust our y. |
1223 p1.setY(p1.y() + 0.5f); | 1223 p1.setY(p1.y() + 0.5f); |
1224 p2.setY(p2.y() + 0.5f); | 1224 p2.setY(p2.y() + 0.5f); |
1225 } | 1225 } |
1226 } | 1226 } |
1227 } | 1227 } |
1228 | 1228 |
1229 PassRefPtr<SkColorFilter> GraphicsContext::WebCoreColorFilterToSkiaColorFilter(C olorFilter colorFilter) | 1229 sk_sp<SkColorFilter> GraphicsContext::WebCoreColorFilterToSkiaColorFilter(ColorF ilter colorFilter) |
1230 { | 1230 { |
1231 switch (colorFilter) { | 1231 switch (colorFilter) { |
1232 case ColorFilterLuminanceToAlpha: | 1232 case ColorFilterLuminanceToAlpha: |
1233 return fromSkSp(SkLumaColorFilter::Make()); | 1233 return SkLumaColorFilter::Make(); |
1234 case ColorFilterLinearRGBToSRGB: | 1234 case ColorFilterLinearRGBToSRGB: |
1235 return ColorSpaceUtilities::createColorSpaceFilter(ColorSpaceLinearRGB, ColorSpaceDeviceRGB); | 1235 return ColorSpaceUtilities::createColorSpaceFilter(ColorSpaceLinearRGB, ColorSpaceDeviceRGB); |
1236 case ColorFilterSRGBToLinearRGB: | 1236 case ColorFilterSRGBToLinearRGB: |
1237 return ColorSpaceUtilities::createColorSpaceFilter(ColorSpaceDeviceRGB, ColorSpaceLinearRGB); | 1237 return ColorSpaceUtilities::createColorSpaceFilter(ColorSpaceDeviceRGB, ColorSpaceLinearRGB); |
1238 case ColorFilterNone: | 1238 case ColorFilterNone: |
1239 break; | 1239 break; |
1240 default: | 1240 default: |
1241 ASSERT_NOT_REACHED(); | 1241 ASSERT_NOT_REACHED(); |
1242 break; | 1242 break; |
1243 } | 1243 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1331 static const SkPMColor colors[] = { | 1331 static const SkPMColor colors[] = { |
1332 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red | 1332 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red |
1333 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray | 1333 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray |
1334 }; | 1334 }; |
1335 | 1335 |
1336 return colors[index]; | 1336 return colors[index]; |
1337 } | 1337 } |
1338 #endif | 1338 #endif |
1339 | 1339 |
1340 } // namespace blink | 1340 } // namespace blink |
OLD | NEW |