Chromium Code Reviews| 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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 m_isTransformInvertible = true; | 272 m_isTransformInvertible = true; |
| 273 } | 273 } |
| 274 | 274 |
| 275 static void updateFilterReferences(HTMLCanvasElement* canvasElement, | 275 static void updateFilterReferences(HTMLCanvasElement* canvasElement, |
| 276 CanvasRenderingContext2D* context, | 276 CanvasRenderingContext2D* context, |
| 277 const FilterOperations& filters) { | 277 const FilterOperations& filters) { |
| 278 context->clearFilterReferences(); | 278 context->clearFilterReferences(); |
| 279 context->addFilterReferences(filters, canvasElement->document()); | 279 context->addFilterReferences(filters, canvasElement->document()); |
| 280 } | 280 } |
| 281 | 281 |
| 282 SkImageFilter* CanvasRenderingContext2DState::getFilterWithoutDocument( | |
| 283 IntSize canvasSize) const { | |
| 284 if (!m_filterValue) | |
| 285 return nullptr; | |
| 286 | |
| 287 if (m_resolvedFilter) | |
| 288 return m_resolvedFilter.get(); | |
| 289 | |
| 290 FilterOperations op = | |
| 291 FilterOperationResolver::createFilterOperations(nullptr, *m_filterValue); | |
|
meade_UTC10
2016/10/26 06:57:34
Nit: don't abbreviate variable names.
fserb
2016/10/26 19:08:26
done
| |
| 292 | |
| 293 // We can't reuse m_fillPaint and m_strokePaint for the filter, since these | |
| 294 // incorporate the global alpha, which isn't applicable here. | |
| 295 SkPaint fillPaintForFilter; | |
| 296 m_fillStyle->applyToPaint(fillPaintForFilter); | |
| 297 fillPaintForFilter.setColor(m_fillStyle->paintColor()); | |
| 298 SkPaint strokePaintForFilter; | |
| 299 m_strokeStyle->applyToPaint(strokePaintForFilter); | |
| 300 strokePaintForFilter.setColor(m_strokeStyle->paintColor()); | |
| 301 | |
| 302 FilterEffectBuilder filterEffectBuilder( | |
| 303 nullptr, FloatRect((FloatPoint()), FloatSize(canvasSize)), | |
|
Justin Novosad
2016/10/24 18:51:22
This nullptr lacks readability. Please use a temp
fserb
2016/10/26 19:08:26
done
| |
| 304 1.0f, // Deliberately ignore zoom on the canvas element. | |
| 305 &fillPaintForFilter, &strokePaintForFilter); | |
|
meade_UTC10
2016/10/26 06:57:34
It looks like these get stored in the FilterEffect
fserb
2016/10/26 19:08:26
yep. They are used the same way on getFilter(). Th
| |
| 306 | |
| 307 if (FilterEffect* lastEffect = filterEffectBuilder.buildFilterEffect(op)) { | |
| 308 m_resolvedFilter = | |
| 309 SkiaImageFilterBuilder::build(lastEffect, ColorSpaceDeviceRGB); | |
| 310 } | |
| 311 | |
| 312 return m_resolvedFilter.get(); | |
| 313 } | |
| 314 | |
| 282 SkImageFilter* CanvasRenderingContext2DState::getFilter( | 315 SkImageFilter* CanvasRenderingContext2DState::getFilter( |
| 283 Element* styleResolutionHost, | 316 Element* styleResolutionHost, |
| 284 IntSize canvasSize, | 317 IntSize canvasSize, |
| 285 CanvasRenderingContext2D* context) const { | 318 CanvasRenderingContext2D* context) const { |
| 286 if (!m_filterValue) | 319 if (!m_filterValue) |
| 287 return nullptr; | 320 return nullptr; |
| 288 | 321 |
| 289 // StyleResolverState cannot be used in frame-less documents. | 322 // StyleResolverState cannot be used in frame-less documents. |
| 290 if (!styleResolutionHost->document().frame()) | 323 if (!styleResolutionHost->document().frame()) |
| 291 return nullptr; | 324 return nullptr; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 context, filterStyle->filter()); | 359 context, filterStyle->filter()); |
| 327 if (lastEffect->originTainted()) | 360 if (lastEffect->originTainted()) |
| 328 context->setOriginTainted(); | 361 context->setOriginTainted(); |
| 329 } | 362 } |
| 330 } | 363 } |
| 331 } | 364 } |
| 332 | 365 |
| 333 return m_resolvedFilter.get(); | 366 return m_resolvedFilter.get(); |
| 334 } | 367 } |
| 335 | 368 |
| 369 bool CanvasRenderingContext2DState::hasFilterWithoutDocument( | |
| 370 IntSize canvasSize) const { | |
| 371 // Checking for a non-null m_filterValue isn't sufficient, since this value | |
| 372 // might refer to a non-existent filter. | |
| 373 return !!getFilterWithoutDocument(canvasSize); | |
| 374 } | |
| 375 | |
| 336 bool CanvasRenderingContext2DState::hasFilter( | 376 bool CanvasRenderingContext2DState::hasFilter( |
| 337 Element* styleResolutionHost, | 377 Element* styleResolutionHost, |
| 338 IntSize canvasSize, | 378 IntSize canvasSize, |
| 339 CanvasRenderingContext2D* context) const { | 379 CanvasRenderingContext2D* context) const { |
| 340 // Checking for a non-null m_filterValue isn't sufficient, since this value | 380 // Checking for a non-null m_filterValue isn't sufficient, since this value |
| 341 // might refer to a non-existent filter. | 381 // might refer to a non-existent filter. |
| 342 return !!getFilter(styleResolutionHost, canvasSize, context); | 382 return !!getFilter(styleResolutionHost, canvasSize, context); |
| 343 } | 383 } |
| 344 | 384 |
| 345 void CanvasRenderingContext2DState::clearResolvedFilter() const { | 385 void CanvasRenderingContext2DState::clearResolvedFilter() const { |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 556 paint->setLooper(0); | 596 paint->setLooper(0); |
| 557 paint->setImageFilter(shadowAndForegroundImageFilter()); | 597 paint->setImageFilter(shadowAndForegroundImageFilter()); |
| 558 return paint; | 598 return paint; |
| 559 } | 599 } |
| 560 paint->setLooper(sk_ref_sp(shadowAndForegroundDrawLooper())); | 600 paint->setLooper(sk_ref_sp(shadowAndForegroundDrawLooper())); |
| 561 paint->setImageFilter(0); | 601 paint->setImageFilter(0); |
| 562 return paint; | 602 return paint; |
| 563 } | 603 } |
| 564 | 604 |
| 565 } // namespace blink | 605 } // namespace blink |
| OLD | NEW |