2 * Copyright 2013 The Android Open Source Project
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
11 #include "GrTexture.h"
12 #include "SkImageFilterUtils.h"
14 #include "SkGrPixelRef.h"
17 bool SkImageFilterUtils::WrapTexture(GrTexture* texture, int width, int height, SkBitmap* result) {
18 result->setConfig(SkBitmap::kARGB_8888_Config, width, height);
19 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (texture)))->unref();
23 bool SkImageFilterUtils::GetInputResultGPU(SkImageFilter* filter, SkImageFilter::Proxy* proxy,
24 const SkBitmap& src, const SkMatrix& ctm,
25 SkBitmap* result, SkIPoint* offset) {
26 // Ensure that GrContext calls under filterImage and filterImageGPU below will see an identity
27 // matrix with no clip and that the matrix, clip, and render target set before this function was
28 // called are restored before we return to the caller.
29 GrContext* context = src.getTexture()->getContext();
30 GrContext::AutoWideOpenIdentityDraw awoid(context, NULL);
34 } else if (filter->canFilterImageGPU()) {
35 return filter->filterImageGPU(proxy, src, ctm, result, offset);
37 if (filter->filterImage(proxy, src, ctm, result, offset)) {
38 if (!result->getTexture()) {
39 GrTexture* resultTex = GrLockAndRefCachedBitmapTexture(context, *result, NULL);
40 result->setPixelRef(new SkGrPixelRef(resultTex))->unref();
41 GrUnlockAndUnrefCachedBitmapTexture(resultTex);