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

Side by Side Diff: chrome/browser/android/vr_shell/textures/url_bar_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 | « chrome/browser/android/vr_shell/textures/url_bar_texture.h ('k') | no next file » | 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/url_bar_texture.h" 5 #include "chrome/browser/android/vr_shell/textures/url_bar_texture.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "cc/paint/skia_paint_canvas.h" 8 #include "cc/paint/skia_paint_canvas.h"
9 #include "components/security_state/core/security_state.h" 9 #include "components/security_state/core/security_state.h"
10 #include "ui/gfx/canvas.h" 10 #include "ui/gfx/canvas.h"
11 #include "ui/gfx/font.h" 11 #include "ui/gfx/font.h"
12 #include "ui/gfx/font_list.h" 12 #include "ui/gfx/font_list.h"
13 #include "ui/gfx/geometry/rect.h" 13 #include "ui/gfx/geometry/rect.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 static constexpr SkColor kTextureBackground = 0x00AAAAAA;
23 static constexpr SkColor kBackground = 0xCCAAAAAA; 23 static constexpr SkColor kBackground = 0xCCAAAAAA;
24 static constexpr SkColor kBackgroundHover = 0xCCDDDDDD; 24 static constexpr SkColor kBackgroundHover = 0xCCDDDDDD;
25 static constexpr SkColor kForeground = 0xCC444444; 25 static constexpr SkColor kForeground = 0xCC444444;
26 static constexpr SkColor kSeparatorColor = 26 static constexpr SkColor kSeparatorColor =
27 SkColorSetARGBMacro(256 * 0.2, 0, 0, 0); 27 SkColorSetARGBMacro(256 * 0.2, 0, 0, 0);
28 28
29 static constexpr float kWidth = 0.672; 29 static constexpr float kWidth = 0.672;
30 static constexpr float kHeight = 0.088; 30 static constexpr float kHeight = 0.088;
31 static constexpr float kFontHeight = 0.027; 31 static constexpr float kFontHeight = 0.027;
32 static constexpr float kBackButtonWidth = kHeight; 32 static constexpr float kBackButtonWidth = kHeight;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 size_.set_height(texture_size.height()); 81 size_.set_height(texture_size.height());
82 size_.set_width(texture_size.width()); 82 size_.set_width(texture_size.width());
83 83
84 canvas->save(); 84 canvas->save();
85 canvas->scale(size_.width() / kWidth, size_.width() / kWidth); 85 canvas->scale(size_.width() / kWidth, size_.width() / kWidth);
86 86
87 // Make a gfx canvas to support utility drawing methods. 87 // Make a gfx canvas to support utility drawing methods.
88 cc::SkiaPaintCanvas paint_canvas(canvas); 88 cc::SkiaPaintCanvas paint_canvas(canvas);
89 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f); 89 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f);
90 90
91 canvas->drawColor(kTextureBackground);
92
93 // Back button area. 91 // Back button area.
94 SkRRect round_rect; 92 SkRRect round_rect;
95 SkVector rounded_corner = {kHeight / 2, kHeight / 2}; 93 SkVector rounded_corner = {kHeight / 2, kHeight / 2};
96 SkVector left_corners[4] = {rounded_corner, {0, 0}, {0, 0}, rounded_corner}; 94 SkVector left_corners[4] = {rounded_corner, {0, 0}, {0, 0}, rounded_corner};
97 round_rect.setRectRadii({0, 0, kHeight, kHeight}, left_corners); 95 round_rect.setRectRadii({0, 0, kHeight, kHeight}, left_corners);
98 SkPaint paint; 96 SkPaint paint;
99 paint.setColor(hover_ ? kBackgroundHover : kBackground); 97 paint.setColor(hover_ ? kBackgroundHover : kBackground);
100 canvas->drawRRect(round_rect, paint); 98 canvas->drawRRect(round_rect, paint);
101 99
102 // URL area. 100 // URL area.
(...skipping 11 matching lines...) Expand all
114 canvas->save(); 112 canvas->save();
115 canvas->translate(kHeight / 2 + kBackIconOffset, kHeight / 2); 113 canvas->translate(kHeight / 2 + kBackIconOffset, kHeight / 2);
116 canvas->translate(-kBackIconHeight / 2, -kBackIconHeight / 2); 114 canvas->translate(-kBackIconHeight / 2, -kBackIconHeight / 2);
117 int icon_default_height = GetDefaultSizeOfVectorIcon(ui::kBackArrowIcon); 115 int icon_default_height = GetDefaultSizeOfVectorIcon(ui::kBackArrowIcon);
118 float icon_scale = kBackIconHeight / icon_default_height; 116 float icon_scale = kBackIconHeight / icon_default_height;
119 canvas->scale(icon_scale, icon_scale); 117 canvas->scale(icon_scale, icon_scale);
120 PaintVectorIcon(&gfx_canvas, ui::kBackArrowIcon, kForeground); 118 PaintVectorIcon(&gfx_canvas, ui::kBackArrowIcon, kForeground);
121 canvas->restore(); 119 canvas->restore();
122 120
123 // Site security state icon. 121 // Site security state icon.
124 // TODO(cjgrant): Plug in the correct icons based on security level. 122 if (!gurl_.is_empty()) {
125 if (!gurl_.spec().empty()) {
126 canvas->save(); 123 canvas->save();
127 canvas->translate( 124 canvas->translate(
128 kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth / 2, 125 kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth / 2,
129 kHeight / 2); 126 kHeight / 2);
130 canvas->translate(-kSecurityIconHeight / 2, -kSecurityIconHeight / 2); 127 canvas->translate(-kSecurityIconHeight / 2, -kSecurityIconHeight / 2);
131 const gfx::VectorIcon& security_icon = getSecurityIcon(security_level_); 128 const gfx::VectorIcon& security_icon = getSecurityIcon(security_level_);
132 icon_default_height = GetDefaultSizeOfVectorIcon(security_icon); 129 icon_default_height = GetDefaultSizeOfVectorIcon(security_icon);
133 icon_scale = kSecurityIconHeight / icon_default_height; 130 icon_scale = kSecurityIconHeight / icon_default_height;
134 canvas->scale(icon_scale, icon_scale); 131 canvas->scale(icon_scale, icon_scale);
135 PaintVectorIcon(&gfx_canvas, security_icon, kForeground); 132 PaintVectorIcon(&gfx_canvas, security_icon, kForeground);
136 canvas->restore(); 133 canvas->restore();
137 } 134 }
138 135
139 canvas->restore(); 136 canvas->restore();
140 137
141 // Draw text based on pixel sizes rather than meters, for correct font sizing. 138 if (!gurl_.is_empty()) {
142 int pixel_font_height = texture_size.height() * kFontHeight / kHeight; 139 if (last_drawn_gurl_ != gurl_) {
143 int text_flags = gfx::Canvas::TEXT_ALIGN_LEFT; 140 // Draw text based on pixel sizes rather than meters, for correct font
144 float url_x = kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth; 141 // sizing.
145 float url_width = kWidth - url_x - kUrlRightMargin; 142 int pixel_font_height = texture_size.height() * kFontHeight / kHeight;
146 gfx_canvas.DrawStringRectWithFlags( 143 float url_x = kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth;
147 base::UTF8ToUTF16(gurl_.spec()), GetDefaultFontList(pixel_font_height), 144 float url_width = kWidth - url_x - kUrlRightMargin;
148 SK_ColorBLACK, 145 gfx::Rect text_bounds(ToPixels(url_x), 0, ToPixels(url_width),
149 gfx::Rect(ToPixels(url_x), 0, ToPixels(url_width), ToPixels(kHeight)), 146 ToPixels(kHeight));
150 text_flags); 147 gurl_render_texts_ =
148 PrepareDrawStringRect(base::UTF8ToUTF16(gurl_.spec()),
149 GetDefaultFontList(pixel_font_height),
150 SK_ColorBLACK, &text_bounds, TEXT_ALIGN_LEFT);
151 last_drawn_gurl_ = gurl_;
152 }
153 for (auto& render_text : gurl_render_texts_)
154 render_text->Draw(&gfx_canvas);
155 }
151 } 156 }
152 157
153 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { 158 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const {
154 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); 159 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth);
155 } 160 }
156 161
157 gfx::SizeF UrlBarTexture::GetDrawnSize() const { 162 gfx::SizeF UrlBarTexture::GetDrawnSize() const {
158 return size_; 163 return size_;
159 } 164 }
160 165
161 } // namespace vr_shell 166 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/textures/url_bar_texture.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698