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

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: Make test pass regardless of CTX build flag 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
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 static SkImageGenerator* new_from_encoded(sk_sp<SkData> data) {
83 SkASSERT(data);
84
85 SkImageGenerator* gen = SkImageGenerator::NewFromEncoded(data.get());
86 if (gen) {
87 return gen;
88 }
89
90 // FIXME: We do not currently have an SkImageGenerator that supports KTX, PK M, or ASTC. (We
91 // used to support them with SkImageDecoder, which has been deleted. We have not yet ported
92 // them to SkCodec: skbug.com/4971) For now, use a dummy class which still a llows retrieving
93 // the encoded data.
94 class DummyGenerator final : public SkImageGenerator {
95 public:
96 DummyGenerator(sk_sp<SkData> data)
97 : INHERITED(SkImageInfo::MakeUnknown(1, 1))
98 , fData(std::move(data))
99 {}
100 protected:
101 SkData* onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM) override {
102 #ifndef SK_SUPPORT_LEGACY_REFENCODEDDATA_NOCTX
103 if (query) {
104 if (!query->supportedFormatFromData(fData->data(), fData->size() )) {
105 return nullptr;
106 }
107 }
108 #endif
109 return SkRef(fData.get());
110 }
111 private:
112 sk_sp<SkData> fData;
113 typedef SkImageGenerator INHERITED;
114 };
115
116 return new DummyGenerator(data);
117 }
118
119 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageGenerator_refEncodedData, reporter, ctxI nfo) {
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 SkEncodedFormatQuery_Gpu query(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 = new_from_encoded(data);
145 SkAutoTDelete<SkImageCacherator> cacher(SkImageCacherator::NewFromGenera tor(gen));
146
147 // we expect ALL formats to be supported on cpu
148 sk_sp<SkData> encData(cacher->refEncoded(nullptr));
149 bool cacherSupported = encData != nullptr;
150 REPORTER_ASSERT(reporter, cacherSupported);
151
152 // now test gpu
153 const bool capsSupported = caps->isConfigTexturable(r.fConfig);
154
155 encData.reset(cacher->refEncoded(context));
156 cacherSupported = encData != nullptr;
157 // test the internal query subclass
158 bool formatSupported = query.supportedFormat(r.fFormat);
159 bool dataSupported = query.supportedFormatFromData(data->data(), data->s ize());
160
161 #ifndef SK_SUPPORT_LEGACY_REFENCODEDDATA_NOCTX
162 REPORTER_ASSERT(reporter, cacherSupported == capsSupported);
163 #endif
164 REPORTER_ASSERT(reporter, dataSupported == capsSupported);
165 // format support is harder, since (for example) KTX format may contain may different
166 // configs. Hence we only require that if a format is supported, then th e caps must agree.
167 if (formatSupported) {
168 REPORTER_ASSERT(reporter, capsSupported);
169 }
170
171 if (false) { // used for testing
172 SkDebugf("caps=%d cacher=%d format=%d data=%d file=%s\n",
173 capsSupported, cacherSupported, formatSupported, dataSuppor ted, r.fName);
174 }
175 }
176 }
177 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698