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

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

Issue 2834543006: Hook up insecure content warnings for http webVR presentation. (Closed)
Patch Set: Add missing files Created 3 years, 8 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/ui_texture.h" 5 #include "chrome/browser/android/vr_shell/textures/ui_texture.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/i18n/char_iterator.h" 11 #include "base/i18n/char_iterator.h"
12 #include "base/i18n/rtl.h" 12 #include "base/i18n/rtl.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "third_party/skia/include/core/SkCanvas.h" 16 #include "third_party/skia/include/core/SkCanvas.h"
17 #include "third_party/skia/include/ports/SkFontMgr.h" 17 #include "third_party/skia/include/ports/SkFontMgr.h"
18 #include "ui/gfx/canvas.h" 18 #include "ui/gfx/canvas.h"
19 #include "ui/gfx/font_list.h" 19 #include "ui/gfx/font_list.h"
20 #include "ui/gl/gl_bindings.h" 20 #include "ui/gl/gl_bindings.h"
21 21
22 namespace vr_shell { 22 namespace vr_shell {
23 23
24 namespace { 24 namespace {
25 constexpr char kDefaultFontFamily[] = "sans-serif"; 25 constexpr char kDefaultFontFamily[] = "sans-serif";
26 } // namespace 26 } // namespace
27 27
28 // TODO(acondor): Create non-square textures to reduce memory usage. 28 UITexture::UITexture() = default;
29 UITexture::UITexture(int texture_handle, int texture_size)
30 : texture_handle_(texture_handle),
31 texture_size_(texture_size),
32 surface_(SkSurface::MakeRasterN32Premul(texture_size_, texture_size_)) {}
33 29
34 UITexture::~UITexture() = default; 30 UITexture::~UITexture() = default;
35 31
36 void UITexture::DrawAndLayout() { 32 void UITexture::DrawAndLayout(SkCanvas* canvas, const gfx::Size& texture_size) {
37 cc::SkiaPaintCanvas paint_canvas(surface_->getCanvas()); 33 cc::SkiaPaintCanvas paint_canvas(canvas);
38 gfx::Canvas canvas(&paint_canvas, 1.0f); 34 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f);
39 canvas.DrawColor(0x00000000); 35 gfx_canvas.DrawColor(0x00000000);
cjgrant 2017/04/21 14:30:13 SK_ColorTRANSPARENT
mthiesse 2017/04/21 15:05:12 Done.
40 Draw(&canvas); 36 Draw(&gfx_canvas, texture_size);
41 SetSize();
42 }
43
44 void UITexture::Flush() {
45 cc::SkiaPaintCanvas paint_canvas(surface_->getCanvas());
46 paint_canvas.flush();
47 SkPixmap pixmap;
48 CHECK(surface_->peekPixels(&pixmap));
49
50 glBindTexture(GL_TEXTURE_2D, texture_handle_);
51 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixmap.width(), pixmap.height(), 0,
52 GL_RGBA, GL_UNSIGNED_BYTE, pixmap.addr());
53 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
54 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
55 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
56 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
57 } 37 }
58 38
59 bool UITexture::IsRTL() { 39 bool UITexture::IsRTL() {
60 return base::i18n::IsRTL(); 40 return base::i18n::IsRTL();
61 } 41 }
62 42
63 gfx::FontList UITexture::GetFontList(int size, base::string16 text) { 43 gfx::FontList UITexture::GetFontList(int size, base::string16 text) {
64 gfx::Font default_font(kDefaultFontFamily, size); 44 gfx::Font default_font(kDefaultFontFamily, size);
65 std::vector<gfx::Font> fonts{default_font}; 45 std::vector<gfx::Font> fonts{default_font};
66 46
(...skipping 13 matching lines...) Expand all
80 std::string name(sk_name.c_str()); 60 std::string name(sk_name.c_str());
81 if (name != kDefaultFontFamily) 61 if (name != kDefaultFontFamily)
82 names.insert(name); 62 names.insert(name);
83 } 63 }
84 for (const auto& name : names) 64 for (const auto& name : names)
85 fonts.push_back(gfx::Font(name, size)); 65 fonts.push_back(gfx::Font(name, size));
86 return gfx::FontList(fonts); 66 return gfx::FontList(fonts);
87 } 67 }
88 68
89 } // namespace vr_shell 69 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698