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