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

Unified Diff: src/effects/SkBlurDrawLooper.cpp

Issue 253633003: add asAShadowBlur for android to drawlooper (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: add unittests (and fix bugs in layerdrawlooper) Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkMaskFilter.cpp ('k') | src/effects/SkBlurMask.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/SkBlurDrawLooper.cpp
diff --git a/src/effects/SkBlurDrawLooper.cpp b/src/effects/SkBlurDrawLooper.cpp
index 03e635be1214a9cb4608bcd5cdb713e53ab9a2ce..5af02db8ee73fb4b0354a910e58673f3499b26d3 100644
--- a/src/effects/SkBlurDrawLooper.cpp
+++ b/src/effects/SkBlurDrawLooper.cpp
@@ -1,10 +1,10 @@
-
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+
#include "SkBlurDrawLooper.h"
#include "SkBlurMask.h" // just for SkBlurMask::ConvertRadiusToSigma
#include "SkBlurMaskFilter.h"
@@ -29,32 +29,27 @@ SkBlurDrawLooper::SkBlurDrawLooper(SkColor color, SkScalar sigma,
this->init(sigma, dx, dy, color, flags);
}
-void SkBlurDrawLooper::init(SkScalar sigma, SkScalar dx, SkScalar dy,
- SkColor color, uint32_t flags) {
- fDx = dx;
- fDy = dy;
- fBlurColor = color;
- fBlurFlags = flags;
-
- SkASSERT(flags <= kAll_BlurFlag);
- if (sigma > 0) {
- uint32_t blurFlags = flags & kIgnoreTransform_BlurFlag ?
- SkBlurMaskFilter::kIgnoreTransform_BlurFlag :
- SkBlurMaskFilter::kNone_BlurFlag;
-
- blurFlags |= flags & kHighQuality_BlurFlag ?
- SkBlurMaskFilter::kHighQuality_BlurFlag :
- SkBlurMaskFilter::kNone_BlurFlag;
-
- fBlur = SkBlurMaskFilter::Create(kNormal_SkBlurStyle, sigma, blurFlags);
+// only call from constructor
+void SkBlurDrawLooper::initEffects() {
+ SkASSERT(fBlurFlags <= kAll_BlurFlag);
+ if (fSigma > 0) {
+ uint32_t flags = fBlurFlags & kIgnoreTransform_BlurFlag ?
+ SkBlurMaskFilter::kIgnoreTransform_BlurFlag :
+ SkBlurMaskFilter::kNone_BlurFlag;
+
+ flags |= fBlurFlags & kHighQuality_BlurFlag ?
+ SkBlurMaskFilter::kHighQuality_BlurFlag :
+ SkBlurMaskFilter::kNone_BlurFlag;
+
+ fBlur = SkBlurMaskFilter::Create(kNormal_SkBlurStyle, fSigma, flags);
} else {
fBlur = NULL;
}
-
- if (flags & kOverrideColor_BlurFlag) {
+
+ if (fBlurFlags & kOverrideColor_BlurFlag) {
// Set alpha to 1 for the override since transparency will already
// be baked into the blurred mask.
- SkColor opaqueColor = SkColorSetA(color, 255);
+ SkColor opaqueColor = SkColorSetA(fBlurColor, 255);
//The SrcIn xfer mode will multiply 'color' by the incoming alpha
fColorFilter = SkColorFilter::CreateModeFilter(opaqueColor,
SkXfermode::kSrcIn_Mode);
@@ -63,32 +58,60 @@ void SkBlurDrawLooper::init(SkScalar sigma, SkScalar dx, SkScalar dy,
}
}
-SkBlurDrawLooper::SkBlurDrawLooper(SkReadBuffer& buffer)
-: INHERITED(buffer) {
+void SkBlurDrawLooper::init(SkScalar sigma, SkScalar dx, SkScalar dy,
+ SkColor color, uint32_t flags) {
+ fSigma = sigma;
+ fDx = dx;
+ fDy = dy;
+ fBlurColor = color;
+ fBlurFlags = flags;
+
+ this->initEffects();
+}
+
+SkBlurDrawLooper::SkBlurDrawLooper(SkReadBuffer& buffer) : INHERITED(buffer) {
+ fSigma = buffer.readScalar();
fDx = buffer.readScalar();
fDy = buffer.readScalar();
fBlurColor = buffer.readColor();
- fBlur = buffer.readMaskFilter();
- fColorFilter = buffer.readColorFilter();
fBlurFlags = buffer.readUInt() & kAll_BlurFlag;
-}
-SkBlurDrawLooper::~SkBlurDrawLooper() {
- SkSafeUnref(fBlur);
- SkSafeUnref(fColorFilter);
+ this->initEffects();
}
void SkBlurDrawLooper::flatten(SkWriteBuffer& buffer) const {
this->INHERITED::flatten(buffer);
+ buffer.writeScalar(fSigma);
buffer.writeScalar(fDx);
buffer.writeScalar(fDy);
buffer.writeColor(fBlurColor);
- buffer.writeFlattenable(fBlur);
- buffer.writeFlattenable(fColorFilter);
- buffer.writeUInt(fBlurFlags);
+ buffer.write32(fBlurFlags);
+}
+
+SkBlurDrawLooper::~SkBlurDrawLooper() {
+ SkSafeUnref(fBlur);
+ SkSafeUnref(fColorFilter);
}
+bool SkBlurDrawLooper::asABlurShadow(BlurShadowRec* rec) const {
+ if (fSigma <= 0 || (fBlurFlags & fBlurFlags & kIgnoreTransform_BlurFlag)) {
+ return false;
+ }
+
+ if (rec) {
+ rec->fSigma = fSigma;
+ rec->fColor = fBlurColor;
+ rec->fOffset.set(fDx, fDy);
+ rec->fStyle = kNormal_SkBlurStyle;
+ rec->fQuality = (fBlurFlags & kHighQuality_BlurFlag) ?
+ kHigh_SkBlurQuality : kLow_SkBlurQuality;
+ }
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////
+
SkDrawLooper::Context* SkBlurDrawLooper::createContext(SkCanvas*, void* storage) const {
return SkNEW_PLACEMENT_ARGS(storage, BlurDrawLooperContext, (this));
}
« no previous file with comments | « src/core/SkMaskFilter.cpp ('k') | src/effects/SkBlurMask.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698