diff options
author | 2012-08-20 14:53:21 +0000 | |
---|---|---|
committer | 2012-08-20 14:53:21 +0000 | |
commit | f1369ce607adf55ffffe58fb93893bafb6ff6ebe (patch) | |
tree | 5d375585df0e0b1ff05b6f08f597bb578a58261f /src/effects/SkSingleInputImageFilter.cpp | |
parent | 52805485581cff7e13134aa1465a2950f7bed007 (diff) |
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
Diffstat (limited to 'src/effects/SkSingleInputImageFilter.cpp')
-rw-r--r-- | src/effects/SkSingleInputImageFilter.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
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<SkImageFilter>(); + } 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) |