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

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

Issue 2877673005: VR: Avoiding regeneration of RenderText objects for texture rendering (Closed)
Patch Set: removing unnecessary comment 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
« no previous file with comments | « no previous file | chrome/browser/android/vr_shell/textures/insecure_content_transient_texture.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_permanent_te xture.h" 5 #include "chrome/browser/android/vr_shell/textures/insecure_content_permanent_te xture.h"
6 6
7 #include "cc/paint/skia_paint_canvas.h" 7 #include "cc/paint/skia_paint_canvas.h"
8 #include "components/strings/grit/components_strings.h" 8 #include "components/strings/grit/components_strings.h"
9 #include "ui/base/l10n/l10n_util.h" 9 #include "ui/base/l10n/l10n_util.h"
10 #include "ui/gfx/canvas.h" 10 #include "ui/gfx/canvas.h"
11 #include "ui/gfx/font_list.h" 11 #include "ui/gfx/font_list.h"
12 #include "ui/gfx/geometry/rect.h" 12 #include "ui/gfx/geometry/rect.h"
13 #include "ui/gfx/geometry/vector2d.h" 13 #include "ui/gfx/geometry/vector2d.h"
14 #include "ui/gfx/paint_vector_icon.h" 14 #include "ui/gfx/paint_vector_icon.h"
15 #include "ui/gfx/render_text.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 = SK_ColorWHITE; 23 const SkColor kBackgroundColor = SK_ColorWHITE;
23 const SkColor kForegroundColor = 0xFF444444; 24 const SkColor kForegroundColor = 0xFF444444;
24 constexpr float kBorderFactor = 0.1; 25 constexpr float kBorderFactor = 0.1;
25 constexpr float kIconSizeFactor = 0.7; 26 constexpr float kIconSizeFactor = 0.7;
26 constexpr float kFontSizeFactor = 0.40; 27 constexpr float kFontSizeFactor = 0.40;
27 constexpr float kTextHeightFactor = 1.0 - 2 * kBorderFactor; 28 constexpr float kTextHeightFactor = 1.0 - 2 * kBorderFactor;
28 constexpr float kTextWidthFactor = 4.0 - 3 * kBorderFactor - kIconSizeFactor; 29 constexpr float kTextWidthFactor = 4.0 - 3 * kBorderFactor - kIconSizeFactor;
29 30
30 } // namespace 31 } // namespace
31 32
32 InsecureContentPermanentTexture::InsecureContentPermanentTexture() = default; 33 InsecureContentPermanentTexture::InsecureContentPermanentTexture() = default;
33 34
34 InsecureContentPermanentTexture::~InsecureContentPermanentTexture() = default; 35 InsecureContentPermanentTexture::~InsecureContentPermanentTexture() = default;
35 36
36 void InsecureContentPermanentTexture::Draw(SkCanvas* sk_canvas, 37 void InsecureContentPermanentTexture::Draw(SkCanvas* sk_canvas,
37 const gfx::Size& texture_size) { 38 const gfx::Size& texture_size) {
38 cc::SkiaPaintCanvas paint_canvas(sk_canvas); 39 cc::SkiaPaintCanvas paint_canvas(sk_canvas);
39 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f); 40 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f);
40 gfx::Canvas* canvas = &gfx_canvas; 41 gfx::Canvas* canvas = &gfx_canvas;
41 42
42 DCHECK(texture_size.height() * 4 == texture_size.width()); 43 DCHECK(texture_size.height() * 4 == texture_size.width());
43 size_.set_height(texture_size.height()); 44 size_.set_height(texture_size.height());
44 int max_width = texture_size.width(); 45 SkPaint paint;
45 cc::PaintFlags flags; 46 paint.setColor(kBackgroundColor);
46 flags.setColor(kBackgroundColor);
47
48 int text_flags = gfx::Canvas::TEXT_ALIGN_CENTER | gfx::Canvas::NO_ELLIPSIS;
49 auto text = 47 auto text =
50 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INSECURE_WEBVR_CONTENT_PERMANENT); 48 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INSECURE_WEBVR_CONTENT_PERMANENT);
51 auto fonts = GetFontList(size_.height() * kFontSizeFactor, text); 49 auto fonts = GetFontList(size_.height() * kFontSizeFactor, text);
52 int text_height = kTextHeightFactor * size_.height(); 50 gfx::Rect text_size(0, kTextHeightFactor * size_.height());
53 int text_width = kTextWidthFactor * size_.height(); 51
54 gfx::Canvas::SizeStringInt(text, fonts, &text_width, &text_height, 0, 52 std::vector<std::unique_ptr<gfx::RenderText>> lines =
55 text_flags); 53 PrepareDrawStringRect(text, fonts, kForegroundColor, &text_size, 0);
56 // Giving some extra width without reaching the texture limit. 54
57 text_width = 55 DCHECK_LE(text_size.width(), kTextWidthFactor * size_.height());
58 static_cast<int>(std::min(text_width + 2 * kBorderFactor * size_.height(), 56 // Setting background size giving some extra lateral padding to the text.
59 kTextWidthFactor * size_.height())); 57 size_.set_width((5 * kBorderFactor + kIconSizeFactor) * size_.height() +
60 size_.set_width((3 * kBorderFactor + kIconSizeFactor) * size_.height() + 58 text_size.width());
61 text_width); 59 float radius = size_.height() * kBorderFactor;
62 DCHECK_LE(size_.width(), max_width); 60 sk_canvas->drawRoundRect(SkRect::MakeWH(size_.width(), size_.height()),
63 canvas->DrawRoundRect(gfx::Rect(size_.width(), size_.height()), 61 radius, radius, paint);
64 size_.height() * kBorderFactor, flags);
65 62
66 canvas->Save(); 63 canvas->Save();
67 canvas->Translate( 64 canvas->Translate(gfx::Vector2d(
68 gfx::Vector2d(IsRTL() ? 2 * kBorderFactor * size_.height() + text_width 65 IsRTL() ? 4 * kBorderFactor * size_.height() + text_size.width()
69 : size_.height() * kBorderFactor, 66 : size_.height() * kBorderFactor,
70 size_.height() * (1.0 - kIconSizeFactor) / 2.0)); 67 size_.height() * (1.0 - kIconSizeFactor) / 2.0));
71 PaintVectorIcon(canvas, ui::kInfoOutlineIcon, 68 PaintVectorIcon(canvas, ui::kInfoOutlineIcon,
72 size_.height() * kIconSizeFactor, kForegroundColor); 69 size_.height() * kIconSizeFactor, kForegroundColor);
73 canvas->Restore(); 70 canvas->Restore();
74 71
75 canvas->Save(); 72 canvas->Save();
76 canvas->Translate(gfx::Vector2d( 73 canvas->Translate(gfx::Vector2d(
77 size_.height() * 74 size_.height() *
78 (IsRTL() ? kBorderFactor : 2 * kBorderFactor + kIconSizeFactor), 75 (IsRTL() ? 2 * kBorderFactor : 3 * kBorderFactor + kIconSizeFactor),
79 size_.height() * kBorderFactor)); 76 size_.height() * kBorderFactor));
80 canvas->DrawStringRectWithFlags( 77 for (auto& render_text : lines)
81 text, fonts, kForegroundColor, 78 render_text->Draw(canvas);
82 gfx::Rect(text_width, kTextHeightFactor * size_.height()), text_flags);
83 canvas->Restore(); 79 canvas->Restore();
84 } 80 }
85 81
86 gfx::Size InsecureContentPermanentTexture::GetPreferredTextureSize( 82 gfx::Size InsecureContentPermanentTexture::GetPreferredTextureSize(
87 int maximum_width) const { 83 int maximum_width) const {
88 // Ensuring height is a quarter of the width. 84 // Ensuring height is a quarter of the width.
89 int height = maximum_width / 4; 85 int height = maximum_width / 4;
90 return gfx::Size(height * 4, height); 86 return gfx::Size(height * 4, height);
91 } 87 }
92 88
93 gfx::SizeF InsecureContentPermanentTexture::GetDrawnSize() const { 89 gfx::SizeF InsecureContentPermanentTexture::GetDrawnSize() const {
94 return size_; 90 return size_;
95 } 91 }
96 92
97 } // namespace vr_shell 93 } // namespace vr_shell
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/android/vr_shell/textures/insecure_content_transient_texture.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698