OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "modules/canvas2d/CanvasRenderingContext2DState.h" | 5 #include "modules/canvas2d/CanvasRenderingContext2DState.h" |
6 | 6 |
7 #include "core/css/CSSFontSelector.h" | 7 #include "core/css/CSSFontSelector.h" |
8 #include "core/css/resolver/FilterOperationResolver.h" | 8 #include "core/css/resolver/FilterOperationResolver.h" |
9 #include "core/css/resolver/StyleBuilder.h" | 9 #include "core/css/resolver/StyleBuilder.h" |
10 #include "core/css/resolver/StyleResolverState.h" | 10 #include "core/css/resolver/StyleResolverState.h" |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 const AffineTransform& transform) { | 265 const AffineTransform& transform) { |
266 m_isTransformInvertible = transform.isInvertible(); | 266 m_isTransformInvertible = transform.isInvertible(); |
267 m_transform = transform; | 267 m_transform = transform; |
268 } | 268 } |
269 | 269 |
270 void CanvasRenderingContext2DState::resetTransform() { | 270 void CanvasRenderingContext2DState::resetTransform() { |
271 m_transform.makeIdentity(); | 271 m_transform.makeIdentity(); |
272 m_isTransformInvertible = true; | 272 m_isTransformInvertible = true; |
273 } | 273 } |
274 | 274 |
275 sk_sp<SkImageFilter> CanvasRenderingContext2DState::getFilterForOffscreenCanvas( | |
276 IntSize canvasSize) const { | |
277 if (!m_filterValue) | |
278 return nullptr; | |
279 | |
280 if (m_resolvedFilter) | |
281 return m_resolvedFilter; | |
282 | |
283 FilterOperations operations = | |
284 FilterOperationResolver::createOffscreenFilterOperations(*m_filterValue); | |
285 | |
286 // We can't reuse m_fillPaint and m_strokePaint for the filter, since these | |
287 // incorporate the global alpha, which isn't applicable here. | |
288 SkPaint fillPaintForFilter; | |
289 m_fillStyle->applyToPaint(fillPaintForFilter); | |
290 fillPaintForFilter.setColor(m_fillStyle->paintColor()); | |
291 SkPaint strokePaintForFilter; | |
292 m_strokeStyle->applyToPaint(strokePaintForFilter); | |
293 strokePaintForFilter.setColor(m_strokeStyle->paintColor()); | |
294 | |
295 FilterEffectBuilder filterEffectBuilder( | |
296 FloatRect((FloatPoint()), FloatSize(canvasSize)), | |
297 1.0f, // Deliberately ignore zoom on the canvas element. | |
298 &fillPaintForFilter, &strokePaintForFilter); | |
299 | |
300 FilterEffect* lastEffect = filterEffectBuilder.buildFilterEffect(operations); | |
301 if (lastEffect) { | |
302 m_resolvedFilter = | |
303 SkiaImageFilterBuilder::build(lastEffect, ColorSpaceDeviceRGB); | |
304 } | |
305 | |
306 return m_resolvedFilter; | |
307 } | |
308 | |
275 sk_sp<SkImageFilter> CanvasRenderingContext2DState::getFilter( | 309 sk_sp<SkImageFilter> CanvasRenderingContext2DState::getFilter( |
276 Element* styleResolutionHost, | 310 Element* styleResolutionHost, |
277 IntSize canvasSize, | 311 IntSize canvasSize, |
278 CanvasRenderingContext2D* context) const { | 312 CanvasRenderingContext2D* context) const { |
279 if (!m_filterValue) | 313 if (!m_filterValue) |
280 return nullptr; | 314 return nullptr; |
281 | 315 |
282 // StyleResolverState cannot be used in frame-less documents. | 316 // StyleResolverState cannot be used in frame-less documents. |
283 if (!styleResolutionHost->document().frame()) | 317 if (!styleResolutionHost->document().frame()) |
284 return nullptr; | 318 return nullptr; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
318 context->updateFilterReferences(filterStyle->filter()); | 352 context->updateFilterReferences(filterStyle->filter()); |
319 if (lastEffect->originTainted()) | 353 if (lastEffect->originTainted()) |
320 context->setOriginTainted(); | 354 context->setOriginTainted(); |
321 } | 355 } |
322 } | 356 } |
323 } | 357 } |
324 | 358 |
325 return m_resolvedFilter; | 359 return m_resolvedFilter; |
326 } | 360 } |
327 | 361 |
362 bool CanvasRenderingContext2DState::hasFilterForOffscreenCanvas( | |
363 IntSize canvasSize) const { | |
364 // Checking for a non-null m_filterValue isn't sufficient, since this value | |
Justin Novosad
2017/01/17 21:59:47
Good point. Do we have a test that covers this?
fserb
2017/01/17 22:10:42
it's just a small detail. It usually will happen w
| |
365 // might refer to a non-existent filter. | |
366 return !!getFilterForOffscreenCanvas(canvasSize); | |
367 } | |
368 | |
328 bool CanvasRenderingContext2DState::hasFilter( | 369 bool CanvasRenderingContext2DState::hasFilter( |
329 Element* styleResolutionHost, | 370 Element* styleResolutionHost, |
330 IntSize canvasSize, | 371 IntSize canvasSize, |
331 CanvasRenderingContext2D* context) const { | 372 CanvasRenderingContext2D* context) const { |
332 // Checking for a non-null m_filterValue isn't sufficient, since this value | 373 // Checking for a non-null m_filterValue isn't sufficient, since this value |
333 // might refer to a non-existent filter. | 374 // might refer to a non-existent filter. |
334 return !!getFilter(styleResolutionHost, canvasSize, context); | 375 return !!getFilter(styleResolutionHost, canvasSize, context); |
335 } | 376 } |
336 | 377 |
337 void CanvasRenderingContext2DState::clearResolvedFilter() const { | 378 void CanvasRenderingContext2DState::clearResolvedFilter() const { |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
545 paint->setLooper(0); | 586 paint->setLooper(0); |
546 paint->setImageFilter(shadowAndForegroundImageFilter()); | 587 paint->setImageFilter(shadowAndForegroundImageFilter()); |
547 return paint; | 588 return paint; |
548 } | 589 } |
549 paint->setLooper(sk_ref_sp(shadowAndForegroundDrawLooper())); | 590 paint->setLooper(sk_ref_sp(shadowAndForegroundDrawLooper())); |
550 paint->setImageFilter(0); | 591 paint->setImageFilter(0); |
551 return paint; | 592 return paint; |
552 } | 593 } |
553 | 594 |
554 } // namespace blink | 595 } // namespace blink |
OLD | NEW |