blob: c88d5fed413a4b20a68de470473518fd6dfc47b9 [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) {
senorblanco@chromium.orgc2594f42013-01-30 19:08:47 +000018 result->setConfig(SkBitmap::kARGB_8888_Config, width, height);
19 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (texture)))->unref();
20 return true;
21}
22
commit-bot@chromium.org7b320702013-07-10 21:22:18 +000023bool SkImageFilterUtils::GetInputResultGPU(SkImageFilter* filter, SkImageFilter::Proxy* proxy,
24 const SkBitmap& src, SkBitmap* result,
25 SkIPoint* offset) {
senorblanco@chromium.orgc2594f42013-01-30 19:08:47 +000026 if (!filter) {
27 *result = src;
28 return true;
29 } else if (filter->canFilterImageGPU()) {
commit-bot@chromium.org7b320702013-07-10 21:22:18 +000030 return filter->filterImageGPU(proxy, src, result, offset);
senorblanco@chromium.orgc2594f42013-01-30 19:08:47 +000031 } else {
commit-bot@chromium.org7b320702013-07-10 21:22:18 +000032 if (filter->filterImage(proxy, src, SkMatrix(), result, offset)) {
senorblanco@chromium.orgc2594f42013-01-30 19:08:47 +000033 if (!result->getTexture()) {
34 GrContext* context = ((GrTexture *) src.getTexture())->getContext();
35 GrTexture* resultTex = GrLockAndRefCachedBitmapTexture(context,
36 *result, NULL);
37 result->setPixelRef(new SkGrPixelRef(resultTex))->unref();
38 GrUnlockAndUnrefCachedBitmapTexture(resultTex);
39 }
40 return true;
41 } else {
42 return false;
43 }
44 }
45}
46#endif