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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/gpu/SkGrPriv.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkData.h" 8 #include "SkData.h"
9 #include "SkGraphics.h" 9 #include "SkGraphics.h"
10 #include "SkImageGenerator.h" 10 #include "SkImageGenerator.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 sizeInfo.fWidthBytes[SkYUVSizeInfo::kV] = 250; 64 sizeInfo.fWidthBytes[SkYUVSizeInfo::kV] = 250;
65 int dummy; 65 int dummy;
66 planes[SkYUVSizeInfo::kY] = planes[SkYUVSizeInfo::kU] = planes[SkYUVSizeInfo ::kV] = &dummy; 66 planes[SkYUVSizeInfo::kY] = planes[SkYUVSizeInfo::kU] = planes[SkYUVSizeInfo ::kV] = &dummy;
67 ig.getYUV8Planes(sizeInfo, planes); 67 ig.getYUV8Planes(sizeInfo, planes);
68 68
69 // Suppressed due to https://code.google.com/p/skia/issues/detail?id=4339 69 // Suppressed due to https://code.google.com/p/skia/issues/detail?id=4339
70 if (false) { 70 if (false) {
71 test_imagegenerator_factory(reporter); 71 test_imagegenerator_factory(reporter);
72 } 72 }
73 } 73 }
74
75 //////////////////////////////////////////////////////////////////////////////// ///////////////////
76 #if SK_SUPPORT_GPU
77 #include "GrCaps.h"
78 #include "GrContext.h"
79 #include "Resources.h"
80 #include "SkImageCacherator.h"
81
82 namespace {
83
84 // FIXME: We do not currently have an SkImageGenerator that supports KTX, PKM, o r ASTC. (We
85 // used to support them with SkImageDecoder, which has been deleted. We have not yet ported
86 // them to SkCodec: skbug.com/4971) For now, use a dummy class which still allow s retrieving
87 // the encoded data.
88 class DummyGenerator final : public SkImageGenerator {
89 public:
90 DummyGenerator(sk_sp<SkData> data, SkEncodedFormat format)
91 : INHERITED(SkImageInfo::MakeUnknown(1, 1))
92 , fData(std::move(data))
93 , fFormat(format)
94 {}
95 protected:
96 SkData* onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM) override {
97 #ifndef SK_SUPPORT_LEGACY_REFENCODEDDATA_NOCTX
98 if (whitelist && !whitelist->includes(fFormat)) {
99 return nullptr;
100 }
101 #endif
102 return SkRef(fData.get());
103 }
104
105 #ifdef SK_SUPPORT_LEGACY_REFENCODEDDATA_NOCTX
106 // This is just here to avoid a build error that fFormat is unused
107 // when SK_SUPPORT_LEGACY_REFENCODEDDATA_NOCTX is defined.
108 SkEncodedFormat format() const { return fFormat;}
109 #endif
110 private:
111 const sk_sp<SkData> fData;
112 const SkEncodedFormat fFormat;
113
114 typedef SkImageGenerator INHERITED;
115 };
116
117 } // anonymous namespace
118
119 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ImageGenerator_refEncodedData, reporter, c txInfo) {
120 const struct {
121 const char* fName;
122 SkEncodedFormat fFormat;
123 GrPixelConfig fConfig; // compressed config or kUnknown
124 } recs[] = {
125 { "mandrill_128.ktx", kKTX_SkEncodedFormat, kETC1_GrPixelCon fig },
126 { "mandrill_128.pkm", kPKM_SkEncodedFormat, kETC1_GrPixelCon fig },
127 { "mandrill_132x132_12x12.astc", kASTC_SkEncodedFormat, kASTC_12x12_GrPi xelConfig },
128
129 // These have no compressed gpu config, so we expected them to not be su pported (on gpu)
130 { "mandrill_128.png", kPNG_SkEncodedFormat, kUnknown_GrPixel Config },
131 { "mandrill_128x128_4x4.astc", kASTC_SkEncodedFormat, kUnknown_GrPixel Config },
132 };
133
134 GrContext* context = ctxInfo.fGrContext;
135 SkGpuFormatWhitelist whitelist(context);
136 const GrCaps* caps = context->caps();
137
138 for (const auto& r : recs) {
139 sk_sp<SkData> data(SkData::MakeFromFileName(GetResourcePath(r.fName).c_s tr()));
140 if (!data) {
141 SkDebugf("----- could not find resource %s\n", r.fName);
142 continue;
143 }
144 SkImageGenerator* gen = SkImageGenerator::NewFromEncoded(data.get());
145 if (!gen) {
146 gen = new DummyGenerator(data, r.fFormat);
147 }
148 SkAutoTDelete<SkImageCacherator> cacher(SkImageCacherator::NewFromGenera tor(gen));
149
150 // we expect ALL formats to be supported on cpu
151 sk_sp<SkData> encData(cacher->refEncoded(nullptr));
152 bool cacherSupported = encData != nullptr;
153 REPORTER_ASSERT(reporter, cacherSupported);
154
155 // now test gpu
156 const bool capsSupported = caps->isConfigTexturable(r.fConfig);
157
158 encData.reset(cacher->refEncoded(context));
159 cacherSupported = encData != nullptr;
160 // test the internal whitelist subclass
161 bool formatSupported = whitelist.includes(r.fFormat);
162
163 #ifndef SK_SUPPORT_LEGACY_REFENCODEDDATA_NOCTX
164 REPORTER_ASSERT(reporter, cacherSupported == capsSupported);
165 #endif
166 // format support is hard, since (for example) KTX format may contain di fferent configs.
167 // Hence we only require that if a format is supported, then the caps mu st agree.
168 if (formatSupported) {
169 REPORTER_ASSERT(reporter, capsSupported);
170 }
171
172 if (false) { // used for testing
173 SkDebugf("caps=%d cacher=%d format=%d file=%s\n",
174 capsSupported, cacherSupported, formatSupported, r.fName);
175 }
176 }
177 }
178 #endif
OLDNEW
« 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