Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(644)

Unified Diff: tests/ImageGeneratorTest.cpp

Issue 1862133002: Add whitelist parameter to refEncodedData (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/SkGrPriv.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ImageGeneratorTest.cpp
diff --git a/tests/ImageGeneratorTest.cpp b/tests/ImageGeneratorTest.cpp
index 3d750b2c7327cc909ba78fa5911d7c711a4c4ed5..3924b3d794dcc67aa9166c4425031ce2710065ff 100644
--- a/tests/ImageGeneratorTest.cpp
+++ b/tests/ImageGeneratorTest.cpp
@@ -71,3 +71,108 @@ DEF_TEST(ImageGenerator, reporter) {
test_imagegenerator_factory(reporter);
}
}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+#if SK_SUPPORT_GPU
+#include "GrCaps.h"
+#include "GrContext.h"
+#include "Resources.h"
+#include "SkImageCacherator.h"
+
+namespace {
+
+// FIXME: We do not currently have an SkImageGenerator that supports KTX, PKM, or ASTC. (We
+// used to support them with SkImageDecoder, which has been deleted. We have not yet ported
+// them to SkCodec: skbug.com/4971) For now, use a dummy class which still allows retrieving
+// the encoded data.
+class DummyGenerator final : public SkImageGenerator {
+public:
+ DummyGenerator(sk_sp<SkData> data, SkEncodedFormat format)
+ : INHERITED(SkImageInfo::MakeUnknown(1, 1))
+ , fData(std::move(data))
+ , fFormat(format)
+ {}
+protected:
+ SkData* onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM) override {
+#ifndef SK_SUPPORT_LEGACY_REFENCODEDDATA_NOCTX
+ if (whitelist && !whitelist->includes(fFormat)) {
+ return nullptr;
+ }
+#endif
+ return SkRef(fData.get());
+ }
+
+#ifdef SK_SUPPORT_LEGACY_REFENCODEDDATA_NOCTX
+ // This is just here to avoid a build error that fFormat is unused
+ // when SK_SUPPORT_LEGACY_REFENCODEDDATA_NOCTX is defined.
+ SkEncodedFormat format() const { return fFormat;}
+#endif
+private:
+ const sk_sp<SkData> fData;
+ const SkEncodedFormat fFormat;
+
+ typedef SkImageGenerator INHERITED;
+};
+
+} // anonymous namespace
+
+DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ImageGenerator_refEncodedData, reporter, ctxInfo) {
+ const struct {
+ const char* fName;
+ SkEncodedFormat fFormat;
+ GrPixelConfig fConfig; // compressed config or kUnknown
+ } recs[] = {
+ { "mandrill_128.ktx", kKTX_SkEncodedFormat, kETC1_GrPixelConfig },
+ { "mandrill_128.pkm", kPKM_SkEncodedFormat, kETC1_GrPixelConfig },
+ { "mandrill_132x132_12x12.astc", kASTC_SkEncodedFormat, kASTC_12x12_GrPixelConfig },
+
+ // These have no compressed gpu config, so we expected them to not be supported (on gpu)
+ { "mandrill_128.png", kPNG_SkEncodedFormat, kUnknown_GrPixelConfig },
+ { "mandrill_128x128_4x4.astc", kASTC_SkEncodedFormat, kUnknown_GrPixelConfig },
+ };
+
+ GrContext* context = ctxInfo.fGrContext;
+ SkGpuFormatWhitelist whitelist(context);
+ const GrCaps* caps = context->caps();
+
+ for (const auto& r : recs) {
+ sk_sp<SkData> data(SkData::MakeFromFileName(GetResourcePath(r.fName).c_str()));
+ if (!data) {
+ SkDebugf("----- could not find resource %s\n", r.fName);
+ continue;
+ }
+ SkImageGenerator* gen = SkImageGenerator::NewFromEncoded(data.get());
+ if (!gen) {
+ gen = new DummyGenerator(data, r.fFormat);
+ }
+ SkAutoTDelete<SkImageCacherator> cacher(SkImageCacherator::NewFromGenerator(gen));
+
+ // we expect ALL formats to be supported on cpu
+ sk_sp<SkData> encData(cacher->refEncoded(nullptr));
+ bool cacherSupported = encData != nullptr;
+ REPORTER_ASSERT(reporter, cacherSupported);
+
+ // now test gpu
+ const bool capsSupported = caps->isConfigTexturable(r.fConfig);
+
+ encData.reset(cacher->refEncoded(context));
+ cacherSupported = encData != nullptr;
+ // test the internal whitelist subclass
+ bool formatSupported = whitelist.includes(r.fFormat);
+
+#ifndef SK_SUPPORT_LEGACY_REFENCODEDDATA_NOCTX
+ REPORTER_ASSERT(reporter, cacherSupported == capsSupported);
+#endif
+ // format support is hard, since (for example) KTX format may contain different configs.
+ // Hence we only require that if a format is supported, then the caps must agree.
+ if (formatSupported) {
+ REPORTER_ASSERT(reporter, capsSupported);
+ }
+
+ if (false) { // used for testing
+ SkDebugf("caps=%d cacher=%d format=%d file=%s\n",
+ capsSupported, cacherSupported, formatSupported, r.fName);
+ }
+ }
+}
+#endif
« no previous file with comments | « src/gpu/SkGrPriv.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698