aboutsummaryrefslogtreecommitdiffstats
path: root/gm
diff options
context:
space:
mode:
authorJim Van Verth <jvanverth@google.com>2019-01-18 10:36:32 -0500
committerSkia Commit-Bot <skia-commit-bot@chromium.org>2019-01-18 16:32:08 +0000
commitee06b33570f0c78616231d8c5ed1e639cd162e69 (patch)
tree63f1a6a3c28cd27909713f33e336397c5f2f4dab /gm
parent3a33fa5371e948e3e79377b6002888c76e75f42e (diff)
downloadplatform_external_skqp-ee06b33570f0c78616231d8c5ed1e639cd162e69.tar.gz
platform_external_skqp-ee06b33570f0c78616231d8c5ed1e639cd162e69.tar.bz2
platform_external_skqp-ee06b33570f0c78616231d8c5ed1e639cd162e69.zip
Reland "Add compressed data support for SkImage."
This is a reland of 57263c2e0ccddf4dd62814c427a39d9d615acbe5 Original change's description: > Add compressed data support for SkImage. > > Adds a new SkImage::MakeFromCompressed method which takes raw data, > a size, and a compression method, and returns a GPU-backed > image. > > Bug: skia:8684 > Change-Id: I570c9dafce283bcd64dfbef4fbe1c4bfeac6ce2a > Reviewed-on: https://skia-review.googlesource.com/c/184484 > Commit-Queue: Jim Van Verth <jvanverth@google.com> > Reviewed-by: Brian Salomon <bsalomon@google.com> > Reviewed-by: Robert Phillips <robertphillips@google.com> Bug: skia:8684 Change-Id: I25fb320e8cc05e1c5afa6faa81e1a55ffd83a7a3 Reviewed-on: https://skia-review.googlesource.com/c/185200 Reviewed-by: Jim Van Verth <jvanverth@google.com> Commit-Queue: Jim Van Verth <jvanverth@google.com>
Diffstat (limited to 'gm')
-rw-r--r--gm/etc1.cpp46
1 files changed, 9 insertions, 37 deletions
diff --git a/gm/etc1.cpp b/gm/etc1.cpp
index a384b12446..f8432db309 100644
--- a/gm/etc1.cpp
+++ b/gm/etc1.cpp
@@ -7,6 +7,7 @@
#include "gm.h"
#include "sk_tool_utils.h"
+#include "SkImage.h"
#include "SkRandom.h"
#if SK_SUPPORT_GPU && !defined(SK_BUILD_FOR_GOOGLE3)
@@ -51,13 +52,13 @@ protected:
}
int size = etc1_get_encoded_data_size(bm.width(), bm.height());
- fETC1Data.reset(size);
+ fETC1Data = SkData::MakeUninitialized(size);
- unsigned char* pixels = (unsigned char*) fETC1Data.get();
+ unsigned char* pixels = (unsigned char*) fETC1Data->writable_data();
if (etc1_encode_image((unsigned char*) bm.getAddr16(0, 0),
bm.width(), bm.height(), 2, bm.rowBytes(), pixels)) {
- fETC1Data.reset();
+ fETC1Data = nullptr;
}
}
@@ -74,40 +75,11 @@ protected:
return;
}
- GrBackendTexture tex = context->contextPriv().getGpu()->createTestingOnlyBackendTexture(
- fETC1Data.get(),
- kTexWidth,
- kTexHeight,
- GrColorType::kRGB_ETC1,
- false,
- GrMipMapped::kNo,
- kTexWidth/2); // rowbytes are meaningless for compressed textures, but this is
- // basically right
-
- if (!tex.isValid()) {
- return;
- }
-
- auto proxy = context->contextPriv().proxyProvider()->wrapBackendTexture(
- tex, kTopLeft_GrSurfaceOrigin,
- kAdopt_GrWrapOwnership,
- kRead_GrIOType);
- if (!proxy) {
- return;
- }
-
- const SkMatrix trans = SkMatrix::MakeTrans(-kPad, -kPad);
-
- auto fp = GrSimpleTextureEffect::Make(proxy, trans);
-
- GrPaint grPaint;
- grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc));
- grPaint.addColorFragmentProcessor(std::move(fp));
-
- SkRect rect = SkRect::MakeXYWH(kPad, kPad, kTexWidth, kTexHeight);
+ sk_sp<SkImage> image = SkImage::MakeFromCompressed(context, fETC1Data,
+ kTexWidth, kTexHeight,
+ SkImage::kETC1_CompressionType);
- renderTargetContext->priv().testingOnly_addDrawOp(
- GrFillRectOp::Make(context, std::move(grPaint), GrAAType::kNone, SkMatrix::I(), rect));
+ canvas->drawImage(image, 0, 0);
}
private:
@@ -115,7 +87,7 @@ private:
static const int kTexWidth = 16;
static const int kTexHeight = 20;
- SkAutoTMalloc<char> fETC1Data;
+ sk_sp<SkData> fETC1Data;
typedef GM INHERITED;
};