aboutsummaryrefslogtreecommitdiffstats
path: root/gm
diff options
context:
space:
mode:
authorJim Van Verth <jvanverth@google.com>2019-01-15 13:24:45 -0500
committerJim Van Verth <jvanverth@google.com>2019-01-15 19:56:28 +0000
commit1676cb92820270a301b3f91745d9e5426fe23c7a (patch)
tree5c94f9eb0d9b259d6426660beb8cacf655f7e290 /gm
parent98dea7b11c239559548718783e0e3205a8bea23e (diff)
downloadplatform_external_skqp-1676cb92820270a301b3f91745d9e5426fe23c7a.tar.gz
platform_external_skqp-1676cb92820270a301b3f91745d9e5426fe23c7a.tar.bz2
platform_external_skqp-1676cb92820270a301b3f91745d9e5426fe23c7a.zip
Restore ETC1 compressed texture support.
Brings back GL ETC1 support and adds Vulkan support as well. Bug: skia:8684 Change-Id: Ie65da0a3172793081f0e4072f161bfb9b14678bc Reviewed-on: https://skia-review.googlesource.com/c/179724 Commit-Queue: Jim Van Verth <jvanverth@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'gm')
-rw-r--r--gm/etc1.cpp127
1 files changed, 127 insertions, 0 deletions
diff --git a/gm/etc1.cpp b/gm/etc1.cpp
new file mode 100644
index 0000000000..8f11ee8793
--- /dev/null
+++ b/gm/etc1.cpp
@@ -0,0 +1,127 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "gm.h"
+#include "sk_tool_utils.h"
+#include "SkRandom.h"
+
+#if SK_SUPPORT_GPU
+#include "etc1.h"
+
+#include "GrContext.h"
+#include "GrGpu.h"
+#include "GrRenderTargetContext.h"
+#include "GrRenderTargetContextPriv.h"
+#include "GrTextureProxy.h"
+#include "effects/GrSimpleTextureEffect.h"
+#include "ops/GrFillRectOp.h"
+
+// Basic test of Ganesh's ETC1 support
+class ETC1GM : public skiagm::GM {
+public:
+ ETC1GM() {
+ this->setBGColor(0xFFCCCCCC);
+ }
+
+protected:
+ SkString onShortName() override {
+ return SkString("etc1");
+ }
+
+ SkISize onISize() override {
+ return SkISize::Make(kTexWidth + 2*kPad, kTexHeight + 2*kPad);
+ }
+
+ void onOnceBeforeDraw() override {
+ SkBitmap bm;
+ SkImageInfo ii = SkImageInfo::Make(kTexWidth, kTexHeight, kRGB_565_SkColorType,
+ kOpaque_SkAlphaType);
+ bm.allocPixels(ii);
+
+ bm.erase(SK_ColorBLUE, SkIRect::MakeWH(kTexWidth, kTexHeight));
+
+ for (int y = 0; y < kTexHeight; y += 4) {
+ for (int x = 0; x < kTexWidth; x += 4) {
+ bm.erase((x+y) % 8 ? SK_ColorRED : SK_ColorGREEN, SkIRect::MakeXYWH(x, y, 4, 4));
+ }
+ }
+
+ int size = etc1_get_encoded_data_size(bm.width(), bm.height());
+ fETC1Data.reset(size);
+
+ unsigned char* pixels = (unsigned char*) fETC1Data.get();
+
+ if (etc1_encode_image((unsigned char*) bm.getAddr16(0, 0),
+ bm.width(), bm.height(), 2, bm.rowBytes(), pixels)) {
+ fETC1Data.reset();
+ }
+ }
+
+ void onDraw(SkCanvas* canvas) override {
+ GrRenderTargetContext* renderTargetContext =
+ canvas->internal_private_accessTopLayerRenderTargetContext();
+ if (!renderTargetContext) {
+ skiagm::GM::DrawGpuOnlyMessage(canvas);
+ return;
+ }
+
+ GrContext* context = canvas->getGrContext();
+ if (!context) {
+ 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);
+
+ renderTargetContext->priv().testingOnly_addDrawOp(
+ GrFillRectOp::Make(context, std::move(grPaint), GrAAType::kNone, SkMatrix::I(), rect));
+ }
+
+private:
+ static const int kPad = 8;
+ static const int kTexWidth = 16;
+ static const int kTexHeight = 20;
+
+ SkAutoTMalloc<char> fETC1Data;
+
+ typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+DEF_GM(return new ETC1GM;)
+
+#endif