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/ui_elements/textured_element.h" | 5 #include "chrome/browser/android/vr_shell/ui_elements/textured_element.h" |
6 | 6 |
7 #include "base/trace_event/trace_event.h" | 7 #include "base/trace_event/trace_event.h" |
8 #include "cc/paint/skia_paint_canvas.h" | 8 #include "cc/paint/skia_paint_canvas.h" |
9 #include "chrome/browser/android/vr_shell/textures/ui_texture.h" | 9 #include "chrome/browser/android/vr_shell/textures/ui_texture.h" |
10 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" | 10 #include "chrome/browser/android/vr_shell/ui_element_renderer.h" |
11 #include "third_party/skia/include/core/SkSurface.h" | 11 #include "third_party/skia/include/core/SkSurface.h" |
12 | 12 |
13 namespace vr_shell { | 13 namespace vr_shell { |
14 | 14 |
15 TexturedElement::TexturedElement(int maximum_width) | 15 TexturedElement::TexturedElement(int maximum_width) |
16 : texture_handle_(-1), maximum_width_(maximum_width) {} | 16 : texture_handle_(-1), maximum_width_(maximum_width) {} |
17 | 17 |
18 TexturedElement::~TexturedElement() = default; | 18 TexturedElement::~TexturedElement() = default; |
19 | 19 |
20 void TexturedElement::Initialize() { | 20 void TexturedElement::Initialize() { |
(...skipping 11 matching lines...) Expand all Loading... |
32 | 32 |
33 void TexturedElement::UpdateTexture() { | 33 void TexturedElement::UpdateTexture() { |
34 if (!initialized_ || !GetTexture()->dirty()) | 34 if (!initialized_ || !GetTexture()->dirty()) |
35 return; | 35 return; |
36 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul( | 36 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul( |
37 texture_size_.width(), texture_size_.height()); | 37 texture_size_.width(), texture_size_.height()); |
38 GetTexture()->DrawAndLayout(surface->getCanvas(), texture_size_); | 38 GetTexture()->DrawAndLayout(surface->getCanvas(), texture_size_); |
39 Flush(surface.get()); | 39 Flush(surface.get()); |
40 } | 40 } |
41 | 41 |
42 void TexturedElement::Render(VrShellRenderer* renderer, | 42 void TexturedElement::Render(UiElementRenderer* renderer, |
43 vr::Mat4f view_proj_matrix) const { | 43 vr::Mat4f view_proj_matrix) const { |
44 if (!initialized_) | 44 if (!initialized_) |
45 return; | 45 return; |
46 gfx::SizeF drawn_size = GetTexture()->GetDrawnSize(); | 46 gfx::SizeF drawn_size = GetTexture()->GetDrawnSize(); |
47 gfx::RectF copy_rect(0, 0, drawn_size.width() / texture_size_.width(), | 47 gfx::RectF copy_rect(0, 0, drawn_size.width() / texture_size_.width(), |
48 drawn_size.height() / texture_size_.height()); | 48 drawn_size.height() / texture_size_.height()); |
49 renderer->GetTexturedQuadRenderer()->AddQuad( | 49 renderer->DrawTexturedQuad(texture_handle_, view_proj_matrix, copy_rect, |
50 texture_handle_, view_proj_matrix, copy_rect, opacity()); | 50 opacity()); |
51 } | 51 } |
52 | 52 |
53 void TexturedElement::Flush(SkSurface* surface) { | 53 void TexturedElement::Flush(SkSurface* surface) { |
54 cc::SkiaPaintCanvas paint_canvas(surface->getCanvas()); | 54 cc::SkiaPaintCanvas paint_canvas(surface->getCanvas()); |
55 paint_canvas.flush(); | 55 paint_canvas.flush(); |
56 SkPixmap pixmap; | 56 SkPixmap pixmap; |
57 CHECK(surface->peekPixels(&pixmap)); | 57 CHECK(surface->peekPixels(&pixmap)); |
58 | 58 |
59 glBindTexture(GL_TEXTURE_2D, texture_handle_); | 59 glBindTexture(GL_TEXTURE_2D, texture_handle_); |
60 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 60 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
61 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 61 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
62 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 62 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
63 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 63 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
64 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixmap.width(), pixmap.height(), 0, | 64 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixmap.width(), pixmap.height(), 0, |
65 GL_RGBA, GL_UNSIGNED_BYTE, pixmap.addr()); | 65 GL_RGBA, GL_UNSIGNED_BYTE, pixmap.addr()); |
66 } | 66 } |
67 | 67 |
68 void TexturedElement::OnSetMode() { | 68 void TexturedElement::OnSetMode() { |
69 GetTexture()->SetMode(mode()); | 69 GetTexture()->SetMode(mode()); |
70 } | 70 } |
71 | 71 |
72 } // namespace vr_shell | 72 } // namespace vr_shell |
OLD | NEW |