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::createFilterOperations(nullptr, *m_filterValue); | |
esprehn
2016/11/22 01:38:37
createOffscreen(...)
it's more clear than passing
fserb
2017/01/17 17:58:44
done.
| |
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 nullptr, // styleResolutionHost | |
esprehn
2016/11/22 01:38:37
Probably want two constructors instead, add one th
fserb
2017/01/17 17:58:44
done.
| |
297 FloatRect((FloatPoint()), FloatSize(canvasSize)), | |
298 1.0f, // Deliberately ignore zoom on the canvas element. | |
299 &fillPaintForFilter, &strokePaintForFilter); | |
300 | |
301 FilterEffect* lastEffect = filterEffectBuilder.buildFilterEffect(operations); | |
302 if (lastEffect) { | |
303 m_resolvedFilter = | |
304 SkiaImageFilterBuilder::build(lastEffect, ColorSpaceDeviceRGB); | |
305 } | |
306 | |
307 return m_resolvedFilter; | |
308 } | |
309 | |
275 sk_sp<SkImageFilter> CanvasRenderingContext2DState::getFilter( | 310 sk_sp<SkImageFilter> CanvasRenderingContext2DState::getFilter( |
276 Element* styleResolutionHost, | 311 Element* styleResolutionHost, |
277 IntSize canvasSize, | 312 IntSize canvasSize, |
278 CanvasRenderingContext2D* context) const { | 313 CanvasRenderingContext2D* context) const { |
279 if (!m_filterValue) | 314 if (!m_filterValue) |
280 return nullptr; | 315 return nullptr; |
281 | 316 |
282 // StyleResolverState cannot be used in frame-less documents. | 317 // StyleResolverState cannot be used in frame-less documents. |
283 if (!styleResolutionHost->document().frame()) | 318 if (!styleResolutionHost->document().frame()) |
284 return nullptr; | 319 return nullptr; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
318 context->updateFilterReferences(filterStyle->filter()); | 353 context->updateFilterReferences(filterStyle->filter()); |
319 if (lastEffect->originTainted()) | 354 if (lastEffect->originTainted()) |
320 context->setOriginTainted(); | 355 context->setOriginTainted(); |
321 } | 356 } |
322 } | 357 } |
323 } | 358 } |
324 | 359 |
325 return m_resolvedFilter; | 360 return m_resolvedFilter; |
326 } | 361 } |
327 | 362 |
363 bool CanvasRenderingContext2DState::hasFilterForOffscreenCanvas( | |
364 IntSize canvasSize) const { | |
365 // Checking for a non-null m_filterValue isn't sufficient, since this value | |
366 // might refer to a non-existent filter. | |
367 return !!getFilterForOffscreenCanvas(canvasSize); | |
368 } | |
369 | |
328 bool CanvasRenderingContext2DState::hasFilter( | 370 bool CanvasRenderingContext2DState::hasFilter( |
329 Element* styleResolutionHost, | 371 Element* styleResolutionHost, |
330 IntSize canvasSize, | 372 IntSize canvasSize, |
331 CanvasRenderingContext2D* context) const { | 373 CanvasRenderingContext2D* context) const { |
332 // Checking for a non-null m_filterValue isn't sufficient, since this value | 374 // Checking for a non-null m_filterValue isn't sufficient, since this value |
333 // might refer to a non-existent filter. | 375 // might refer to a non-existent filter. |
334 return !!getFilter(styleResolutionHost, canvasSize, context); | 376 return !!getFilter(styleResolutionHost, canvasSize, context); |
335 } | 377 } |
336 | 378 |
337 void CanvasRenderingContext2DState::clearResolvedFilter() const { | 379 void CanvasRenderingContext2DState::clearResolvedFilter() const { |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
549 paint->setLooper(0); | 591 paint->setLooper(0); |
550 paint->setImageFilter(shadowAndForegroundImageFilter()); | 592 paint->setImageFilter(shadowAndForegroundImageFilter()); |
551 return paint; | 593 return paint; |
552 } | 594 } |
553 paint->setLooper(sk_ref_sp(shadowAndForegroundDrawLooper())); | 595 paint->setLooper(sk_ref_sp(shadowAndForegroundDrawLooper())); |
554 paint->setImageFilter(0); | 596 paint->setImageFilter(0); |
555 return paint; | 597 return paint; |
556 } | 598 } |
557 | 599 |
558 } // namespace blink | 600 } // namespace blink |
OLD | NEW |