aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2017-05-22 20:14:41 +0000
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-05-22 20:14:50 +0000
commitbc262e110a7292950ce912e42de75b7573d0367e (patch)
tree3a5777eb2ab87791b487e3141d00c91b9749adf4 /gm
parentbcd8637772e3a678c744e28b4f4b2d42f8405284 (diff)
Revert "Remove compressed (ETC1) texture support from Ganesh"
This reverts commit ee26363aaae62db2a851f2873e2405a9cf7f995a. Reason for revert: Failing Google 3 roll. Original change's description: > Remove compressed (ETC1) texture support from Ganesh > > Change-Id: If4cf286df87ea87338aba47001d90a5fcc4f2667 > Reviewed-on: https://skia-review.googlesource.com/17456 > Commit-Queue: Robert Phillips <robertphillips@google.com> > Reviewed-by: Brian Salomon <bsalomon@google.com> > TBR=bsalomon@google.com,robertphillips@google.com NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Change-Id: Ie1a57187287e03600a69e374501478e93c41415c Reviewed-on: https://skia-review.googlesource.com/17527 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'gm')
-rw-r--r--gm/etc1.cpp118
1 files changed, 118 insertions, 0 deletions
diff --git a/gm/etc1.cpp b/gm/etc1.cpp
new file mode 100644
index 0000000000..cc01a0e35e
--- /dev/null
+++ b/gm/etc1.cpp
@@ -0,0 +1,118 @@
+/*
+ * 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 "GrRenderTargetContext.h"
+#include "GrRenderTargetContextPriv.h"
+#include "GrTextureProxy.h"
+#include "effects/GrSimpleTextureEffect.h"
+#include "ops/GrNonAAFillRectOp.h"
+
+// Basic test of Ganesh's ETC1 support
+class ETC1GM : public skiagm::GM {
+public:
+ ETC1GM() {
+ this->setBGColor(sk_tool_utils::color_to_565(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;
+ }
+
+ GrSurfaceDesc desc;
+ desc.fConfig = kETC1_GrPixelConfig;
+ desc.fWidth = kTexWidth;
+ desc.fHeight = kTexHeight;
+
+ sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeDeferred(context->resourceProvider(),
+ desc, SkBudgeted::kYes,
+ fETC1Data.get(), 0);
+ if (!proxy) {
+ return;
+ }
+
+ const SkMatrix trans = SkMatrix::MakeTrans(-kPad, -kPad);
+
+ sk_sp<GrFragmentProcessor> fp = GrSimpleTextureEffect::Make(context->resourceProvider(),
+ std::move(proxy),
+ nullptr, 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(GrNonAAFillRectOp::Make(
+ std::move(grPaint), SkMatrix::I(), rect, nullptr, nullptr, GrAAType::kNone));
+ }
+
+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