Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/android/vr_shell/textured_element.h" | |
| 6 | |
| 7 #include "cc/paint/skia_paint_canvas.h" | |
| 8 #include "chrome/browser/android/vr_shell/textures/ui_texture.h" | |
| 9 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" | |
| 10 #include "third_party/skia/include/core/SkSurface.h" | |
| 11 | |
| 12 namespace vr_shell { | |
| 13 | |
| 14 TexturedElement::TexturedElement(int preferred_width) | |
| 15 : texture_handle_(-1), preferred_width_(preferred_width) {} | |
| 16 | |
| 17 TexturedElement::~TexturedElement() = default; | |
| 18 | |
| 19 void TexturedElement::Initialize() { | |
| 20 glGenTextures(1, &texture_handle_); | |
| 21 DCHECK(GetTexture() != nullptr); | |
| 22 size_ = GetTexture()->GetPreferredTextureSize(preferred_width_); | |
|
acondor_
2017/04/21 15:04:23
I would use the word Maximum instead of Preferred,
mthiesse
2017/04/21 17:17:30
Done.
| |
| 23 sk_sp<SkSurface> surface = | |
| 24 SkSurface::MakeRasterN32Premul(size_.width(), size_.height()); | |
| 25 GetTexture()->DrawAndLayout(surface->getCanvas(), size_); | |
| 26 Flush(surface.get()); | |
| 27 fill = Fill::SELF; | |
| 28 gfx::SizeF actual_size = GetTexture()->GetActualSize(); | |
|
acondor_
2017/04/21 15:04:23
drawn_size maybe?
mthiesse
2017/04/21 17:17:29
Done.
| |
| 29 float y = actual_size.height() / actual_size.width() * size.x(); | |
| 30 size = {size.x(), y, 1}; | |
|
cjgrant
2017/04/21 14:30:13
This is a little interesting in that the scene man
acondor_
2017/04/21 15:04:23
Are we sure we want to fix X coordinate globally?
mthiesse
2017/04/21 15:05:11
Yeah, I want to refactor this in the future. We sh
| |
| 31 } | |
| 32 | |
| 33 void TexturedElement::Render(VrShellRenderer* renderer, | |
| 34 vr::Mat4f view_proj_matrix) const { | |
| 35 gfx::SizeF actual_size = GetTexture()->GetActualSize(); | |
| 36 gfx::RectF copy_rect(0, 0, actual_size.width() / size_.width(), | |
| 37 actual_size.height() / size_.height()); | |
| 38 renderer->GetSkiaQuadRenderer()->AddQuad(texture_handle_, view_proj_matrix, | |
| 39 copy_rect, opacity); | |
| 40 } | |
| 41 | |
| 42 void TexturedElement::Flush(SkSurface* surface) { | |
| 43 cc::SkiaPaintCanvas paint_canvas(surface->getCanvas()); | |
| 44 paint_canvas.flush(); | |
| 45 SkPixmap pixmap; | |
| 46 CHECK(surface->peekPixels(&pixmap)); | |
| 47 | |
| 48 glBindTexture(GL_TEXTURE_2D, texture_handle_); | |
| 49 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixmap.width(), pixmap.height(), 0, | |
| 50 GL_RGBA, GL_UNSIGNED_BYTE, pixmap.addr()); | |
| 51 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
|
cjgrant
2017/04/21 14:30:13
Aren't these the same properties being set at rend
acondor_
2017/04/21 15:04:23
They are ok here, once per the whole execution and
mthiesse
2017/04/21 15:05:11
yes. I didn't write this part so I'm not actually
mthiesse
2017/04/21 17:17:30
Done.
| |
| 52 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
| 53 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
| 54 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |
| 55 } | |
| 56 | |
| 57 } // namespace vr_shell | |
| OLD | NEW |