From f1369ce607adf55ffffe58fb93893bafb6ff6ebe Mon Sep 17 00:00:00 2001 From: "senorblanco@chromium.org" Date: Mon, 20 Aug 2012 14:53:21 +0000 Subject: Implements a new class, SkSingleInputImageFilter, to handle DAG connectivity for filters with a single image input. This provides functionality to store, flatten and unflatten a single SkImageFilter input, as well as to recursively evaluate it on the CPU or GPU. The following classes were re-parented to implement DAG connectivity: SkBlurImageFilter, SkDilateImageFilter, SkErodeImageFilter, SkColorFilterImageFilter. The constructors for each have been appended with a new parameter, representing the input filter (default NULL). This change also implements an arbitrary SkBitmap input source for filtering, SkBitmapSource. NOTE: This CL will require gyp file changes when rolling past this revision. Review URL: https://codereview.appspot.com/6462071/ git-svn-id: http://skia.googlecode.com/svn/trunk@5170 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/effects/SkSingleInputImageFilter.cpp | 85 ++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/effects/SkSingleInputImageFilter.cpp (limited to 'src/effects/SkSingleInputImageFilter.cpp') diff --git a/src/effects/SkSingleInputImageFilter.cpp b/src/effects/SkSingleInputImageFilter.cpp new file mode 100644 index 0000000000..291d81cf1a --- /dev/null +++ b/src/effects/SkSingleInputImageFilter.cpp @@ -0,0 +1,85 @@ +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkSingleInputImageFilter.h" +#include "SkBitmap.h" +#include "SkFlattenableBuffers.h" +#include "SkMatrix.h" +#if SK_SUPPORT_GPU +#include "GrTexture.h" +#include "SkGr.h" +#include "SkGrPixelRef.h" +#endif + +SkSingleInputImageFilter::SkSingleInputImageFilter(SkImageFilter* input) : fInput(input) { + SkSafeRef(fInput); +} + +SkSingleInputImageFilter::~SkSingleInputImageFilter() { + SkSafeUnref(fInput); +} + +SkSingleInputImageFilter::SkSingleInputImageFilter(SkFlattenableReadBuffer& rb) { + if (rb.readBool()) { + fInput = rb.readFlattenableT(); + } else { + fInput = NULL; + } +} + +void SkSingleInputImageFilter::flatten(SkFlattenableWriteBuffer& wb) const { + wb.writeBool(NULL != fInput); + if (NULL != fInput) { + wb.writeFlattenable(fInput); + } +} + +SkBitmap SkSingleInputImageFilter::getInputResult(Proxy* proxy, + const SkBitmap& src, + const SkMatrix& ctm, + SkIPoint* offset) { + SkBitmap result; + if (fInput && fInput->filterImage(proxy, src, ctm, &result, offset)) { + return result; + } else { + return src; + } +} + +#if SK_SUPPORT_GPU +GrTexture* SkSingleInputImageFilter::getInputResultAsTexture(GrTexture* src, + const SkRect& rect) { + GrTexture* resultTex; + if (!fInput) { + resultTex = src; + } else if (fInput->canFilterImageGPU()) { + // onFilterImageGPU() already refs the result, so just return it here. + return fInput->onFilterImageGPU(src, rect); + } else { + SkBitmap srcBitmap, result; + srcBitmap.setConfig(SkBitmap::kARGB_8888_Config, src->width(), src->height()); + srcBitmap.setPixelRef(new SkGrPixelRef(src))->unref(); + SkIPoint offset; + if (fInput->filterImage(NULL, srcBitmap, SkMatrix(), &result, &offset)) { + if (result.getTexture()) { + resultTex = (GrTexture*) result.getTexture(); + } else { + resultTex = GrLockCachedBitmapTexture(src->getContext(), result, NULL); + SkSafeRef(resultTex); + GrUnlockCachedBitmapTexture(resultTex); + return resultTex; + } + } else { + resultTex = src; + } + } + SkSafeRef(resultTex); + return resultTex; +} +#endif + +SK_DEFINE_FLATTENABLE_REGISTRAR(SkSingleInputImageFilter) -- cgit v1.2.3