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

Side by Side Diff: chrome/browser/android/vr_shell/ui_elements/textured_element.cc

Issue 2950173002: VR: System indicator rework. (Closed)
Patch Set: Address comments; increase size slightly for readability, now that position is dynamic. Created 3 years, 6 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/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/ui_element_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 #include "ui/gfx/geometry/rect_f.h" 12 #include "ui/gfx/geometry/rect_f.h"
13 13
14 namespace vr_shell { 14 namespace vr_shell {
15 15
16 TexturedElement::TexturedElement(int maximum_width) 16 TexturedElement::TexturedElement(int maximum_width)
17 : texture_handle_(-1), maximum_width_(maximum_width) {} 17 : texture_handle_(-1), maximum_width_(maximum_width) {}
18 18
19 TexturedElement::~TexturedElement() = default; 19 TexturedElement::~TexturedElement() = default;
20 20
21 void TexturedElement::Initialize() { 21 void TexturedElement::Initialize() {
22 TRACE_EVENT0("gpu", "TexturedElement::Initialize"); 22 TRACE_EVENT0("gpu", "TexturedElement::Initialize");
23 glGenTextures(1, &texture_handle_); 23 glGenTextures(1, &texture_handle_);
24 DCHECK(GetTexture() != nullptr); 24 DCHECK(GetTexture() != nullptr);
25 texture_size_ = GetTexture()->GetPreferredTextureSize(maximum_width_); 25 texture_size_ = GetTexture()->GetPreferredTextureSize(maximum_width_);
26 initialized_ = true; 26 initialized_ = true;
27 UpdateTexture(); 27 UpdateTexture();
28 set_fill(Fill::SELF); 28 set_fill(Fill::SELF);
29 gfx::SizeF drawn_size = GetTexture()->GetDrawnSize();
30 float y = drawn_size.height() / drawn_size.width() * size().x();
31 set_size({size().x(), y, 1});
32 } 29 }
33 30
34 void TexturedElement::UpdateTexture() { 31 void TexturedElement::UpdateTexture() {
35 if (!initialized_ || !GetTexture()->dirty()) 32 if (!initialized_ || !GetTexture()->dirty())
36 return; 33 return;
37 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul( 34 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(
38 texture_size_.width(), texture_size_.height()); 35 texture_size_.width(), texture_size_.height());
39 GetTexture()->DrawAndLayout(surface->getCanvas(), texture_size_); 36 GetTexture()->DrawAndLayout(surface->getCanvas(), texture_size_);
40 Flush(surface.get()); 37 Flush(surface.get());
38 // Update the element size's aspect ratio to match the texture.
39 UpdateElementSize();
40 }
41
42 void TexturedElement::UpdateElementSize() {
43 // Updating the height according to width is a hack. This may be overridden.
44 gfx::SizeF drawn_size = GetTexture()->GetDrawnSize();
45 float y = drawn_size.height() / drawn_size.width() * size().x();
46 set_size({size().x(), y, 1});
41 } 47 }
42 48
43 void TexturedElement::Render(UiElementRenderer* renderer, 49 void TexturedElement::Render(UiElementRenderer* renderer,
44 gfx::Transform view_proj_matrix) const { 50 gfx::Transform view_proj_matrix) const {
45 if (!initialized_) 51 if (!initialized_)
46 return; 52 return;
47 gfx::SizeF drawn_size = GetTexture()->GetDrawnSize(); 53 gfx::SizeF drawn_size = GetTexture()->GetDrawnSize();
48 gfx::RectF copy_rect(0, 0, drawn_size.width() / texture_size_.width(), 54 gfx::RectF copy_rect(0, 0, drawn_size.width() / texture_size_.width(),
49 drawn_size.height() / texture_size_.height()); 55 drawn_size.height() / texture_size_.height());
50 renderer->DrawTexturedQuad(texture_handle_, view_proj_matrix, copy_rect, 56 renderer->DrawTexturedQuad(texture_handle_, view_proj_matrix, copy_rect,
(...skipping 14 matching lines...) Expand all
65 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixmap.width(), pixmap.height(), 0, 71 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixmap.width(), pixmap.height(), 0,
66 GL_RGBA, GL_UNSIGNED_BYTE, pixmap.addr()); 72 GL_RGBA, GL_UNSIGNED_BYTE, pixmap.addr());
67 } 73 }
68 74
69 void TexturedElement::OnSetMode() { 75 void TexturedElement::OnSetMode() {
70 GetTexture()->SetMode(mode()); 76 GetTexture()->SetMode(mode());
71 UpdateTexture(); 77 UpdateTexture();
72 } 78 }
73 79
74 } // namespace vr_shell 80 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698