OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. |
3 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 #include "third_party/skia/include/core/SkColorFilter.h" | 44 #include "third_party/skia/include/core/SkColorFilter.h" |
45 #include "third_party/skia/include/core/SkData.h" | 45 #include "third_party/skia/include/core/SkData.h" |
46 #include "third_party/skia/include/core/SkDevice.h" | 46 #include "third_party/skia/include/core/SkDevice.h" |
47 #include "third_party/skia/include/core/SkPicture.h" | 47 #include "third_party/skia/include/core/SkPicture.h" |
48 #include "third_party/skia/include/core/SkPictureRecorder.h" | 48 #include "third_party/skia/include/core/SkPictureRecorder.h" |
49 #include "third_party/skia/include/core/SkRRect.h" | 49 #include "third_party/skia/include/core/SkRRect.h" |
50 #include "third_party/skia/include/core/SkRefCnt.h" | 50 #include "third_party/skia/include/core/SkRefCnt.h" |
51 #include "third_party/skia/include/core/SkSurface.h" | 51 #include "third_party/skia/include/core/SkSurface.h" |
52 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" | 52 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" |
53 #include "third_party/skia/include/effects/SkCornerPathEffect.h" | 53 #include "third_party/skia/include/effects/SkCornerPathEffect.h" |
54 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h" | |
54 #include "third_party/skia/include/effects/SkLumaColorFilter.h" | 55 #include "third_party/skia/include/effects/SkLumaColorFilter.h" |
55 #include "third_party/skia/include/effects/SkMatrixImageFilter.h" | 56 #include "third_party/skia/include/effects/SkMatrixImageFilter.h" |
56 #include "third_party/skia/include/effects/SkPictureImageFilter.h" | 57 #include "third_party/skia/include/effects/SkPictureImageFilter.h" |
57 #include "third_party/skia/include/gpu/GrRenderTarget.h" | 58 #include "third_party/skia/include/gpu/GrRenderTarget.h" |
58 #include "third_party/skia/include/gpu/GrTexture.h" | 59 #include "third_party/skia/include/gpu/GrTexture.h" |
59 #include "wtf/Assertions.h" | 60 #include "wtf/Assertions.h" |
60 #include "wtf/MathExtras.h" | 61 #include "wtf/MathExtras.h" |
61 | 62 |
62 namespace { | 63 namespace { |
63 | 64 |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 if (!color.alpha() || (!offset.width() && !offset.height() && !blur)) { | 315 if (!color.alpha() || (!offset.width() && !offset.height() && !blur)) { |
315 if (shadowMode == DrawShadowOnly) { | 316 if (shadowMode == DrawShadowOnly) { |
316 // shadow only, but there is no shadow: use an empty draw looper to disable rendering of the source primitive | 317 // shadow only, but there is no shadow: use an empty draw looper to disable rendering of the source primitive |
317 setDrawLooper(drawLooperBuilder.release()); | 318 setDrawLooper(drawLooperBuilder.release()); |
318 return; | 319 return; |
319 } | 320 } |
320 clearShadow(); | 321 clearShadow(); |
321 return; | 322 return; |
322 } | 323 } |
323 | 324 |
324 drawLooperBuilder->addShadow(offset, blur, color, shadowTransformMode, shado wAlphaMode); | 325 drawLooperBuilder->addShadow(offset, blur, color, shadowTransformMode, shado wAlphaMode); |
Justin Novosad
2014/10/23 02:29:21
We shouldn't be setting up a draw looper in cases
sugoi1
2014/10/23 17:43:17
And it is. See preparePaintForDrawRectToRec().
| |
325 if (shadowMode == DrawShadowAndForeground) { | 326 if (shadowMode == DrawShadowAndForeground) { |
326 drawLooperBuilder->addUnmodifiedContent(); | 327 drawLooperBuilder->addUnmodifiedContent(); |
327 } | 328 } |
328 setDrawLooper(drawLooperBuilder.release()); | 329 setDrawLooper(drawLooperBuilder.release()); |
330 | |
331 // The image filter MUST be set after the draw looper, because setting the d raw looper will reset the image filter | |
Stephen White
2014/10/23 01:45:47
I think we should just have setDrawLooper leave th
sugoi1
2014/10/23 17:43:17
Done.
| |
332 if (shadowTransformMode == DrawLooperBuilder::ShadowIgnoresTransforms | |
333 && shadowAlphaMode == DrawLooperBuilder::ShadowRespectsAlpha) { | |
Justin Novosad
2014/10/23 02:29:21
With this condition, you will regress performance
sugoi1
2014/10/23 17:43:17
This image filter will only be used to replace the
| |
334 SkColor skColor = color.rgb(); | |
335 const SkScalar sigma = 0.288675f * blur + 0.5f; | |
336 setImageFilter(adoptRef(SkDropShadowImageFilter::Create(offset.width(), offset.height(), sigma, sigma, skColor))); | |
Stephen White
2014/10/23 01:45:47
I think we should put this in a RefPtr<SkImageFilt
Justin Novosad
2014/10/23 02:29:21
You are not supporting the shadowMode==ShadowOnly
sugoi1
2014/10/23 17:43:17
Done.
sugoi1
2014/10/23 17:43:17
I'm not going to fix this now, so I'll skip this p
| |
337 } | |
329 } | 338 } |
330 | 339 |
331 void GraphicsContext::setDrawLooper(PassOwnPtr<DrawLooperBuilder> drawLooperBuil der) | 340 void GraphicsContext::setDrawLooper(PassOwnPtr<DrawLooperBuilder> drawLooperBuil der) |
332 { | 341 { |
333 if (contextDisabled()) | 342 if (contextDisabled()) |
334 return; | 343 return; |
335 | 344 |
336 mutableState()->setDrawLooper(drawLooperBuilder->detachDrawLooper()); | 345 mutableState()->setDrawLooper(drawLooperBuilder->detachDrawLooper()); |
346 // If the draw looper is overwritten externally, remove the image filter, as it is no longer equivalent to the draw looper | |
347 clearImageFilter(); | |
Stephen White
2014/10/23 01:45:47
So if you agree with the above, remove this.
sugoi1
2014/10/23 17:43:17
Done.
| |
337 } | 348 } |
338 | 349 |
339 void GraphicsContext::clearDrawLooper() | 350 void GraphicsContext::clearDrawLooper() |
340 { | 351 { |
341 if (contextDisabled()) | 352 if (contextDisabled()) |
342 return; | 353 return; |
343 | 354 |
344 mutableState()->clearDrawLooper(); | 355 mutableState()->clearDrawLooper(); |
356 // If the draw looper is overwritten externally, remove the image filter, as it is no longer equivalent to the draw looper | |
357 clearImageFilter(); | |
Stephen White
2014/10/23 01:45:47
And this.
sugoi1
2014/10/23 17:43:17
Done.
| |
358 } | |
359 | |
360 void GraphicsContext::setImageFilter(PassRefPtr<SkImageFilter> imageFilter) | |
361 { | |
362 if (contextDisabled()) | |
363 return; | |
364 | |
365 mutableState()->setImageFilter(imageFilter); | |
366 } | |
367 | |
368 void GraphicsContext::clearImageFilter() | |
369 { | |
370 if (contextDisabled()) | |
371 return; | |
372 | |
373 mutableState()->clearImageFilter(); | |
345 } | 374 } |
346 | 375 |
347 bool GraphicsContext::hasShadow() const | 376 bool GraphicsContext::hasShadow() const |
348 { | 377 { |
349 return !!immutableState()->drawLooper(); | 378 return !!immutableState()->drawLooper() || !!immutableState()->imageFilter() ; |
350 } | 379 } |
351 | 380 |
352 bool GraphicsContext::getTransformedClipBounds(FloatRect* bounds) const | 381 bool GraphicsContext::getTransformedClipBounds(FloatRect* bounds) const |
353 { | 382 { |
354 if (contextDisabled()) | 383 if (contextDisabled()) |
355 return false; | 384 return false; |
356 ASSERT(m_canvas); | 385 ASSERT(m_canvas); |
357 SkIRect skIBounds; | 386 SkIRect skIBounds; |
358 if (!m_canvas->getClipDeviceBounds(&skIBounds)) | 387 if (!m_canvas->getClipDeviceBounds(&skIBounds)) |
359 return false; | 388 return false; |
(...skipping 1600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1960 m_textRegion.join(textRect); | 1989 m_textRegion.join(textRect); |
1961 } | 1990 } |
1962 } | 1991 } |
1963 | 1992 |
1964 void GraphicsContext::preparePaintForDrawRectToRect( | 1993 void GraphicsContext::preparePaintForDrawRectToRect( |
1965 SkPaint* paint, | 1994 SkPaint* paint, |
1966 const SkRect& srcRect, | 1995 const SkRect& srcRect, |
1967 const SkRect& destRect, | 1996 const SkRect& destRect, |
1968 CompositeOperator compositeOp, | 1997 CompositeOperator compositeOp, |
1969 WebBlendMode blendMode, | 1998 WebBlendMode blendMode, |
1999 bool isOpaque, | |
1970 bool isLazyDecoded, | 2000 bool isLazyDecoded, |
1971 bool isDataComplete) const | 2001 bool isDataComplete) const |
1972 { | 2002 { |
1973 paint->setXfermodeMode(WebCoreCompositeToSkiaComposite(compositeOp, blendMod e)); | 2003 paint->setXfermodeMode(WebCoreCompositeToSkiaComposite(compositeOp, blendMod e)); |
1974 paint->setColorFilter(this->colorFilter()); | 2004 paint->setColorFilter(this->colorFilter()); |
1975 paint->setAlpha(this->getNormalizedAlpha()); | 2005 paint->setAlpha(this->getNormalizedAlpha()); |
1976 paint->setLooper(this->drawLooper()); | 2006 if (this->imageFilter() && !isOpaque) { |
2007 paint->setImageFilter(this->imageFilter()); | |
2008 } else { | |
2009 paint->setLooper(this->drawLooper()); | |
2010 } | |
1977 paint->setAntiAlias(shouldDrawAntiAliased(this, destRect)); | 2011 paint->setAntiAlias(shouldDrawAntiAliased(this, destRect)); |
1978 | 2012 |
1979 InterpolationQuality resampling; | 2013 InterpolationQuality resampling; |
1980 if (this->isAccelerated()) { | 2014 if (this->isAccelerated()) { |
1981 resampling = InterpolationLow; | 2015 resampling = InterpolationLow; |
1982 } else if (this->printing()) { | 2016 } else if (this->printing()) { |
1983 resampling = InterpolationNone; | 2017 resampling = InterpolationNone; |
1984 } else if (isLazyDecoded) { | 2018 } else if (isLazyDecoded) { |
1985 resampling = InterpolationHigh; | 2019 resampling = InterpolationHigh; |
1986 } else { | 2020 } else { |
(...skipping 13 matching lines...) Expand all Loading... | |
2000 // FIXME: This is to not break tests (it results in the filter bitmap fl ag | 2034 // FIXME: This is to not break tests (it results in the filter bitmap fl ag |
2001 // being set to true). We need to decide if we respect InterpolationNone | 2035 // being set to true). We need to decide if we respect InterpolationNone |
2002 // being returned from computeInterpolationQuality. | 2036 // being returned from computeInterpolationQuality. |
2003 resampling = InterpolationLow; | 2037 resampling = InterpolationLow; |
2004 } | 2038 } |
2005 resampling = limitInterpolationQuality(this, resampling); | 2039 resampling = limitInterpolationQuality(this, resampling); |
2006 paint->setFilterLevel(static_cast<SkPaint::FilterLevel>(resampling)); | 2040 paint->setFilterLevel(static_cast<SkPaint::FilterLevel>(resampling)); |
2007 } | 2041 } |
2008 | 2042 |
2009 } // namespace blink | 2043 } // namespace blink |
OLD | NEW |