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 static void updateFilterReferences(HTMLCanvasElement* canvasElement, |
| 276 CanvasRenderingContext2D* context, |
| 277 const FilterOperations& filters) { |
| 278 context->clearFilterReferences(); |
| 279 context->addFilterReferences(filters, canvasElement->document()); |
| 280 } |
| 281 |
275 sk_sp<SkImageFilter> CanvasRenderingContext2DState::getFilter( | 282 sk_sp<SkImageFilter> CanvasRenderingContext2DState::getFilter( |
276 Element* styleResolutionHost, | 283 Element* styleResolutionHost, |
277 IntSize canvasSize, | 284 IntSize canvasSize, |
278 CanvasRenderingContext2D* context) const { | 285 CanvasRenderingContext2D* context) const { |
279 if (!m_filterValue) | 286 if (!m_filterValue) |
280 return nullptr; | 287 return nullptr; |
281 | 288 |
282 // StyleResolverState cannot be used in frame-less documents. | 289 // StyleResolverState cannot be used in frame-less documents. |
283 if (!styleResolutionHost->document().frame()) | 290 if (!styleResolutionHost->document().frame()) |
284 return nullptr; | 291 return nullptr; |
(...skipping 23 matching lines...) Expand all Loading... |
308 FilterEffectBuilder filterEffectBuilder( | 315 FilterEffectBuilder filterEffectBuilder( |
309 styleResolutionHost, FloatRect((FloatPoint()), FloatSize(canvasSize)), | 316 styleResolutionHost, FloatRect((FloatPoint()), FloatSize(canvasSize)), |
310 1.0f, // Deliberately ignore zoom on the canvas element. | 317 1.0f, // Deliberately ignore zoom on the canvas element. |
311 &fillPaintForFilter, &strokePaintForFilter); | 318 &fillPaintForFilter, &strokePaintForFilter); |
312 | 319 |
313 if (FilterEffect* lastEffect = | 320 if (FilterEffect* lastEffect = |
314 filterEffectBuilder.buildFilterEffect(filterStyle->filter())) { | 321 filterEffectBuilder.buildFilterEffect(filterStyle->filter())) { |
315 m_resolvedFilter = | 322 m_resolvedFilter = |
316 SkiaImageFilterBuilder::build(lastEffect, ColorSpaceDeviceRGB); | 323 SkiaImageFilterBuilder::build(lastEffect, ColorSpaceDeviceRGB); |
317 if (m_resolvedFilter) { | 324 if (m_resolvedFilter) { |
318 context->updateFilterReferences(filterStyle->filter()); | 325 updateFilterReferences(toHTMLCanvasElement(styleResolutionHost), |
| 326 context, filterStyle->filter()); |
319 if (lastEffect->originTainted()) | 327 if (lastEffect->originTainted()) |
320 context->setOriginTainted(); | 328 context->setOriginTainted(); |
321 } | 329 } |
322 } | 330 } |
323 } | 331 } |
324 | 332 |
325 return m_resolvedFilter; | 333 return m_resolvedFilter; |
326 } | 334 } |
327 | 335 |
328 bool CanvasRenderingContext2DState::hasFilter( | 336 bool CanvasRenderingContext2DState::hasFilter( |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 paint->setLooper(0); | 557 paint->setLooper(0); |
550 paint->setImageFilter(shadowAndForegroundImageFilter()); | 558 paint->setImageFilter(shadowAndForegroundImageFilter()); |
551 return paint; | 559 return paint; |
552 } | 560 } |
553 paint->setLooper(sk_ref_sp(shadowAndForegroundDrawLooper())); | 561 paint->setLooper(sk_ref_sp(shadowAndForegroundDrawLooper())); |
554 paint->setImageFilter(0); | 562 paint->setImageFilter(0); |
555 return paint; | 563 return paint; |
556 } | 564 } |
557 | 565 |
558 } // namespace blink | 566 } // namespace blink |
OLD | NEW |