skia2/gm/deferredtextureimagedata.cpp
halcanary e9d55c57a6 Revert of Store mipmap levels in deferred texture image (patchset #11 id:200001 of https://codereview.chromium.org/2115023002/ )
Reason for revert:
speculative revert: android dm crashes

Original issue's description:
> Store mipmap levels in deferred texture image
>
> This is a follow-up to https://codereview.chromium.org/2034933003/ which
> was reverted due to a memory leak.
>
> When creating the deferred texture image, detect if using medium / high
> quality. If so, generate and store mipmaps in the deferred texture
> image.
>
> When creating a texture from that be sure to read it back out.
>
> BUG=578304
> GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2115023002
>
> Committed: https://skia.googlesource.com/skia/+/d6113140f7ae8996f679ac6698a60fb8c1386da3

TBR=brianosman@google.com,bsalomon@google.com,ericrk@chromium.org,cblume@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=578304

Review-Url: https://codereview.chromium.org/2227323002
2016-08-09 17:46:25 -07:00

82 lines
3.0 KiB
C++

/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include <vector>
#include "gm.h"
#include "GrContext.h"
#include "Resources.h"
#include "SkImage.h"
#if SK_SUPPORT_GPU
// Helper function that uploads the given SkImage using MakdeFromDeferredTextureImageData and then
// draws the uploaded version at the specified coordinates.
static bool DrawDeferredTextureImageData(GrContext* context, SkCanvas* canvas, SkImage* image,
SkImage::DeferredTextureImageUsageParams* params,
SkScalar x, SkScalar y) {
SkAutoTUnref<GrContextThreadSafeProxy> proxy(context->threadSafeProxy());
size_t deferredSize = image->getDeferredTextureImageData(*proxy, params, 1, nullptr);
if (deferredSize == 0) {
SkDebugf("\nCould not create DeferredTextureImageData.\n");
return false;
}
std::vector<uint8_t> memory;
memory.resize(deferredSize);
image->getDeferredTextureImageData(*proxy, params, 1, memory.data());
sk_sp<SkImage> uploadedImage =
SkImage::MakeFromDeferredTextureImageData(context, memory.data(), SkBudgeted::kNo);
canvas->drawImage(uploadedImage, x, y);
return true;
}
DEF_SIMPLE_GM(deferred_texture_image_data, canvas, 60, 10) {
GrContext* context = canvas->getGrContext();
if (!context) {
skiagm::GM::DrawGpuOnlyMessage(canvas);
return;
}
sk_sp<SkImage> encodedImage = GetResourceAsImage("randPixels.png");
if (!encodedImage) {
SkDebugf("\nCould not load resource.\n");
return;
}
SkBitmap bitmap;
if (!GetResourceAsBitmap("randPixels.png", &bitmap)) {
SkDebugf("\nCould not decode resource.\n");
return;
}
sk_sp<SkImage> decodedImage = SkImage::MakeFromBitmap(bitmap);
// Draw both encoded and decoded image via deferredTextureImageData.
SkImage::DeferredTextureImageUsageParams params;
DrawDeferredTextureImageData(context, canvas, encodedImage.get(), &params, 0, 0);
DrawDeferredTextureImageData(context, canvas, decodedImage.get(), &params, 10, 0);
// Draw 50% scaled versions of the encoded and decoded images at medium quality.
SkImage::DeferredTextureImageUsageParams mediumScaledParams;
mediumScaledParams.fPreScaleMipLevel = 1;
mediumScaledParams.fQuality = kMedium_SkFilterQuality;
DrawDeferredTextureImageData(context, canvas, encodedImage.get(), &mediumScaledParams, 20, 0);
DrawDeferredTextureImageData(context, canvas, decodedImage.get(), &mediumScaledParams, 30, 0);
// Draw 50% scaled versions of the encoded and decoded images at none quality.
SkImage::DeferredTextureImageUsageParams noneScaledParams;
noneScaledParams.fPreScaleMipLevel = 1;
noneScaledParams.fQuality = kNone_SkFilterQuality;
DrawDeferredTextureImageData(context, canvas, encodedImage.get(), &noneScaledParams, 40, 0);
DrawDeferredTextureImageData(context, canvas, decodedImage.get(), &noneScaledParams, 50, 0);
}
#endif