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/ui_texture.h" | 5 #include "chrome/browser/android/vr_shell/textures/ui_texture.h" |
6 | 6 |
7 #include <set> | |
7 #include <string> | 8 #include <string> |
8 #include <vector> | 9 #include <vector> |
9 | 10 |
11 #include "base/i18n/char_iterator.h" | |
10 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
11 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "chrome/browser/browser_process.h" | |
12 #include "third_party/skia/include/core/SkCanvas.h" | 15 #include "third_party/skia/include/core/SkCanvas.h" |
16 #include "third_party/skia/include/ports/SkFontMgr.h" | |
13 #include "ui/gfx/canvas.h" | 17 #include "ui/gfx/canvas.h" |
18 #include "ui/gfx/font_list.h" | |
14 #include "ui/gl/gl_bindings.h" | 19 #include "ui/gl/gl_bindings.h" |
15 | 20 |
16 namespace vr_shell { | 21 namespace vr_shell { |
17 | 22 |
23 namespace { | |
24 constexpr char kDefaultFontFamily[] = "sans-serif"; | |
25 } // namespace | |
26 | |
18 // TODO(acondor): Create non-square textures to reduce memory usage. | 27 // TODO(acondor): Create non-square textures to reduce memory usage. |
19 UITexture::UITexture(int texture_handle, int texture_size) | 28 UITexture::UITexture(int texture_handle, int texture_size) |
20 : texture_handle_(texture_handle), | 29 : texture_handle_(texture_handle), |
21 texture_size_(texture_size), | 30 texture_size_(texture_size), |
22 surface_(SkSurface::MakeRasterN32Premul(texture_size_, texture_size_)) {} | 31 surface_(SkSurface::MakeRasterN32Premul(texture_size_, texture_size_)) {} |
23 | 32 |
24 UITexture::~UITexture() = default; | 33 UITexture::~UITexture() = default; |
25 | 34 |
26 void UITexture::DrawAndLayout() { | 35 void UITexture::DrawAndLayout() { |
27 cc::SkiaPaintCanvas paint_canvas(surface_->getCanvas()); | 36 cc::SkiaPaintCanvas paint_canvas(surface_->getCanvas()); |
(...skipping 11 matching lines...) Expand all Loading... | |
39 | 48 |
40 glBindTexture(GL_TEXTURE_2D, texture_handle_); | 49 glBindTexture(GL_TEXTURE_2D, texture_handle_); |
41 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixmap.width(), pixmap.height(), 0, | 50 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixmap.width(), pixmap.height(), 0, |
42 GL_RGBA, GL_UNSIGNED_BYTE, pixmap.addr()); | 51 GL_RGBA, GL_UNSIGNED_BYTE, pixmap.addr()); |
43 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 52 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
44 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 53 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
45 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 54 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
46 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 55 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
47 } | 56 } |
48 | 57 |
58 gfx::FontList UITexture::GetFontList(int size, base::string16 text) { | |
mthiesse
2017/04/18 21:30:35
This feels like code that shouldn't be specific to
acondor_
2017/04/18 23:48:46
Added a TODO. It should be gfx::GetFallbackFonts,
| |
59 gfx::Font default_font(kDefaultFontFamily, size); | |
60 std::vector<gfx::Font> fonts{default_font}; | |
61 sk_sp<SkFontMgr> font_mgr(SkFontMgr::RefDefault()); | |
62 std::set<std::string> names; | |
63 // TODO(acondor): Query BrowserProcess to obtain the application locale. | |
64 for (base::i18n::UTF16CharIterator it(&text); !it.end(); it.Advance()) { | |
65 sk_sp<SkTypeface> tf(font_mgr->matchFamilyStyleCharacter( | |
66 default_font.GetFontName().c_str(), SkFontStyle(), nullptr, 0, | |
67 it.get())); | |
68 SkString sk_name; | |
69 tf->getFamilyName(&sk_name); | |
70 std::string name(sk_name.c_str()); | |
71 if (name != kDefaultFontFamily) | |
72 names.insert(name); | |
73 } | |
74 for (const auto& name : names) | |
75 fonts.push_back(gfx::Font(name, size)); | |
76 return gfx::FontList(fonts); | |
77 } | |
78 | |
49 } // namespace vr_shell | 79 } // namespace vr_shell |
OLD | NEW |