Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(467)

Side by Side Diff: chrome/browser/android/vr_shell/textures/insecure_content_transient_texture.cc

Issue 2861343002: Enable gpu rasterization in the vr shell
Patch Set: additional trace instrumentation Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "chrome/browser/android/vr_shell/textures/insecure_content_transient_te xture.h" 5 #include "chrome/browser/android/vr_shell/textures/insecure_content_transient_te xture.h"
6 6
7 #include "base/trace_event/trace_event.h"
7 #include "cc/paint/skia_paint_canvas.h" 8 #include "cc/paint/skia_paint_canvas.h"
8 #include "components/strings/grit/components_strings.h" 9 #include "components/strings/grit/components_strings.h"
9 #include "ui/base/l10n/l10n_util.h" 10 #include "ui/base/l10n/l10n_util.h"
10 #include "ui/gfx/canvas.h" 11 #include "ui/gfx/canvas.h"
11 #include "ui/gfx/font_list.h" 12 #include "ui/gfx/font_list.h"
12 #include "ui/gfx/geometry/rect.h" 13 #include "ui/gfx/geometry/rect.h"
13 #include "ui/gfx/geometry/vector2d.h" 14 #include "ui/gfx/geometry/vector2d.h"
14 #include "ui/gfx/paint_vector_icon.h" 15 #include "ui/gfx/paint_vector_icon.h"
15 #include "ui/gfx/vector_icon_types.h" 16 #include "ui/gfx/vector_icon_types.h"
16 #include "ui/vector_icons/vector_icons.h" 17 #include "ui/vector_icons/vector_icons.h"
17 18
18 namespace vr_shell { 19 namespace vr_shell {
19 20
20 namespace { 21 namespace {
21 22
22 const SkColor kBackgroundColor = 0xCC1A1A1A; 23 const SkColor kBackgroundColor = 0xCC1A1A1A;
23 const SkColor kForegroundColor = SK_ColorWHITE; 24 const SkColor kForegroundColor = SK_ColorWHITE;
24 constexpr float kBorderFactor = 0.045; 25 constexpr float kBorderFactor = 0.045;
25 constexpr float kFontSizeFactor = 0.048; 26 constexpr float kFontSizeFactor = 0.048;
26 constexpr float kTextWidthFactor = 1.0 - 3 * kBorderFactor; 27 constexpr float kTextWidthFactor = 1.0 - 3 * kBorderFactor;
27 28
28 } // namespace 29 } // namespace
29 30
30 InsecureContentTransientTexture::InsecureContentTransientTexture() = default; 31 InsecureContentTransientTexture::InsecureContentTransientTexture() = default;
31 32
32 InsecureContentTransientTexture::~InsecureContentTransientTexture() = default; 33 InsecureContentTransientTexture::~InsecureContentTransientTexture() = default;
33 34
34 void InsecureContentTransientTexture::Draw(gfx::Canvas* canvas, 35 void InsecureContentTransientTexture::Draw(gfx::Canvas* canvas,
35 const gfx::Size& texture_size) { 36 const gfx::Size& texture_size) {
37 TRACE_EVENT0("gpu,vr", "InsecureContentTransientTexture::Draw");
36 size_.set_width(texture_size.width()); 38 size_.set_width(texture_size.width());
37 int max_height = texture_size.height(); 39 int max_height = texture_size.height();
38 cc::PaintFlags flags; 40 cc::PaintFlags flags;
39 flags.setColor(kBackgroundColor); 41 flags.setColor(kBackgroundColor);
40 42
43 TRACE_EVENT_BEGIN0("gpu,vr", "GetStringUTF16");
41 int text_flags = gfx::Canvas::TEXT_ALIGN_CENTER | gfx::Canvas::MULTI_LINE; 44 int text_flags = gfx::Canvas::TEXT_ALIGN_CENTER | gfx::Canvas::MULTI_LINE;
42 auto text = 45 auto text =
43 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INSECURE_WEBVR_CONTENT_TRANSIENT); 46 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INSECURE_WEBVR_CONTENT_TRANSIENT);
47 TRACE_EVENT_END0("gpu,vr", "GetStringUTF16");
48
49 TRACE_EVENT_BEGIN0("gpu,vr", "GetFontList");
44 auto fonts = GetFontList(size_.width() * kFontSizeFactor, text); 50 auto fonts = GetFontList(size_.width() * kFontSizeFactor, text);
51 TRACE_EVENT_END0("gpu,vr", "GetFontList");
52
45 int text_width = size_.width() * kTextWidthFactor; 53 int text_width = size_.width() * kTextWidthFactor;
46 int text_height = 0; // Will be increased during text measurement. 54 int text_height = 0; // Will be increased during text measurement.
47 gfx::Canvas::SizeStringInt(text, fonts, &text_width, &text_height, 0, 55 gfx::Canvas::SizeStringInt(text, fonts, &text_width, &text_height, 0,
48 text_flags); 56 text_flags);
49 57
50 // Making sure the drawing fits within the texture. 58 // Making sure the drawing fits within the texture.
51 text_height = std::min( 59 text_height = std::min(
52 text_height, static_cast<int>((1.0 - 2 * kBorderFactor) * size_.width())); 60 text_height, static_cast<int>((1.0 - 2 * kBorderFactor) * size_.width()));
53 size_.set_height(size_.width() * 2 * kBorderFactor + text_height); 61 size_.set_height(size_.width() * 2 * kBorderFactor + text_height);
54 DCHECK_LE(size_.height(), max_height); 62 DCHECK_LE(size_.height(), max_height);
55 canvas->DrawRoundRect(gfx::Rect(size_.width(), size_.height()), 63 canvas->DrawRoundRect(gfx::Rect(size_.width(), size_.height()),
56 size_.height() * kBorderFactor, flags); 64 size_.height() * kBorderFactor, flags);
57 65
58 canvas->Save(); 66 canvas->Save();
59 canvas->Translate(gfx::Vector2d(size_.width() * kBorderFactor, 67 canvas->Translate(gfx::Vector2d(size_.width() * kBorderFactor,
60 size_.width() * kBorderFactor)); 68 size_.width() * kBorderFactor));
69
70 TRACE_EVENT_BEGIN0("gpu,vr", "DrawStringRectWithFlags");
61 canvas->DrawStringRectWithFlags( 71 canvas->DrawStringRectWithFlags(
62 text, fonts, kForegroundColor, 72 text, fonts, kForegroundColor,
63 gfx::Rect(kTextWidthFactor * size_.width(), text_height), text_flags); 73 gfx::Rect(kTextWidthFactor * size_.width(), text_height), text_flags);
74 TRACE_EVENT_END0("gpu,vr", "DrawStringRectWithFlags");
64 canvas->Restore(); 75 canvas->Restore();
65 } 76 }
66 77
67 gfx::Size InsecureContentTransientTexture::GetPreferredTextureSize( 78 gfx::Size InsecureContentTransientTexture::GetPreferredTextureSize(
68 int maximum_width) const { 79 int maximum_width) const {
69 return gfx::Size(maximum_width, maximum_width); 80 return gfx::Size(maximum_width, maximum_width);
70 } 81 }
71 82
72 gfx::SizeF InsecureContentTransientTexture::GetDrawnSize() const { 83 gfx::SizeF InsecureContentTransientTexture::GetDrawnSize() const {
73 return size_; 84 return size_;
74 } 85 }
75 86
76 } // namespace vr_shell 87 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698