| OLD | NEW |
| 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 "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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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(gfx::Canvas* canvas, | 37 void InsecureContentPermanentTexture::Draw(gfx::Canvas* canvas, |
| 37 const gfx::Size& texture_size) { | 38 const gfx::Size& texture_size) { |
| 39 TRACE_EVENT0("gpu,vr", "InsecureContentPermanentTexture::Draw"); |
| 38 DCHECK(texture_size.height() * 4 == texture_size.width()); | 40 DCHECK(texture_size.height() * 4 == texture_size.width()); |
| 39 size_.set_height(texture_size.height()); | 41 size_.set_height(texture_size.height()); |
| 40 int max_width = texture_size.width(); | 42 int max_width = texture_size.width(); |
| 41 cc::PaintFlags flags; | 43 cc::PaintFlags flags; |
| 42 flags.setColor(kBackgroundColor); | 44 flags.setColor(kBackgroundColor); |
| 43 | 45 |
| 46 TRACE_EVENT_BEGIN0("gpu,vr", "GetStringUTF16"); |
| 44 int text_flags = gfx::Canvas::TEXT_ALIGN_CENTER | gfx::Canvas::NO_ELLIPSIS; | 47 int text_flags = gfx::Canvas::TEXT_ALIGN_CENTER | gfx::Canvas::NO_ELLIPSIS; |
| 45 auto text = | 48 auto text = |
| 46 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INSECURE_WEBVR_CONTENT_PERMANENT); | 49 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INSECURE_WEBVR_CONTENT_PERMANENT); |
| 50 TRACE_EVENT_END0("gpu,vr", "GetStringUTF16"); |
| 51 |
| 52 TRACE_EVENT_BEGIN0("gpu,vr", "GetFontList"); |
| 47 auto fonts = GetFontList(size_.height() * kFontSizeFactor, text); | 53 auto fonts = GetFontList(size_.height() * kFontSizeFactor, text); |
| 54 TRACE_EVENT_END0("gpu,vr", "GetFontList"); |
| 55 |
| 48 int text_height = kTextHeightFactor * size_.height(); | 56 int text_height = kTextHeightFactor * size_.height(); |
| 49 int text_width = kTextWidthFactor * size_.height(); | 57 int text_width = kTextWidthFactor * size_.height(); |
| 50 gfx::Canvas::SizeStringInt(text, fonts, &text_width, &text_height, 0, | 58 gfx::Canvas::SizeStringInt(text, fonts, &text_width, &text_height, 0, |
| 51 text_flags); | 59 text_flags); |
| 52 // Giving some extra width without reaching the texture limit. | 60 // Giving some extra width without reaching the texture limit. |
| 53 text_width = | 61 text_width = |
| 54 static_cast<int>(std::min(text_width + 2 * kBorderFactor * size_.height(), | 62 static_cast<int>(std::min(text_width + 2 * kBorderFactor * size_.height(), |
| 55 kTextWidthFactor * size_.height())); | 63 kTextWidthFactor * size_.height())); |
| 56 size_.set_width((3 * kBorderFactor + kIconSizeFactor) * size_.height() + | 64 size_.set_width((3 * kBorderFactor + kIconSizeFactor) * size_.height() + |
| 57 text_width); | 65 text_width); |
| 58 DCHECK_LE(size_.width(), max_width); | 66 DCHECK_LE(size_.width(), max_width); |
| 59 canvas->DrawRoundRect(gfx::Rect(size_.width(), size_.height()), | 67 canvas->DrawRoundRect(gfx::Rect(size_.width(), size_.height()), |
| 60 size_.height() * kBorderFactor, flags); | 68 size_.height() * kBorderFactor, flags); |
| 61 | 69 |
| 62 canvas->Save(); | 70 canvas->Save(); |
| 63 canvas->Translate( | 71 canvas->Translate( |
| 64 gfx::Vector2d(IsRTL() ? 2 * kBorderFactor * size_.height() + text_width | 72 gfx::Vector2d(IsRTL() ? 2 * kBorderFactor * size_.height() + text_width |
| 65 : size_.height() * kBorderFactor, | 73 : size_.height() * kBorderFactor, |
| 66 size_.height() * (1.0 - kIconSizeFactor) / 2.0)); | 74 size_.height() * (1.0 - kIconSizeFactor) / 2.0)); |
| 67 PaintVectorIcon(canvas, ui::kInfoOutlineIcon, | 75 PaintVectorIcon(canvas, ui::kInfoOutlineIcon, |
| 68 size_.height() * kIconSizeFactor, kForegroundColor); | 76 size_.height() * kIconSizeFactor, kForegroundColor); |
| 69 canvas->Restore(); | 77 canvas->Restore(); |
| 70 | 78 |
| 71 canvas->Save(); | 79 canvas->Save(); |
| 72 canvas->Translate(gfx::Vector2d( | 80 canvas->Translate(gfx::Vector2d( |
| 73 size_.height() * | 81 size_.height() * |
| 74 (IsRTL() ? kBorderFactor : 2 * kBorderFactor + kIconSizeFactor), | 82 (IsRTL() ? kBorderFactor : 2 * kBorderFactor + kIconSizeFactor), |
| 75 size_.height() * kBorderFactor)); | 83 size_.height() * kBorderFactor)); |
| 84 |
| 85 TRACE_EVENT_BEGIN0("gpu,vr", "DrawStringRectWithFlags"); |
| 76 canvas->DrawStringRectWithFlags( | 86 canvas->DrawStringRectWithFlags( |
| 77 text, fonts, kForegroundColor, | 87 text, fonts, kForegroundColor, |
| 78 gfx::Rect(text_width, kTextHeightFactor * size_.height()), text_flags); | 88 gfx::Rect(text_width, kTextHeightFactor * size_.height()), text_flags); |
| 89 TRACE_EVENT_END0("gpu,vr", "DrawStringRectWithFlags"); |
| 79 canvas->Restore(); | 90 canvas->Restore(); |
| 80 } | 91 } |
| 81 | 92 |
| 82 gfx::Size InsecureContentPermanentTexture::GetPreferredTextureSize( | 93 gfx::Size InsecureContentPermanentTexture::GetPreferredTextureSize( |
| 83 int maximum_width) const { | 94 int maximum_width) const { |
| 84 // Ensuring height is a quarter of the width. | 95 // Ensuring height is a quarter of the width. |
| 85 int height = maximum_width / 4; | 96 int height = maximum_width / 4; |
| 86 return gfx::Size(height * 4, height); | 97 return gfx::Size(height * 4, height); |
| 87 } | 98 } |
| 88 | 99 |
| 89 gfx::SizeF InsecureContentPermanentTexture::GetDrawnSize() const { | 100 gfx::SizeF InsecureContentPermanentTexture::GetDrawnSize() const { |
| 90 return size_; | 101 return size_; |
| 91 } | 102 } |
| 92 | 103 |
| 93 } // namespace vr_shell | 104 } // namespace vr_shell |
| OLD | NEW |