Skip to content

Commit

Permalink
Reland "[vr] Measure text render speed in GTest"
Browse files Browse the repository at this point in the history
This is a reland of 3bc3b8b
Original change's description:
> [vr] Measure text render speed in GTest
> 
> This change also adds a new target for performance tests in VR
> and a target for dependencies shared among vr test targets.
> 
> Bug: 772551, 774636
> Change-Id: I7de0cd8a5fcba3e71358625c1f3ebfb9bab49fba
> Reviewed-on: https://chromium-review.googlesource.com/703690
> Commit-Queue: Tibor Goldschwendt <tiborg@chromium.org>
> Reviewed-by: Scott Violet <sky@chromium.org>
> Reviewed-by: Ian Vollick <vollick@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#509419}

TBR=vollick@chromium.org,sky@chromium.org,leilei@chromium.org,cjgrant@chromium.org,tiborg@chromium.org

Bug: 772551, 774636
Change-Id: I833e6dba30885fb7a902ac222614e8ab97f9f874
Reviewed-on: https://chromium-review.googlesource.com/723726
Commit-Queue: Tibor Goldschwendt <tiborg@chromium.org>
Reviewed-by: Tibor Goldschwendt <tiborg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#509500}
  • Loading branch information
Tibor Goldschwendt authored and Commit Bot committed Oct 17, 2017
1 parent 38bb988 commit 213a422
Show file tree
Hide file tree
Showing 13 changed files with 207 additions and 86 deletions.
5 changes: 4 additions & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,10 @@ group("gn_all") {
}

if (enable_vr) {
deps += [ "//chrome/browser/vr:vr_common_unittests" ]
deps += [
"//chrome/browser/vr:vr_common_perftests",
"//chrome/browser/vr:vr_common_unittests",
]
if (is_linux && use_ozone) {
deps += [ "//chrome/browser/vr/testapp:vr_testapp" ]
}
Expand Down
68 changes: 47 additions & 21 deletions chrome/browser/vr/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,8 @@ test("vr_common_unittests") {
"service/vr_device_manager_unittest.cc",
"test/animation_utils.cc",
"test/animation_utils.h",
"test/constants.h",
"test/fake_ui_element_renderer.cc",
"test/fake_ui_element_renderer.h",
"test/gl_test_environment.cc",
"test/gl_test_environment.h",
"test/gl_test_environment_unittest.cc",
"test/mock_browser_interface.cc",
"test/mock_browser_interface.h",
Expand All @@ -239,40 +236,69 @@ test("vr_common_unittests") {
defines = [ "DEVICE_VR_IMPLEMENTATION" ]

deps = [
":vr_test_support",
"//cc:test_support",
"//mojo/common",
"//mojo/public/cpp/bindings",
"//testing/gmock",
"//ui/gfx:test_support",
"//ui/gfx/geometry",
"//ui/gl",
]

if (is_android) {
deps += [ "//ui/android:ui_java" ]
}
}

test("vr_common_perftests") {
sources = [
"test/run_all_unittests.cc",
"text_perftest.cc",
]
deps = [
":vr_test_support",
"//testing/perf",
]

if (is_android) {
deps += [ "//ui/android:ui_java" ]
}
}

source_set("vr_test_support") {
testonly = true

sources = [
"test/constants.h",
"test/gl_test_environment.cc",
"test/gl_test_environment.h",
]

public_deps = [
":vr_common",
":vr_test_pak",
"//base/test:test_support",
"//cc:test_support",
"//components/security_state/core",
"//components/toolbar:vector_icons",

# TODO(mthiesse, crbug.com/769373): Remove dependency on device/vr:fakes.
"//device/vr:fakes",
"//mojo/common",
"//mojo/edk/system",
"//mojo/public/cpp/bindings",
"//skia",
"//testing/gmock",
"//testing/gtest",
"//ui/accessibility:ax_gen",
"//ui/gl:test_support",

# TODO(mthiesse, crbug.com/769373): Remove dependency on device/vr:fakes.
"//device/vr:fakes",

# TODO(mthiesse): Figure out why these webrtc deps are necessary for compiling these tests.
# Is a dependency missing from some other target?
"//third_party/webrtc/api:video_frame_api",
"//third_party/webrtc/system_wrappers:metrics_default",
"//ui/accessibility:ax_gen",
"//ui/gfx:test_support",
"//ui/gfx/geometry",
"//ui/gl",
"//ui/gl:test_support",
]

if (is_win) {
deps -= [ ":vr_common" ]
deps += [ ":vr_common_source" ]
}

if (is_android) {
deps += [ "//ui/android:ui_java" ]
public_deps -= [ ":vr_common" ]
public_deps += [ ":vr_common_source" ]
}

data = [
Expand Down
25 changes: 17 additions & 8 deletions chrome/browser/vr/elements/text.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ namespace vr {

class TextTexture : public UiTexture {
public:
TextTexture(const base::string16& text, float font_height, float text_width)
: text_(text), font_height_(font_height), text_width_(text_width) {}
TextTexture(float font_height, float text_width)
: font_height_(font_height), text_width_(text_width) {}
~TextTexture() override {}

void SetText(const base::string16& text) {
if (text_ == text)
return;
text_ = text;
set_dirty();
}

void SetColor(SkColor color) {
if (color_ == color)
return;
Expand Down Expand Up @@ -50,22 +57,24 @@ class TextTexture : public UiTexture {

Text::Text(int maximum_width_pixels,
float font_height_meters,
float text_width_meters,
const base::string16& text)
float text_width_meters)
: TexturedElement(maximum_width_pixels),
texture_(base::MakeUnique<TextTexture>(text,
font_height_meters,
texture_(base::MakeUnique<TextTexture>(font_height_meters,
text_width_meters)) {}
Text::~Text() {}

UiTexture* Text::GetTexture() const {
return texture_.get();
void Text::SetText(const base::string16& text) {
texture_->SetText(text);
}

void Text::SetColor(SkColor color) {
texture_->SetColor(color);
}

UiTexture* Text::GetTexture() const {
return texture_.get();
}

void TextTexture::Draw(SkCanvas* sk_canvas, const gfx::Size& texture_size) {
cc::SkiaPaintCanvas paint_canvas(sk_canvas);
gfx::Canvas gfx_canvas(&paint_canvas, 1.0f);
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/vr/elements/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class Text : public TexturedElement {
public:
Text(int maximum_width_pixels,
float font_height_meters,
float text_width_meters,
const base::string16& text);
float text_width_meters);
~Text() override;

void SetText(const base::string16& text);
void SetColor(SkColor color);

private:
Expand Down
53 changes: 36 additions & 17 deletions chrome/browser/vr/test/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,52 @@
#ifndef CHROME_BROWSER_VR_TEST_CONSTANTS_H_
#define CHROME_BROWSER_VR_TEST_CONSTANTS_H_

#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/vector3d_f.h"
#include "ui/gfx/transform.h"

namespace vr {

// Proj matrix as used on a Pixel phone.
static const gfx::Transform kProjMatrix(1.03317f,
0.0f,
0.271253f,
0.0f,
0.0f,
0.862458f,
-0.0314586f,
0.0f,
0.0f,
0.0f,
-1.002f,
-0.2002f,
0.0f,
0.0f,
-1.0f,
0.0f);
// Proj matrix as used on a Pixel phone with the Daydream headset.
static const gfx::Transform kPixelDaydreamProjMatrix(1.03317f,
0.0f,
0.271253f,
0.0f,
0.0f,
0.862458f,
-0.0314586f,
0.0f,
0.0f,
0.0f,
-1.002f,
-0.2002f,
0.0f,
0.0f,
-1.0f,
0.0f);

static const gfx::Vector3dF kForwardVector(0.0f, 0.0f, -1.0f);

constexpr float kEpsilon = 1e-5f;

// Resolution of Pixel Phone for one eye.
static const gfx::Size kPixelHalfScreen(960, 1080);

static const char* kLoremIpsum100Chars =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis erat nisl, "
"tempus nec neque at nullam.";
static const char* kLoremIpsum700Chars =
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo "
"ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis "
"dis parturient montes, nascetur ridiculus mus. Donec quam felis, "
"ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa "
"quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, "
"arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. "
"Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras "
"dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. "
"Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. "
"Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus";

} // namespace vr

#endif // CHROME_BROWSER_VR_TEST_CONSTANTS_H_
8 changes: 1 addition & 7 deletions chrome/browser/vr/test/ui_pixel_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "base/memory/ptr_util.h"
#include "build/build_config.h"
#include "chrome/browser/vr/browser_ui_interface.h"
#include "chrome/browser/vr/test/constants.h"
#include "chrome/browser/vr/ui_browser_interface.h"
#include "chrome/browser/vr/ui_input_manager.h"
#include "chrome/browser/vr/ui_renderer.h"
Expand All @@ -20,13 +21,6 @@

namespace vr {

namespace {

// Resolution of Pixel Phone for one eye.
static const gfx::Size kPixelHalfScreen(960, 1080);

} // namespace

UiPixelTest::UiPixelTest() : frame_buffer_size_(kPixelHalfScreen) {}

UiPixelTest::~UiPixelTest() = default;
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/vr/test/ui_scene_manager_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void UiSceneManagerTest::CheckRendererOpacityRecursive(

FakeUiElementRenderer renderer;
if (element->draw_phase() != kPhaseNone) {
element->Render(&renderer, kProjMatrix);
element->Render(&renderer, kPixelDaydreamProjMatrix);
}

// It is expected that some elements doesn't render anything (such as root
Expand Down
17 changes: 1 addition & 16 deletions chrome/browser/vr/testapp/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//tools/grit/repack.gni")

executable("vr_testapp") {
testonly = true

Expand All @@ -16,27 +14,14 @@ executable("vr_testapp") {
]

deps = [
"//base",
"//build/config:exe_and_shlib_deps",
"//chrome/browser/resources:vr_shell_resources",
"//chrome/browser/vr:vr_common",
"//chrome/browser/vr:vr_test_pak",
"//chrome/browser/vr:vr_test_support",
"//components:components_tests_pak",
"//components/security_state/core",
"//components/toolbar:vector_icons",
"//components/tracing:startup_tracing",

# TODO(mthiesse, crbug.com/769373): Remove dependency on device/vr:fakes.
"//device/vr:fakes",
"//skia",
"//ui/accessibility:ax_gen",
"//ui/display/types",
"//ui/events",
"//ui/events:dom_keycode_converter",
"//ui/events/ozone:events_ozone_layout",
"//ui/gfx/geometry",
"//ui/gl",
"//ui/gl/init",
"//ui/ozone",
"//ui/platform_window",
]
Expand Down
84 changes: 84 additions & 0 deletions chrome/browser/vr/text_perftest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/memory/ptr_util.h"
#include "base/strings/utf_string_conversions.h"
#include "cc/base/lap_timer.h"
#include "chrome/browser/vr/elements/text.h"
#include "chrome/browser/vr/test/constants.h"
#include "chrome/browser/vr/test/gl_test_environment.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/perf/perf_test.h"

namespace vr {

namespace {

constexpr int kMaximumTextWidthPixels = 512;
constexpr size_t kNumberOfRuns = 35;
constexpr float kFontHeightMeters = 0.05f;
constexpr float kTextWidthMeters = 1.0f;

} // namespace

class TextPerfTest : public testing::Test {
public:
void SetUp() override {
gl_test_environment_ =
base::MakeUnique<GlTestEnvironment>(kPixelHalfScreen);
text_element_ = base::MakeUnique<Text>(kMaximumTextWidthPixels,
kFontHeightMeters, kTextWidthMeters);
text_element_->Initialize();
}

void TearDown() override {
text_element_.reset();
gl_test_environment_.reset();
}

protected:
void PrintResults(const std::string& name) {
perf_test::PrintResult(name, "", "render_time_avg", timer_.MsPerLap(), "ms",
true);
perf_test::PrintResult(name, "", "number_of_runs",
static_cast<size_t>(timer_.NumLaps()), "runs", true);
}

void RenderAndLapTimer() {
static_cast<UiElement*>(text_element_.get())->PrepareToDraw();
// Make sure all GL commands are applied before we measure the time.
glFinish();
timer_.NextLap();
}

std::unique_ptr<Text> text_element_;
cc::LapTimer timer_;

private:
std::unique_ptr<GlTestEnvironment> gl_test_environment_;
};

TEST_F(TextPerfTest, RenderLoremIpsum100Chars) {
base::string16 text = base::UTF8ToUTF16(kLoremIpsum100Chars);
timer_.Reset();
for (size_t i = 0; i < kNumberOfRuns; i++) {
text[0] = 'a' + (i % 26);
text_element_->SetText(text);
RenderAndLapTimer();
}
PrintResults("render_lorem_ipsum_100_chars");
}

TEST_F(TextPerfTest, RenderLoremIpsum700Chars) {
base::string16 text = base::UTF8ToUTF16(kLoremIpsum700Chars);
timer_.Reset();
for (size_t i = 0; i < kNumberOfRuns; i++) {
text[0] = 'a' + (i % 26);
text_element_->SetText(text);
RenderAndLapTimer();
}
PrintResults("render_lorem_ipsum_700_chars");
}

} // namespace vr
Loading

0 comments on commit 213a422

Please sign in to comment.