OLD | NEW |
| (Empty) |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/json/json_reader.h" | |
6 #include "base/memory/ref_counted_memory.h" | |
7 #include "base/run_loop.h" | |
8 #include "base/strings/stringprintf.h" | |
9 #include "base/test/launcher/unit_test_launcher.h" | |
10 #include "base/test/test_suite.h" | |
11 #include "components/display_compositor/gl_helper.h" | |
12 #include "gpu/command_buffer/client/gl_in_process_context.h" | |
13 #include "gpu/command_buffer/client/gles2_implementation.h" | |
14 #include "media/base/video_frame.h" | |
15 #include "media/base/video_util.h" | |
16 #include "testing/gtest/include/gtest/gtest.h" | |
17 #include "third_party/skia/include/core/SkBitmap.h" | |
18 #include "ui/gl/gl_implementation.h" | |
19 | |
20 namespace display_compositor { | |
21 | |
22 namespace { | |
23 int kYUVReadbackSizes[] = {2, 4, 14}; | |
24 } | |
25 | |
26 class YUVReadbackTest : public testing::Test { | |
27 protected: | |
28 void SetUp() override { | |
29 gpu::gles2::ContextCreationAttribHelper attributes; | |
30 attributes.alpha_size = 8; | |
31 attributes.depth_size = 24; | |
32 attributes.red_size = 8; | |
33 attributes.green_size = 8; | |
34 attributes.blue_size = 8; | |
35 attributes.stencil_size = 8; | |
36 attributes.samples = 4; | |
37 attributes.sample_buffers = 1; | |
38 attributes.bind_generates_resource = false; | |
39 | |
40 context_.reset(gpu::GLInProcessContext::Create( | |
41 nullptr, /* service */ | |
42 nullptr, /* surface */ | |
43 true, /* offscreen */ | |
44 gfx::kNullAcceleratedWidget, /* window */ | |
45 gfx::Size(1, 1), /* size */ | |
46 nullptr, /* share_context */ | |
47 attributes, gfx::PreferDiscreteGpu, | |
48 ::gpu::GLInProcessContextSharedMemoryLimits(), | |
49 nullptr, /* gpu_memory_buffer_manager */ | |
50 nullptr /* image_factory */)); | |
51 gl_ = context_->GetImplementation(); | |
52 gpu::ContextSupport* support = context_->GetImplementation(); | |
53 | |
54 helper_.reset(new display_compositor::GLHelper(gl_, support)); | |
55 } | |
56 | |
57 void TearDown() override { | |
58 helper_.reset(NULL); | |
59 context_.reset(NULL); | |
60 } | |
61 | |
62 void StartTracing(const std::string& filter) { | |
63 base::trace_event::TraceLog::GetInstance()->SetEnabled( | |
64 base::trace_event::TraceConfig(filter, | |
65 base::trace_event::RECORD_UNTIL_FULL), | |
66 base::trace_event::TraceLog::RECORDING_MODE); | |
67 } | |
68 | |
69 static void TraceDataCB( | |
70 const base::Callback<void()>& callback, | |
71 std::string* output, | |
72 const scoped_refptr<base::RefCountedString>& json_events_str, | |
73 bool has_more_events) { | |
74 if (output->size() > 1 && !json_events_str->data().empty()) { | |
75 output->append(","); | |
76 } | |
77 output->append(json_events_str->data()); | |
78 if (!has_more_events) { | |
79 callback.Run(); | |
80 } | |
81 } | |
82 | |
83 // End tracing, return tracing data in a simple map | |
84 // of event name->counts. | |
85 void EndTracing(std::map<std::string, int>* event_counts) { | |
86 std::string json_data = "["; | |
87 base::trace_event::TraceLog::GetInstance()->SetDisabled(); | |
88 base::RunLoop run_loop; | |
89 base::trace_event::TraceLog::GetInstance()->Flush( | |
90 base::Bind(&YUVReadbackTest::TraceDataCB, run_loop.QuitClosure(), | |
91 base::Unretained(&json_data))); | |
92 run_loop.Run(); | |
93 json_data.append("]"); | |
94 | |
95 std::string error_msg; | |
96 std::unique_ptr<base::Value> trace_data = | |
97 base::JSONReader::ReadAndReturnError(json_data, 0, NULL, &error_msg); | |
98 CHECK(trace_data) << "JSON parsing failed (" << error_msg | |
99 << ") JSON data:" << std::endl | |
100 << json_data; | |
101 | |
102 base::ListValue* list; | |
103 CHECK(trace_data->GetAsList(&list)); | |
104 for (size_t i = 0; i < list->GetSize(); i++) { | |
105 base::Value* item = NULL; | |
106 if (list->Get(i, &item)) { | |
107 base::DictionaryValue* dict; | |
108 CHECK(item->GetAsDictionary(&dict)); | |
109 std::string name; | |
110 CHECK(dict->GetString("name", &name)); | |
111 std::string trace_type; | |
112 CHECK(dict->GetString("ph", &trace_type)); | |
113 // Count all except END traces, as they come in BEGIN/END pairs. | |
114 if (trace_type != "E" && trace_type != "e") | |
115 (*event_counts)[name]++; | |
116 VLOG(1) << "trace name: " << name; | |
117 } | |
118 } | |
119 } | |
120 | |
121 // Look up a single channel value. Works for 4-channel and single channel | |
122 // bitmaps. Clamp x/y. | |
123 int Channel(SkBitmap* pixels, int x, int y, int c) { | |
124 if (pixels->bytesPerPixel() == 4) { | |
125 uint32_t* data = | |
126 pixels->getAddr32(std::max(0, std::min(x, pixels->width() - 1)), | |
127 std::max(0, std::min(y, pixels->height() - 1))); | |
128 return (*data) >> (c * 8) & 0xff; | |
129 } else { | |
130 DCHECK_EQ(pixels->bytesPerPixel(), 1); | |
131 DCHECK_EQ(c, 0); | |
132 return *pixels->getAddr8(std::max(0, std::min(x, pixels->width() - 1)), | |
133 std::max(0, std::min(y, pixels->height() - 1))); | |
134 } | |
135 } | |
136 | |
137 // Set a single channel value. Works for 4-channel and single channel | |
138 // bitmaps. Clamp x/y. | |
139 void SetChannel(SkBitmap* pixels, int x, int y, int c, int v) { | |
140 DCHECK_GE(x, 0); | |
141 DCHECK_GE(y, 0); | |
142 DCHECK_LT(x, pixels->width()); | |
143 DCHECK_LT(y, pixels->height()); | |
144 if (pixels->bytesPerPixel() == 4) { | |
145 uint32_t* data = pixels->getAddr32(x, y); | |
146 v = std::max(0, std::min(v, 255)); | |
147 *data = (*data & ~(0xffu << (c * 8))) | (v << (c * 8)); | |
148 } else { | |
149 DCHECK_EQ(pixels->bytesPerPixel(), 1); | |
150 DCHECK_EQ(c, 0); | |
151 uint8_t* data = pixels->getAddr8(x, y); | |
152 v = std::max(0, std::min(v, 255)); | |
153 *data = v; | |
154 } | |
155 } | |
156 | |
157 // Print all the R, G, B or A values from an SkBitmap in a | |
158 // human-readable format. | |
159 void PrintChannel(SkBitmap* pixels, int c) { | |
160 for (int y = 0; y < pixels->height(); y++) { | |
161 std::string formatted; | |
162 for (int x = 0; x < pixels->width(); x++) { | |
163 formatted.append(base::StringPrintf("%3d, ", Channel(pixels, x, y, c))); | |
164 } | |
165 LOG(ERROR) << formatted; | |
166 } | |
167 } | |
168 | |
169 // Get a single R, G, B or A value as a float. | |
170 float ChannelAsFloat(SkBitmap* pixels, int x, int y, int c) { | |
171 return Channel(pixels, x, y, c) / 255.0; | |
172 } | |
173 | |
174 // Works like a GL_LINEAR lookup on an SkBitmap. | |
175 float Bilinear(SkBitmap* pixels, float x, float y, int c) { | |
176 x -= 0.5; | |
177 y -= 0.5; | |
178 int base_x = static_cast<int>(floorf(x)); | |
179 int base_y = static_cast<int>(floorf(y)); | |
180 x -= base_x; | |
181 y -= base_y; | |
182 return (ChannelAsFloat(pixels, base_x, base_y, c) * (1 - x) * (1 - y) + | |
183 ChannelAsFloat(pixels, base_x + 1, base_y, c) * x * (1 - y) + | |
184 ChannelAsFloat(pixels, base_x, base_y + 1, c) * (1 - x) * y + | |
185 ChannelAsFloat(pixels, base_x + 1, base_y + 1, c) * x * y); | |
186 } | |
187 | |
188 void FlipSKBitmap(SkBitmap* bitmap) { | |
189 int bpp = bitmap->bytesPerPixel(); | |
190 DCHECK(bpp == 4 || bpp == 1); | |
191 int top_line = 0; | |
192 int bottom_line = bitmap->height() - 1; | |
193 while (top_line < bottom_line) { | |
194 for (int x = 0; x < bitmap->width(); x++) { | |
195 bpp == 4 ? std::swap(*bitmap->getAddr32(x, top_line), | |
196 *bitmap->getAddr32(x, bottom_line)) | |
197 : std::swap(*bitmap->getAddr8(x, top_line), | |
198 *bitmap->getAddr8(x, bottom_line)); | |
199 } | |
200 top_line++; | |
201 bottom_line--; | |
202 } | |
203 } | |
204 | |
205 // Note: Left/Right means Top/Bottom when used for Y dimension. | |
206 enum Margin { | |
207 MarginLeft, | |
208 MarginMiddle, | |
209 MarginRight, | |
210 MarginInvalid, | |
211 }; | |
212 | |
213 static Margin NextMargin(Margin m) { | |
214 switch (m) { | |
215 case MarginLeft: | |
216 return MarginMiddle; | |
217 case MarginMiddle: | |
218 return MarginRight; | |
219 case MarginRight: | |
220 return MarginInvalid; | |
221 default: | |
222 return MarginInvalid; | |
223 } | |
224 } | |
225 | |
226 int compute_margin(int insize, int outsize, Margin m) { | |
227 int available = outsize - insize; | |
228 switch (m) { | |
229 default: | |
230 EXPECT_TRUE(false) << "This should not happen."; | |
231 return 0; | |
232 case MarginLeft: | |
233 return 0; | |
234 case MarginMiddle: | |
235 return (available / 2) & ~1; | |
236 case MarginRight: | |
237 return available; | |
238 } | |
239 } | |
240 | |
241 // Convert 0.0 - 1.0 to 0 - 255 | |
242 int float_to_byte(float v) { | |
243 int ret = static_cast<int>(floorf(v * 255.0f + 0.5f)); | |
244 if (ret < 0) { | |
245 return 0; | |
246 } | |
247 if (ret > 255) { | |
248 return 255; | |
249 } | |
250 return ret; | |
251 } | |
252 | |
253 static void callcallback(const base::Callback<void()>& callback, | |
254 bool result) { | |
255 callback.Run(); | |
256 } | |
257 | |
258 void PrintPlane(unsigned char* plane, int xsize, int stride, int ysize) { | |
259 for (int y = 0; y < ysize; y++) { | |
260 std::string formatted; | |
261 for (int x = 0; x < xsize; x++) { | |
262 formatted.append(base::StringPrintf("%3d, ", plane[y * stride + x])); | |
263 } | |
264 LOG(ERROR) << formatted << " (" << (plane + y * stride) << ")"; | |
265 } | |
266 } | |
267 | |
268 // Compare two planes make sure that each component of each pixel | |
269 // is no more than |maxdiff| apart. | |
270 void ComparePlane(unsigned char* truth, | |
271 int truth_stride, | |
272 unsigned char* other, | |
273 int other_stride, | |
274 int maxdiff, | |
275 int xsize, | |
276 int ysize, | |
277 SkBitmap* source, | |
278 std::string message) { | |
279 for (int x = 0; x < xsize; x++) { | |
280 for (int y = 0; y < ysize; y++) { | |
281 int a = other[y * other_stride + x]; | |
282 int b = truth[y * truth_stride + x]; | |
283 EXPECT_NEAR(a, b, maxdiff) << " x=" << x << " y=" << y << " " | |
284 << message; | |
285 if (std::abs(a - b) > maxdiff) { | |
286 LOG(ERROR) << "-------expected--------"; | |
287 PrintPlane(truth, xsize, truth_stride, ysize); | |
288 LOG(ERROR) << "-------actual--------"; | |
289 PrintPlane(other, xsize, other_stride, ysize); | |
290 if (source) { | |
291 LOG(ERROR) << "-------before yuv conversion: red--------"; | |
292 PrintChannel(source, 0); | |
293 LOG(ERROR) << "-------before yuv conversion: green------"; | |
294 PrintChannel(source, 1); | |
295 LOG(ERROR) << "-------before yuv conversion: blue-------"; | |
296 PrintChannel(source, 2); | |
297 } | |
298 return; | |
299 } | |
300 } | |
301 } | |
302 } | |
303 | |
304 // YUV readback test. Create a test pattern, convert to YUV | |
305 // with reference implementation and compare to what gl_helper | |
306 // returns. | |
307 void TestYUVReadback(int xsize, | |
308 int ysize, | |
309 int output_xsize, | |
310 int output_ysize, | |
311 int xmargin, | |
312 int ymargin, | |
313 int test_pattern, | |
314 bool flip, | |
315 bool use_mrt, | |
316 display_compositor::GLHelper::ScalerQuality quality) { | |
317 GLuint src_texture; | |
318 gl_->GenTextures(1, &src_texture); | |
319 SkBitmap input_pixels; | |
320 input_pixels.allocN32Pixels(xsize, ysize); | |
321 | |
322 for (int x = 0; x < xsize; ++x) { | |
323 for (int y = 0; y < ysize; ++y) { | |
324 switch (test_pattern) { | |
325 case 0: // Smooth test pattern | |
326 SetChannel(&input_pixels, x, y, 0, x * 10); | |
327 SetChannel(&input_pixels, x, y, 1, y * 10); | |
328 SetChannel(&input_pixels, x, y, 2, (x + y) * 10); | |
329 SetChannel(&input_pixels, x, y, 3, 255); | |
330 break; | |
331 case 1: // Small blocks | |
332 SetChannel(&input_pixels, x, y, 0, x & 1 ? 255 : 0); | |
333 SetChannel(&input_pixels, x, y, 1, y & 1 ? 255 : 0); | |
334 SetChannel(&input_pixels, x, y, 2, (x + y) & 1 ? 255 : 0); | |
335 SetChannel(&input_pixels, x, y, 3, 255); | |
336 break; | |
337 case 2: // Medium blocks | |
338 SetChannel(&input_pixels, x, y, 0, 10 + x / 2 * 50); | |
339 SetChannel(&input_pixels, x, y, 1, 10 + y / 3 * 50); | |
340 SetChannel(&input_pixels, x, y, 2, (x + y) / 5 * 50 + 5); | |
341 SetChannel(&input_pixels, x, y, 3, 255); | |
342 break; | |
343 } | |
344 } | |
345 } | |
346 | |
347 gl_->BindTexture(GL_TEXTURE_2D, src_texture); | |
348 gl_->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, xsize, ysize, 0, GL_RGBA, | |
349 GL_UNSIGNED_BYTE, input_pixels.getPixels()); | |
350 | |
351 gpu::Mailbox mailbox; | |
352 gl_->GenMailboxCHROMIUM(mailbox.name); | |
353 EXPECT_FALSE(mailbox.IsZero()); | |
354 gl_->ProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | |
355 const GLuint64 fence_sync = gl_->InsertFenceSyncCHROMIUM(); | |
356 gl_->ShallowFlushCHROMIUM(); | |
357 | |
358 gpu::SyncToken sync_token; | |
359 gl_->GenSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); | |
360 | |
361 std::string message = base::StringPrintf( | |
362 "input size: %dx%d " | |
363 "output size: %dx%d " | |
364 "margin: %dx%d " | |
365 "pattern: %d %s %s", | |
366 xsize, ysize, output_xsize, output_ysize, xmargin, ymargin, | |
367 test_pattern, flip ? "flip" : "noflip", flip ? "mrt" : "nomrt"); | |
368 std::unique_ptr<ReadbackYUVInterface> yuv_reader( | |
369 helper_->CreateReadbackPipelineYUV( | |
370 quality, gfx::Size(xsize, ysize), gfx::Rect(0, 0, xsize, ysize), | |
371 gfx::Size(xsize, ysize), flip, use_mrt)); | |
372 | |
373 scoped_refptr<media::VideoFrame> output_frame = | |
374 media::VideoFrame::CreateFrame( | |
375 media::PIXEL_FORMAT_YV12, | |
376 // The coded size of the output frame is rounded up to the next | |
377 // 16-byte boundary. This tests that the readback is being | |
378 // positioned inside the frame's visible region, and not dependent | |
379 // on its coded size. | |
380 gfx::Size((output_xsize + 15) & ~15, (output_ysize + 15) & ~15), | |
381 gfx::Rect(0, 0, output_xsize, output_ysize), | |
382 gfx::Size(output_xsize, output_ysize), | |
383 base::TimeDelta::FromSeconds(0)); | |
384 scoped_refptr<media::VideoFrame> truth_frame = | |
385 media::VideoFrame::CreateFrame( | |
386 media::PIXEL_FORMAT_YV12, gfx::Size(output_xsize, output_ysize), | |
387 gfx::Rect(0, 0, output_xsize, output_ysize), | |
388 gfx::Size(output_xsize, output_ysize), | |
389 base::TimeDelta::FromSeconds(0)); | |
390 | |
391 base::RunLoop run_loop; | |
392 yuv_reader->ReadbackYUV(mailbox, sync_token, output_frame->visible_rect(), | |
393 output_frame->stride(media::VideoFrame::kYPlane), | |
394 output_frame->data(media::VideoFrame::kYPlane), | |
395 output_frame->stride(media::VideoFrame::kUPlane), | |
396 output_frame->data(media::VideoFrame::kUPlane), | |
397 output_frame->stride(media::VideoFrame::kVPlane), | |
398 output_frame->data(media::VideoFrame::kVPlane), | |
399 gfx::Point(xmargin, ymargin), | |
400 base::Bind(&callcallback, run_loop.QuitClosure())); | |
401 | |
402 const gfx::Rect paste_rect(gfx::Point(xmargin, ymargin), | |
403 gfx::Size(xsize, ysize)); | |
404 media::LetterboxYUV(output_frame.get(), paste_rect); | |
405 run_loop.Run(); | |
406 | |
407 if (flip) { | |
408 FlipSKBitmap(&input_pixels); | |
409 } | |
410 | |
411 unsigned char* Y = truth_frame->visible_data(media::VideoFrame::kYPlane); | |
412 unsigned char* U = truth_frame->visible_data(media::VideoFrame::kUPlane); | |
413 unsigned char* V = truth_frame->visible_data(media::VideoFrame::kVPlane); | |
414 int32_t y_stride = truth_frame->stride(media::VideoFrame::kYPlane); | |
415 int32_t u_stride = truth_frame->stride(media::VideoFrame::kUPlane); | |
416 int32_t v_stride = truth_frame->stride(media::VideoFrame::kVPlane); | |
417 memset(Y, 0x00, y_stride * output_ysize); | |
418 memset(U, 0x80, u_stride * output_ysize / 2); | |
419 memset(V, 0x80, v_stride * output_ysize / 2); | |
420 | |
421 const float kRGBtoYColorWeights[] = {0.257f, 0.504f, 0.098f, 0.0625f}; | |
422 const float kRGBtoUColorWeights[] = {-0.148f, -0.291f, 0.439f, 0.5f}; | |
423 const float kRGBtoVColorWeights[] = {0.439f, -0.368f, -0.071f, 0.5f}; | |
424 | |
425 for (int y = 0; y < ysize; y++) { | |
426 for (int x = 0; x < xsize; x++) { | |
427 Y[(y + ymargin) * y_stride + x + xmargin] = float_to_byte( | |
428 ChannelAsFloat(&input_pixels, x, y, 0) * kRGBtoYColorWeights[0] + | |
429 ChannelAsFloat(&input_pixels, x, y, 1) * kRGBtoYColorWeights[1] + | |
430 ChannelAsFloat(&input_pixels, x, y, 2) * kRGBtoYColorWeights[2] + | |
431 kRGBtoYColorWeights[3]); | |
432 } | |
433 } | |
434 | |
435 for (int y = 0; y < ysize / 2; y++) { | |
436 for (int x = 0; x < xsize / 2; x++) { | |
437 U[(y + ymargin / 2) * u_stride + x + xmargin / 2] = | |
438 float_to_byte(Bilinear(&input_pixels, x * 2 + 1.0, y * 2 + 1.0, 0) * | |
439 kRGBtoUColorWeights[0] + | |
440 Bilinear(&input_pixels, x * 2 + 1.0, y * 2 + 1.0, 1) * | |
441 kRGBtoUColorWeights[1] + | |
442 Bilinear(&input_pixels, x * 2 + 1.0, y * 2 + 1.0, 2) * | |
443 kRGBtoUColorWeights[2] + | |
444 kRGBtoUColorWeights[3]); | |
445 V[(y + ymargin / 2) * v_stride + x + xmargin / 2] = | |
446 float_to_byte(Bilinear(&input_pixels, x * 2 + 1.0, y * 2 + 1.0, 0) * | |
447 kRGBtoVColorWeights[0] + | |
448 Bilinear(&input_pixels, x * 2 + 1.0, y * 2 + 1.0, 1) * | |
449 kRGBtoVColorWeights[1] + | |
450 Bilinear(&input_pixels, x * 2 + 1.0, y * 2 + 1.0, 2) * | |
451 kRGBtoVColorWeights[2] + | |
452 kRGBtoVColorWeights[3]); | |
453 } | |
454 } | |
455 | |
456 ComparePlane( | |
457 Y, y_stride, output_frame->visible_data(media::VideoFrame::kYPlane), | |
458 output_frame->stride(media::VideoFrame::kYPlane), 2, output_xsize, | |
459 output_ysize, &input_pixels, message + " Y plane"); | |
460 ComparePlane( | |
461 U, u_stride, output_frame->visible_data(media::VideoFrame::kUPlane), | |
462 output_frame->stride(media::VideoFrame::kUPlane), 2, output_xsize / 2, | |
463 output_ysize / 2, &input_pixels, message + " U plane"); | |
464 ComparePlane( | |
465 V, v_stride, output_frame->visible_data(media::VideoFrame::kVPlane), | |
466 output_frame->stride(media::VideoFrame::kVPlane), 2, output_xsize / 2, | |
467 output_ysize / 2, &input_pixels, message + " V plane"); | |
468 | |
469 gl_->DeleteTextures(1, &src_texture); | |
470 } | |
471 | |
472 std::unique_ptr<gpu::GLInProcessContext> context_; | |
473 gpu::gles2::GLES2Interface* gl_; | |
474 std::unique_ptr<display_compositor::GLHelper> helper_; | |
475 gfx::DisableNullDrawGLBindings enable_pixel_output_; | |
476 }; | |
477 | |
478 TEST_F(YUVReadbackTest, YUVReadbackOptTest) { | |
479 // This test uses the gpu.service/gpu_decoder tracing events to detect how | |
480 // many scaling passes are actually performed by the YUV readback pipeline. | |
481 StartTracing(TRACE_DISABLED_BY_DEFAULT( | |
482 "gpu.service") "," TRACE_DISABLED_BY_DEFAULT("gpu_decoder")); | |
483 | |
484 TestYUVReadback(800, 400, 800, 400, 0, 0, 1, false, true, | |
485 display_compositor::GLHelper::SCALER_QUALITY_FAST); | |
486 | |
487 std::map<std::string, int> event_counts; | |
488 EndTracing(&event_counts); | |
489 int draw_buffer_calls = event_counts["kDrawBuffersEXTImmediate"]; | |
490 int draw_arrays_calls = event_counts["kDrawArrays"]; | |
491 VLOG(1) << "Draw buffer calls: " << draw_buffer_calls; | |
492 VLOG(1) << "DrawArrays calls: " << draw_arrays_calls; | |
493 | |
494 if (draw_buffer_calls) { | |
495 // When using MRT, the YUV readback code should only | |
496 // execute two draw arrays, and scaling should be integrated | |
497 // into those two calls since we are using the FAST scalign | |
498 // quality. | |
499 EXPECT_EQ(2, draw_arrays_calls); | |
500 } else { | |
501 // When not using MRT, there are three passes for the YUV, | |
502 // and one for the scaling. | |
503 EXPECT_EQ(4, draw_arrays_calls); | |
504 } | |
505 } | |
506 | |
507 class YUVReadbackPixelTest | |
508 : public YUVReadbackTest, | |
509 public ::testing::WithParamInterface< | |
510 std::tr1::tuple<bool, bool, unsigned int, unsigned int>> {}; | |
511 | |
512 TEST_P(YUVReadbackPixelTest, Test) { | |
513 bool flip = std::tr1::get<0>(GetParam()); | |
514 bool use_mrt = std::tr1::get<1>(GetParam()); | |
515 unsigned int x = std::tr1::get<2>(GetParam()); | |
516 unsigned int y = std::tr1::get<3>(GetParam()); | |
517 | |
518 for (unsigned int ox = x; ox < arraysize(kYUVReadbackSizes); ox++) { | |
519 for (unsigned int oy = y; oy < arraysize(kYUVReadbackSizes); oy++) { | |
520 // If output is a subsection of the destination frame, (letterbox) | |
521 // then try different variations of where the subsection goes. | |
522 for (Margin xm = x < ox ? MarginLeft : MarginRight; xm <= MarginRight; | |
523 xm = NextMargin(xm)) { | |
524 for (Margin ym = y < oy ? MarginLeft : MarginRight; ym <= MarginRight; | |
525 ym = NextMargin(ym)) { | |
526 for (int pattern = 0; pattern < 3; pattern++) { | |
527 TestYUVReadback( | |
528 kYUVReadbackSizes[x], kYUVReadbackSizes[y], | |
529 kYUVReadbackSizes[ox], kYUVReadbackSizes[oy], | |
530 compute_margin(kYUVReadbackSizes[x], kYUVReadbackSizes[ox], xm), | |
531 compute_margin(kYUVReadbackSizes[y], kYUVReadbackSizes[oy], ym), | |
532 pattern, flip, use_mrt, | |
533 display_compositor::GLHelper::SCALER_QUALITY_GOOD); | |
534 if (HasFailure()) { | |
535 return; | |
536 } | |
537 } | |
538 } | |
539 } | |
540 } | |
541 } | |
542 } | |
543 | |
544 // First argument is intentionally empty. | |
545 INSTANTIATE_TEST_CASE_P( | |
546 , | |
547 YUVReadbackPixelTest, | |
548 ::testing::Combine( | |
549 ::testing::Bool(), | |
550 ::testing::Bool(), | |
551 ::testing::Range<unsigned int>(0, arraysize(kYUVReadbackSizes)), | |
552 ::testing::Range<unsigned int>(0, arraysize(kYUVReadbackSizes)))); | |
553 | |
554 } // namespace display_compositor | |
OLD | NEW |