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