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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 context->updateFilterReferences(filterStyle->filter()); | 356 context->updateFilterReferences(filterStyle->filter()); |
323 if (lastEffect->originTainted()) | 357 if (lastEffect->originTainted()) |
324 context->setOriginTainted(); | 358 context->setOriginTainted(); |
325 } | 359 } |
326 } | 360 } |
327 } | 361 } |
328 | 362 |
329 return m_resolvedFilter; | 363 return m_resolvedFilter; |
330 } | 364 } |
331 | 365 |
| 366 bool CanvasRenderingContext2DState::hasFilterForOffscreenCanvas( |
| 367 IntSize canvasSize) const { |
| 368 // Checking for a non-null m_filterValue isn't sufficient, since this value |
| 369 // might refer to a non-existent filter. |
| 370 return !!getFilterForOffscreenCanvas(canvasSize); |
| 371 } |
| 372 |
332 bool CanvasRenderingContext2DState::hasFilter( | 373 bool CanvasRenderingContext2DState::hasFilter( |
333 Element* styleResolutionHost, | 374 Element* styleResolutionHost, |
334 IntSize canvasSize, | 375 IntSize canvasSize, |
335 CanvasRenderingContext2D* context) const { | 376 CanvasRenderingContext2D* context) const { |
336 // Checking for a non-null m_filterValue isn't sufficient, since this value | 377 // Checking for a non-null m_filterValue isn't sufficient, since this value |
337 // might refer to a non-existent filter. | 378 // might refer to a non-existent filter. |
338 return !!getFilter(styleResolutionHost, canvasSize, context); | 379 return !!getFilter(styleResolutionHost, canvasSize, context); |
339 } | 380 } |
340 | 381 |
341 void CanvasRenderingContext2DState::clearResolvedFilter() const { | 382 void CanvasRenderingContext2DState::clearResolvedFilter() const { |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 paint->setLooper(0); | 590 paint->setLooper(0); |
550 paint->setImageFilter(shadowAndForegroundImageFilter()); | 591 paint->setImageFilter(shadowAndForegroundImageFilter()); |
551 return paint; | 592 return paint; |
552 } | 593 } |
553 paint->setLooper(sk_ref_sp(shadowAndForegroundDrawLooper())); | 594 paint->setLooper(sk_ref_sp(shadowAndForegroundDrawLooper())); |
554 paint->setImageFilter(0); | 595 paint->setImageFilter(0); |
555 return paint; | 596 return paint; |
556 } | 597 } |
557 | 598 |
558 } // namespace blink | 599 } // namespace blink |
OLD | NEW |