blob: 8385fb446ae0726ade2ccfbad3250239e6209211 [file] [log] [blame]
senorblanco@chromium.orgc2594f42013-01-30 19:08:47 +00001/*
2 * Copyright 2013 The Android Open Source Project
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
robertphillips@google.comc3ecf652013-01-31 02:33:09 +00008#include "SkMatrix.h"
9
senorblanco@chromium.orgc2594f42013-01-30 19:08:47 +000010#if SK_SUPPORT_GPU
11#include "GrTexture.h"
12#include "SkImageFilterUtils.h"
13#include "SkBitmap.h"
senorblanco@chromium.orgc2594f42013-01-30 19:08:47 +000014#include "SkGrPixelRef.h"
15#include "SkGr.h"
16
17bool SkImageFilterUtils::WrapTexture(GrTexture* texture, int width, int height, SkBitmap* result) {
reed@google.com398337b2013-12-11 21:22:39 +000018 result->setConfig(SkBitmap::kARGB_8888_Config, width, height);
19 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (texture)))->unref();
senorblanco@chromium.orgc2594f42013-01-30 19:08:47 +000020 return true;
21}
22
commit-bot@chromium.org7b320702013-07-10 21:22:18 +000023bool SkImageFilterUtils::GetInputResultGPU(SkImageFilter* filter, SkImageFilter::Proxy* proxy,
commit-bot@chromium.org1aa54bf2013-08-05 16:53:50 +000024 const SkBitmap& src, const SkMatrix& ctm,
25 SkBitmap* result, SkIPoint* offset) {
commit-bot@chromium.orgbbfe4542013-10-24 01:46:11 +000026 // 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);
senorblanco@chromium.orgc2594f42013-01-30 19:08:47 +000031 if (!filter) {
32 *result = src;
33 return true;
34 } else if (filter->canFilterImageGPU()) {
commit-bot@chromium.org1aa54bf2013-08-05 16:53:50 +000035 return filter->filterImageGPU(proxy, src, ctm, result, offset);
senorblanco@chromium.orgc2594f42013-01-30 19:08:47 +000036 } else {
commit-bot@chromium.org1aa54bf2013-08-05 16:53:50 +000037 if (filter->filterImage(proxy, src, ctm, result, offset)) {
senorblanco@chromium.orgc2594f42013-01-30 19:08:47 +000038 if (!result->getTexture()) {
commit-bot@chromium.orgbbfe4542013-10-24 01:46:11 +000039 GrTexture* resultTex = GrLockAndRefCachedBitmapTexture(context, *result, NULL);
reed@google.com398337b2013-12-11 21:22:39 +000040 result->setPixelRef(new SkGrPixelRef(resultTex))->unref();
senorblanco@chromium.orgc2594f42013-01-30 19:08:47 +000041 GrUnlockAndUnrefCachedBitmapTexture(resultTex);
42 }
43 return true;
44 } else {
45 return false;
46 }
47 }
48}
49#endif