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

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

Issue 2972843002: Revert of [vr] Ensure that textured elements never draw with a dirty texture (Closed)
Patch Set: Created 3 years, 5 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
« no previous file with comments | « chrome/browser/android/vr_shell/ui_elements/textured_element.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 11 matching lines...) Expand all
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 } 29 }
30 30
31 void TexturedElement::UpdateTexture() { 31 void TexturedElement::UpdateTexture() {
32 if (!initialized_ || !GetTexture()->dirty() || !IsVisible()) 32 if (!initialized_ || !GetTexture()->dirty())
33 return; 33 return;
34 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul( 34 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(
35 texture_size_.width(), texture_size_.height()); 35 texture_size_.width(), texture_size_.height());
36 GetTexture()->DrawAndLayout(surface->getCanvas(), texture_size_); 36 GetTexture()->DrawAndLayout(surface->getCanvas(), texture_size_);
37 Flush(surface.get()); 37 Flush(surface.get());
38 // Update the element size's aspect ratio to match the texture. 38 // Update the element size's aspect ratio to match the texture.
39 UpdateElementSize(); 39 UpdateElementSize();
40 } 40 }
41 41
42 void TexturedElement::UpdateElementSize() { 42 void TexturedElement::UpdateElementSize() {
43 // Updating the height according to width is a hack. This may be overridden. 43 // Updating the height according to width is a hack. This may be overridden.
44 gfx::SizeF drawn_size = GetTexture()->GetDrawnSize(); 44 gfx::SizeF drawn_size = GetTexture()->GetDrawnSize();
45 float y = drawn_size.height() / drawn_size.width() * size().x(); 45 float y = drawn_size.height() / drawn_size.width() * size().x();
46 set_size({size().x(), y, 1}); 46 set_size({size().x(), y, 1});
47 } 47 }
48 48
49 void TexturedElement::Render(UiElementRenderer* renderer, 49 void TexturedElement::Render(UiElementRenderer* renderer,
50 gfx::Transform view_proj_matrix) const { 50 gfx::Transform view_proj_matrix) const {
51 if (!initialized_) 51 if (!initialized_)
52 return; 52 return;
53 DCHECK(!GetTexture()->dirty());
54 gfx::SizeF drawn_size = GetTexture()->GetDrawnSize(); 53 gfx::SizeF drawn_size = GetTexture()->GetDrawnSize();
55 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(),
56 drawn_size.height() / texture_size_.height()); 55 drawn_size.height() / texture_size_.height());
57 renderer->DrawTexturedQuad(texture_handle_, view_proj_matrix, copy_rect, 56 renderer->DrawTexturedQuad(texture_handle_, view_proj_matrix, copy_rect,
58 opacity()); 57 opacity());
59 } 58 }
60 59
61 void TexturedElement::Flush(SkSurface* surface) { 60 void TexturedElement::Flush(SkSurface* surface) {
62 cc::SkiaPaintCanvas paint_canvas(surface->getCanvas()); 61 cc::SkiaPaintCanvas paint_canvas(surface->getCanvas());
63 paint_canvas.flush(); 62 paint_canvas.flush();
64 SkPixmap pixmap; 63 SkPixmap pixmap;
65 CHECK(surface->peekPixels(&pixmap)); 64 CHECK(surface->peekPixels(&pixmap));
66 65
67 glBindTexture(GL_TEXTURE_2D, texture_handle_); 66 glBindTexture(GL_TEXTURE_2D, texture_handle_);
68 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 67 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
69 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 68 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
70 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 69 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
71 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 70 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
72 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,
73 GL_RGBA, GL_UNSIGNED_BYTE, pixmap.addr()); 72 GL_RGBA, GL_UNSIGNED_BYTE, pixmap.addr());
74 } 73 }
75 74
76 void TexturedElement::OnSetMode() { 75 void TexturedElement::OnSetMode() {
77 GetTexture()->SetMode(mode()); 76 GetTexture()->SetMode(mode());
78 UpdateTexture(); 77 UpdateTexture();
79 } 78 }
80 79
81 void TexturedElement::OnBeginFrame(const base::TimeTicks& begin_frame_time) {
82 UpdateTexture();
83 }
84
85 } // namespace vr_shell 80 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/ui_elements/textured_element.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698