aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/effects/SkColorFilterImageFilter.cpp
diff options
context:
space:
mode:
authorGravatar senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-10-26 19:37:00 +0000
committerGravatar senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-10-26 19:37:00 +0000
commitcd9f55989e680b7f52fa21766dde0ac67ac9911f (patch)
tree8c8c4baca3cf32f2a4fd4104d52c10189a06209d /src/effects/SkColorFilterImageFilter.cpp
parenta76de72a6036da0a6b051b14411b80941971f881 (diff)
Add a factory Create function for SkColorFilterImageFilter, and move the matrix optimization there. This will allow the Chrome compositor to extract the optimized matrix, and potentially apply the color matrix itself, saving a buffer allocation & draw.
Review URL: https://codereview.appspot.com/6739057 git-svn-id: http://skia.googlecode.com/svn/trunk@6152 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/effects/SkColorFilterImageFilter.cpp')
-rwxr-xr-xsrc/effects/SkColorFilterImageFilter.cpp46
1 files changed, 20 insertions, 26 deletions
diff --git a/src/effects/SkColorFilterImageFilter.cpp b/src/effects/SkColorFilterImageFilter.cpp
index 22b5d12c9c..369f782d18 100755
--- a/src/effects/SkColorFilterImageFilter.cpp
+++ b/src/effects/SkColorFilterImageFilter.cpp
@@ -56,6 +56,24 @@ bool matrix_needs_clamping(SkScalar matrix[20]) {
};
+SkColorFilterImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf,
+ SkImageFilter* input) {
+ SkASSERT(cf);
+ SkScalar colorMatrix[20], inputMatrix[20];
+ SkColorFilter* inputColorFilter;
+ if (input && cf->asColorMatrix(colorMatrix)
+ && (inputColorFilter = input->asColorFilter())
+ && inputColorFilter->asColorMatrix(inputMatrix)
+ && !matrix_needs_clamping(inputMatrix)) {
+ SkScalar combinedMatrix[20];
+ mult_color_matrix(inputMatrix, colorMatrix, combinedMatrix);
+ SkAutoTUnref<SkColorFilter> newCF(SkNEW_ARGS(SkColorMatrixFilter, (combinedMatrix)));
+ return SkNEW_ARGS(SkColorFilterImageFilter, (newCF, input->getInput(0)));
+ } else {
+ return SkNEW_ARGS(SkColorFilterImageFilter, (cf, input));
+ }
+}
+
SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf, SkImageFilter* input) : INHERITED(input), fColorFilter(cf) {
SkASSERT(cf);
SkSafeRef(cf);
@@ -79,37 +97,13 @@ bool SkColorFilterImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& sourc
const SkMatrix& matrix,
SkBitmap* result,
SkIPoint* loc) {
- SkImageFilter* parent = getInput(0);
- SkScalar colorMatrix[20];
- SkBitmap src;
- SkColorFilter* cf;
- if (parent && fColorFilter->asColorMatrix(colorMatrix)) {
- SkColorFilter* parentColorFilter;
- SkScalar parentMatrix[20];
- while (parent && (parentColorFilter = parent->asColorFilter())
- && parentColorFilter->asColorMatrix(parentMatrix)
- && !matrix_needs_clamping(parentMatrix)) {
- SkScalar combinedMatrix[20];
- mult_color_matrix(parentMatrix, colorMatrix, combinedMatrix);
- memcpy(colorMatrix, combinedMatrix, 20 * sizeof(SkScalar));
- parent = parent->getInput(0);
- }
- if (!parent || !parent->filterImage(proxy, source, matrix, &src, loc)) {
- src = source;
- }
- cf = SkNEW_ARGS(SkColorMatrixFilter, (colorMatrix));
- } else {
- src = this->getInputResult(proxy, source, matrix, loc);
- cf = fColorFilter;
- cf->ref();
- }
-
+ SkBitmap src = this->getInputResult(proxy, source, matrix, loc);
SkAutoTUnref<SkDevice> device(proxy->createDevice(src.width(), src.height()));
SkCanvas canvas(device.get());
SkPaint paint;
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
- paint.setColorFilter(cf)->unref();
+ paint.setColorFilter(fColorFilter);
canvas.drawSprite(src, 0, 0, &paint);
*result = device.get()->accessBitmap(false);