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

Unified Diff: chrome/browser/android/vr_shell/textured_element.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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/vr_shell/textured_element.cc
diff --git a/chrome/browser/android/vr_shell/textured_element.cc b/chrome/browser/android/vr_shell/textured_element.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a10d5e65c106c2895c1c2274f21af604d4d0ce49
--- /dev/null
+++ b/chrome/browser/android/vr_shell/textured_element.cc
@@ -0,0 +1,57 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/android/vr_shell/textured_element.h"
+
+#include "cc/paint/skia_paint_canvas.h"
+#include "chrome/browser/android/vr_shell/textures/ui_texture.h"
+#include "chrome/browser/android/vr_shell/vr_shell_renderer.h"
+#include "third_party/skia/include/core/SkSurface.h"
+
+namespace vr_shell {
+
+TexturedElement::TexturedElement(int preferred_width)
+ : texture_handle_(-1), preferred_width_(preferred_width) {}
+
+TexturedElement::~TexturedElement() = default;
+
+void TexturedElement::Initialize() {
+ glGenTextures(1, &texture_handle_);
+ DCHECK(GetTexture() != nullptr);
+ 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.
+ sk_sp<SkSurface> surface =
+ SkSurface::MakeRasterN32Premul(size_.width(), size_.height());
+ GetTexture()->DrawAndLayout(surface->getCanvas(), size_);
+ Flush(surface.get());
+ fill = Fill::SELF;
+ gfx::SizeF actual_size = GetTexture()->GetActualSize();
acondor_ 2017/04/21 15:04:23 drawn_size maybe?
mthiesse 2017/04/21 17:17:29 Done.
+ float y = actual_size.height() / actual_size.width() * size.x();
+ 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
+}
+
+void TexturedElement::Render(VrShellRenderer* renderer,
+ vr::Mat4f view_proj_matrix) const {
+ gfx::SizeF actual_size = GetTexture()->GetActualSize();
+ gfx::RectF copy_rect(0, 0, actual_size.width() / size_.width(),
+ actual_size.height() / size_.height());
+ renderer->GetSkiaQuadRenderer()->AddQuad(texture_handle_, view_proj_matrix,
+ copy_rect, opacity);
+}
+
+void TexturedElement::Flush(SkSurface* surface) {
+ cc::SkiaPaintCanvas paint_canvas(surface->getCanvas());
+ paint_canvas.flush();
+ SkPixmap pixmap;
+ CHECK(surface->peekPixels(&pixmap));
+
+ glBindTexture(GL_TEXTURE_2D, texture_handle_);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixmap.width(), pixmap.height(), 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, pixmap.addr());
+ 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.
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+}
+
+} // namespace vr_shell

Powered by Google App Engine
This is Rietveld 408576698