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

Side by Side Diff: Source/platform/graphics/GraphicsContext.cpp

Issue 669123002: Fixed Shadow blur for transparent objects (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added missing virtual layout test to TestExpectations Created 6 years, 2 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 /* 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
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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
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);
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 if (shadowTransformMode == DrawLooperBuilder::ShadowIgnoresTransforms
Justin Novosad 2014/11/28 23:20:39 This is wrong by the way. SkDropShadowImageFilter
332 && shadowAlphaMode == DrawLooperBuilder::ShadowRespectsAlpha) {
333 // This image filter will be used in place of the drawLooper created abo ve but only for drawing non-opaque bitmaps;
334 // see preparePaintForDrawRectToRect().
335 SkColor skColor = color.rgb();
336 // These constants are from RadiusToSigma() from DrawLooperBuilder.cpp.
337 const SkScalar sigma = 0.288675f * blur + 0.5f;
338 SkDropShadowImageFilter::ShadowMode dropShadowMode = shadowMode == DrawS hadowAndForeground ? SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMod e : SkDropShadowImageFilter::kDrawShadowOnly_ShadowMode;
339 RefPtr<SkImageFilter> filter = adoptRef(SkDropShadowImageFilter::Create( offset.width(), offset.height(), sigma, sigma, skColor, dropShadowMode));
340 setDropShadowImageFilter(filter);
341 }
329 } 342 }
330 343
331 void GraphicsContext::setDrawLooper(PassOwnPtr<DrawLooperBuilder> drawLooperBuil der) 344 void GraphicsContext::setDrawLooper(PassOwnPtr<DrawLooperBuilder> drawLooperBuil der)
332 { 345 {
333 if (contextDisabled()) 346 if (contextDisabled())
334 return; 347 return;
335 348
336 mutableState()->setDrawLooper(drawLooperBuilder->detachDrawLooper()); 349 mutableState()->setDrawLooper(drawLooperBuilder->detachDrawLooper());
337 } 350 }
338 351
339 void GraphicsContext::clearDrawLooper() 352 void GraphicsContext::clearDrawLooper()
340 { 353 {
341 if (contextDisabled()) 354 if (contextDisabled())
342 return; 355 return;
343 356
344 mutableState()->clearDrawLooper(); 357 mutableState()->clearDrawLooper();
345 } 358 }
346 359
360 void GraphicsContext::setDropShadowImageFilter(PassRefPtr<SkImageFilter> imageFi lter)
361 {
362 if (contextDisabled())
363 return;
364
365 mutableState()->setDropShadowImageFilter(imageFilter);
366 }
367
368 void GraphicsContext::clearDropShadowImageFilter()
369 {
370 if (contextDisabled())
371 return;
372
373 mutableState()->clearDropShadowImageFilter();
374 }
375
347 bool GraphicsContext::hasShadow() const 376 bool GraphicsContext::hasShadow() const
348 { 377 {
349 return !!immutableState()->drawLooper(); 378 return !!immutableState()->drawLooper() || !!immutableState()->dropShadowIma geFilter();
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
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 isBitmapWithAlpha,
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->dropShadowImageFilter() && isBitmapWithAlpha) {
2007 paint->setImageFilter(this->dropShadowImageFilter());
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
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
OLDNEW
« no previous file with comments | « Source/platform/graphics/GraphicsContext.h ('k') | Source/platform/graphics/GraphicsContextState.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698