| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/containers/small_map.h" | 8 #include "base/containers/small_map.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "gpu/perftests/measurements.h" | 13 #include "gpu/perftests/measurements.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "testing/perf/perf_test.h" | 16 #include "testing/perf/perf_test.h" |
| 17 #include "ui/gfx/geometry/size.h" | 17 #include "ui/gfx/geometry/size.h" |
| 18 #include "ui/gfx/geometry/vector2d_f.h" | 18 #include "ui/gfx/geometry/vector2d_f.h" |
| 19 #include "ui/gl/gl_bindings.h" | 19 #include "ui/gl/gl_bindings.h" |
| 20 #include "ui/gl/gl_context.h" | 20 #include "ui/gl/gl_context.h" |
| 21 #include "ui/gl/gl_enums.h" | 21 #include "ui/gl/gl_enums.h" |
| 22 #include "ui/gl/gl_surface.h" | 22 #include "ui/gl/gl_surface.h" |
| 23 #include "ui/gl/gl_version_info.h" |
| 23 #include "ui/gl/gpu_timing.h" | 24 #include "ui/gl/gpu_timing.h" |
| 24 #include "ui/gl/scoped_make_current.h" | 25 #include "ui/gl/scoped_make_current.h" |
| 25 | 26 |
| 26 namespace gpu { | 27 namespace gpu { |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 const int kUploadPerfWarmupRuns = 10; | 30 const int kUploadPerfWarmupRuns = 5; |
| 30 const int kUploadPerfTestRuns = 100; | 31 const int kUploadPerfTestRuns = 30; |
| 31 | 32 |
| 32 #define SHADER(Src) #Src | 33 #define SHADER(Src) #Src |
| 33 | 34 |
| 34 // clang-format off | 35 // clang-format off |
| 35 const char kVertexShader[] = | 36 const char kVertexShader[] = |
| 36 SHADER( | 37 SHADER( |
| 37 uniform vec2 translation; | 38 uniform vec2 translation; |
| 38 attribute vec2 a_position; | 39 attribute vec2 a_position; |
| 39 attribute vec2 a_texCoord; | 40 attribute vec2 a_texCoord; |
| 40 varying vec2 v_texCoord; | 41 varying vec2 v_texCoord; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 int rgba_stride = size.width() * GLFormatBytePerPixel(GL_RGBA); | 120 int rgba_stride = size.width() * GLFormatBytePerPixel(GL_RGBA); |
| 120 for (int y = 0; y < size.height(); ++y) { | 121 for (int y = 0; y < size.height(); ++y) { |
| 121 for (int x = 0; x < size.width(); ++x) { | 122 for (int x = 0; x < size.width(); ++x) { |
| 122 int rgba_index = y * rgba_stride + x * GLFormatBytePerPixel(GL_RGBA); | 123 int rgba_index = y * rgba_stride + x * GLFormatBytePerPixel(GL_RGBA); |
| 123 int pixels_index = y * pixels_stride + x * bytes_per_pixel; | 124 int pixels_index = y * pixels_stride + x * bytes_per_pixel; |
| 124 uint8 expected[4] = {0}; | 125 uint8 expected[4] = {0}; |
| 125 switch (format) { | 126 switch (format) { |
| 126 case GL_LUMINANCE: // (L_t, L_t, L_t, 1) | 127 case GL_LUMINANCE: // (L_t, L_t, L_t, 1) |
| 127 expected[1] = pixels[pixels_index]; | 128 expected[1] = pixels[pixels_index]; |
| 128 expected[2] = pixels[pixels_index]; | 129 expected[2] = pixels[pixels_index]; |
| 129 case GL_RED_EXT: // (R_t, 0, 0, 1)n | 130 case GL_RED: // (R_t, 0, 0, 1) |
| 130 expected[0] = pixels[pixels_index]; | 131 expected[0] = pixels[pixels_index]; |
| 131 expected[3] = 255; | 132 expected[3] = 255; |
| 132 break; | 133 break; |
| 133 case GL_RGBA: // (R_t, G_t, B_t, A_t) | 134 case GL_RGBA: // (R_t, G_t, B_t, A_t) |
| 134 memcpy(expected, &pixels[pixels_index], 4); | 135 memcpy(expected, &pixels[pixels_index], 4); |
| 135 break; | 136 break; |
| 136 default: | 137 default: |
| 137 NOTREACHED(); | 138 NOTREACHED(); |
| 138 } | 139 } |
| 139 if (memcmp(&rgba[rgba_index], expected, 4)) { | 140 if (memcmp(&rgba[rgba_index], expected, 4)) { |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 GLint translation_location_ = -1; | 380 GLint translation_location_ = -1; |
| 380 GLuint vertex_buffer_ = 0; | 381 GLuint vertex_buffer_ = 0; |
| 381 }; | 382 }; |
| 382 | 383 |
| 383 // Perf test that generates, uploads and draws a texture on a surface repeatedly | 384 // Perf test that generates, uploads and draws a texture on a surface repeatedly |
| 384 // and prints out aggregated measurements for all the runs. | 385 // and prints out aggregated measurements for all the runs. |
| 385 TEST_F(TextureUploadPerfTest, glTexImage2d) { | 386 TEST_F(TextureUploadPerfTest, glTexImage2d) { |
| 386 int sizes[] = {21, 128, 256, 512, 1024}; | 387 int sizes[] = {21, 128, 256, 512, 1024}; |
| 387 std::vector<GLenum> formats; | 388 std::vector<GLenum> formats; |
| 388 formats.push_back(GL_RGBA); | 389 formats.push_back(GL_RGBA); |
| 389 // Used by default for ResourceProvider::yuv_resource_format_. | 390 |
| 390 formats.push_back(GL_LUMINANCE); | 391 if (!gl_context_->GetVersionInfo()->is_es3) { |
| 392 // Used by default for ResourceProvider::yuv_resource_format_. |
| 393 formats.push_back(GL_LUMINANCE); |
| 394 } |
| 391 | 395 |
| 392 ui::ScopedMakeCurrent smc(gl_context_.get(), surface_.get()); | 396 ui::ScopedMakeCurrent smc(gl_context_.get(), surface_.get()); |
| 393 bool has_texture_rg = gl_context_->HasExtension("GL_EXT_texture_rg") || | 397 const bool has_texture_rg = gl_context_->GetVersionInfo()->is_es3 || |
| 394 gl_context_->HasExtension("GL_ARB_texture_rg"); | 398 gl_context_->HasExtension("GL_EXT_texture_rg") || |
| 399 gl_context_->HasExtension("GL_ARB_texture_rg"); |
| 395 | 400 |
| 396 if (has_texture_rg) { | 401 if (has_texture_rg) { |
| 397 // Used as ResourceProvider::yuv_resource_format_ if | 402 // Used as ResourceProvider::yuv_resource_format_ if |
| 398 // {ARB,EXT}_texture_rg are available. | 403 // {ARB,EXT}_texture_rg are available. |
| 399 formats.push_back(GL_RED_EXT); | 404 formats.push_back(GL_RED); |
| 400 } | 405 } |
| 401 for (int side : sizes) { | 406 for (int side : sizes) { |
| 402 ASSERT_GE(fbo_size_.width(), side); | 407 ASSERT_GE(fbo_size_.width(), side); |
| 403 ASSERT_GE(fbo_size_.height(), side); | 408 ASSERT_GE(fbo_size_.height(), side); |
| 404 gfx::Size size(side, side); | 409 gfx::Size size(side, side); |
| 405 GenerateVertexBuffer(size); | 410 GenerateVertexBuffer(size); |
| 406 for (GLenum format : formats) { | 411 for (GLenum format : formats) { |
| 407 RunUploadAndDrawMultipleTimes(size, format); | 412 RunUploadAndDrawMultipleTimes(size, format); |
| 408 } | 413 } |
| 409 } | 414 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 gpu_timing_client_->CheckAndResetTimerErrors(); | 477 gpu_timing_client_->CheckAndResetTimerErrors(); |
| 473 if (!gpu_timer_errors) { | 478 if (!gpu_timer_errors) { |
| 474 upload_and_draw_timers.GetAsMeasurement("upload_and_draw") | 479 upload_and_draw_timers.GetAsMeasurement("upload_and_draw") |
| 475 .PrintResult("renaming"); | 480 .PrintResult("renaming"); |
| 476 finish_timers.GetAsMeasurement("finish").PrintResult("renaming"); | 481 finish_timers.GetAsMeasurement("finish").PrintResult("renaming"); |
| 477 } | 482 } |
| 478 } | 483 } |
| 479 | 484 |
| 480 } // namespace | 485 } // namespace |
| 481 } // namespace gpu | 486 } // namespace gpu |
| OLD | NEW |