blob: 92fe67e84c05e95452567bf685d6c4236140ade0 [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) {
commit-bot@chromium.orge13af712014-01-13 20:39:14 +000018 SkImageInfo info = {
19 width,
20 height,
21 kPMColor_SkColorType,
22 kPremul_SkAlphaType,
23 };
24 result->setConfig(info);
25 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref();
senorblanco@chromium.orgc2594f42013-01-30 19:08:47 +000026 return true;
27}
28
commit-bot@chromium.org7b320702013-07-10 21:22:18 +000029bool SkImageFilterUtils::GetInputResultGPU(SkImageFilter* filter, SkImageFilter::Proxy* proxy,
commit-bot@chromium.org1aa54bf2013-08-05 16:53:50 +000030 const SkBitmap& src, const SkMatrix& ctm,
31 SkBitmap* result, SkIPoint* offset) {
commit-bot@chromium.orgbbfe4542013-10-24 01:46:11 +000032 // Ensure that GrContext calls under filterImage and filterImageGPU below will see an identity
33 // matrix with no clip and that the matrix, clip, and render target set before this function was
34 // called are restored before we return to the caller.
35 GrContext* context = src.getTexture()->getContext();
36 GrContext::AutoWideOpenIdentityDraw awoid(context, NULL);
senorblanco@chromium.orgc2594f42013-01-30 19:08:47 +000037 if (!filter) {
senorblanco@chromium.org6776b822014-01-03 21:48:22 +000038 offset->fX = offset->fY = 0;
senorblanco@chromium.orgc2594f42013-01-30 19:08:47 +000039 *result = src;
40 return true;
41 } else if (filter->canFilterImageGPU()) {
commit-bot@chromium.org1aa54bf2013-08-05 16:53:50 +000042 return filter->filterImageGPU(proxy, src, ctm, result, offset);
senorblanco@chromium.orgc2594f42013-01-30 19:08:47 +000043 } else {
commit-bot@chromium.org1aa54bf2013-08-05 16:53:50 +000044 if (filter->filterImage(proxy, src, ctm, result, offset)) {
senorblanco@chromium.orgc2594f42013-01-30 19:08:47 +000045 if (!result->getTexture()) {
reed@google.combf790232013-12-13 19:45:58 +000046 SkImageInfo info;
47 if (!result->asImageInfo(&info)) {
48 return false;
49 }
commit-bot@chromium.orgbbfe4542013-10-24 01:46:11 +000050 GrTexture* resultTex = GrLockAndRefCachedBitmapTexture(context, *result, NULL);
reed@google.combf790232013-12-13 19:45:58 +000051 result->setPixelRef(new SkGrPixelRef(info, resultTex))->unref();
senorblanco@chromium.orgc2594f42013-01-30 19:08:47 +000052 GrUnlockAndUnrefCachedBitmapTexture(resultTex);
53 }
54 return true;
55 } else {
56 return false;
57 }
58 }
59}
60#endif