Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(343)

Side by Side Diff: third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DState.cpp

Issue 2326633002: Adds filter support for offscreen canvas (Closed)
Patch Set: Working version of filters on offscreen canvas Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 context->clearFilterReferences(); 288 context->clearFilterReferences();
289 context->addFilterReferences(filters, canvasElement->document()); 289 context->addFilterReferences(filters, canvasElement->document());
290 } 290 }
291 291
292 SkImageFilter* CanvasRenderingContext2DState::getFilter(Element* styleResolution Host, IntSize canvasSize, CanvasRenderingContext2D* context) const 292 SkImageFilter* CanvasRenderingContext2DState::getFilter(Element* styleResolution Host, IntSize canvasSize, CanvasRenderingContext2D* context) const
293 { 293 {
294 if (!m_filterValue) 294 if (!m_filterValue)
295 return nullptr; 295 return nullptr;
296 296
297 // StyleResolverState cannot be used in frame-less documents. 297 // StyleResolverState cannot be used in frame-less documents.
298 if (!styleResolutionHost->document().frame()) 298 if (styleResolutionHost && !styleResolutionHost->document().frame())
299 return nullptr; 299 return nullptr;
300 300
301 if (!m_resolvedFilter) { 301 if (!m_resolvedFilter) {
302 RefPtr<ComputedStyle> filterStyle = ComputedStyle::create(); 302 RefPtr<ComputedStyle> filterStyle = ComputedStyle::create();
303 // Must set font in case the filter uses any font-relative units (em, ex ) 303 // Must set font in case the filter uses any font-relative units (em, ex )
304 filterStyle->setFont(m_fontForFilter); 304 filterStyle->setFont(m_fontForFilter);
305 305
306 StyleResolverState resolverState(styleResolutionHost->document(), styleR esolutionHost, filterStyle.get()); 306 if (styleResolutionHost) {
307 resolverState.setStyle(filterStyle); 307 StyleResolverState resolverState(styleResolutionHost->document(), st yleResolutionHost, filterStyle.get());
308 resolverState.setStyle(filterStyle);
308 309
309 StyleBuilder::applyProperty(CSSPropertyFilter, resolverState, *m_filterV alue); 310 StyleBuilder::applyProperty(CSSPropertyFilter, resolverState, *m_fil terValue);
310 resolverState.loadPendingResources(); 311 resolverState.loadPendingResources();
312 } else {
313 StyleResolverState resolverState(filterStyle.get());
314 resolverState.setStyle(filterStyle);
315
316 StyleBuilder::applyProperty(CSSPropertyFilter, resolverState, *m_fil terValue);
317 resolverState.loadPendingResources();
318 }
319
320
311 FilterEffectBuilder* filterEffectBuilder = FilterEffectBuilder::create() ; 321 FilterEffectBuilder* filterEffectBuilder = FilterEffectBuilder::create() ;
312 322
313 // We can't reuse m_fillPaint and m_strokePaint for the filter, since th ese incorporate 323 // We can't reuse m_fillPaint and m_strokePaint for the filter, since th ese incorporate
314 // the global alpha, which isn't applicable here. 324 // the global alpha, which isn't applicable here.
315 SkPaint fillPaintForFilter; 325 SkPaint fillPaintForFilter;
316 SkPaint strokePaintForFilter; 326 SkPaint strokePaintForFilter;
317 m_fillStyle->applyToPaint(fillPaintForFilter); 327 m_fillStyle->applyToPaint(fillPaintForFilter);
318 m_strokeStyle->applyToPaint(strokePaintForFilter); 328 m_strokeStyle->applyToPaint(strokePaintForFilter);
319 fillPaintForFilter.setColor(m_fillStyle->paintColor()); 329 fillPaintForFilter.setColor(m_fillStyle->paintColor());
320 strokePaintForFilter.setColor(m_strokeStyle->paintColor()); 330 strokePaintForFilter.setColor(m_strokeStyle->paintColor());
321 FloatSize floatCanvasSize(canvasSize); 331 FloatSize floatCanvasSize(canvasSize);
322 const double effectiveZoom = 1.0; // Deliberately ignore zoom on the can vas element 332 const double effectiveZoom = 1.0; // Deliberately ignore zoom on the can vas element
323 filterEffectBuilder->build(styleResolutionHost, filterStyle->filter(), e ffectiveZoom, &floatCanvasSize, &fillPaintForFilter, &strokePaintForFilter); 333 filterEffectBuilder->build(styleResolutionHost, filterStyle->filter(), e ffectiveZoom, &floatCanvasSize, &fillPaintForFilter, &strokePaintForFilter);
324 334
325 if (FilterEffect* lastEffect = filterEffectBuilder->lastEffect()) { 335 if (FilterEffect* lastEffect = filterEffectBuilder->lastEffect()) {
326 lastEffect->determineMaximumEffectRect(DetermineMaxEffectRectNone); 336 lastEffect->determineMaximumEffectRect(DetermineMaxEffectRectNone);
327 m_resolvedFilter = SkiaImageFilterBuilder::build(lastEffect, ColorSp aceDeviceRGB); 337 m_resolvedFilter = SkiaImageFilterBuilder::build(lastEffect, ColorSp aceDeviceRGB);
328 if (m_resolvedFilter) { 338 if (styleResolutionHost && m_resolvedFilter) {
329 updateFilterReferences(toHTMLCanvasElement(styleResolutionHost), context, filterStyle->filter()); 339 updateFilterReferences(toHTMLCanvasElement(styleResolutionHost), context, filterStyle->filter());
330 if (lastEffect->originTainted()) 340 if (lastEffect->originTainted())
331 context->setOriginTainted(); 341 context->setOriginTainted();
332 } 342 }
333 } 343 }
334 } 344 }
335 345
336 return m_resolvedFilter.get(); 346 return m_resolvedFilter.get();
337 } 347 }
338 348
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 paint->setLooper(0); 571 paint->setLooper(0);
562 paint->setImageFilter(shadowAndForegroundImageFilter()); 572 paint->setImageFilter(shadowAndForegroundImageFilter());
563 return paint; 573 return paint;
564 } 574 }
565 paint->setLooper(sk_ref_sp(shadowAndForegroundDrawLooper())); 575 paint->setLooper(sk_ref_sp(shadowAndForegroundDrawLooper()));
566 paint->setImageFilter(0); 576 paint->setImageFilter(0);
567 return paint; 577 return paint;
568 } 578 }
569 579
570 } // namespace blink 580 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698