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 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
19 result->setConfig(info);
20 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref();
24 bool SkImageFilterUtils::GetInputResultGPU(SkImageFilter* filter, SkImageFilter::Proxy* proxy,
25 const SkBitmap& src, const SkMatrix& ctm,
26 SkBitmap* result, SkIPoint* offset) {
27 // Ensure that GrContext calls under filterImage and filterImageGPU below will see an identity
28 // matrix with no clip and that the matrix, clip, and render target set before this function was
29 // called are restored before we return to the caller.
30 GrContext* context = src.getTexture()->getContext();
31 GrContext::AutoWideOpenIdentityDraw awoid(context, NULL);
33 offset->fX = offset->fY = 0;
36 } else if (filter->canFilterImageGPU()) {
37 return filter->filterImageGPU(proxy, src, ctm, result, offset);
39 if (filter->filterImage(proxy, src, ctm, result, offset)) {
40 if (!result->getTexture()) {
42 if (!result->asImageInfo(&info)) {
45 GrTexture* resultTex = GrLockAndRefCachedBitmapTexture(context, *result, NULL);
46 result->setPixelRef(new SkGrPixelRef(info, resultTex))->unref();
47 GrUnlockAndUnrefCachedBitmapTexture(resultTex);