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

Unified Diff: third_party/WebKit/Source/modules/vr/VRDisplay.cpp

Issue 2552443002: WebVR: Add sanity checks for decoded pose index values (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « device/vr/android/gvr/gvr_device_provider.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/vr/VRDisplay.cpp
diff --git a/third_party/WebKit/Source/modules/vr/VRDisplay.cpp b/third_party/WebKit/Source/modules/vr/VRDisplay.cpp
index c286f069f65efba7d5c194963e6b69a5bd3a168b..4d3a8aa3eaba490da39c512b03b8a40b9a318b77 100644
--- a/third_party/WebKit/Source/modules/vr/VRDisplay.cpp
+++ b/third_party/WebKit/Source/modules/vr/VRDisplay.cpp
@@ -28,10 +28,16 @@
#include "public/platform/Platform.h"
#include "wtf/AutoReset.h"
+#include <array>
+
namespace blink {
namespace {
+// Magic numbers used to mark valid pose index values encoded in frame
+// data. Must match the magic numbers used in vr_shell.cc.
+static constexpr std::array<uint8_t, 2> kWebVrPosePixelMagicNumbers{{42, 142}};
+
VREye stringToVREye(const String& whichEye) {
if (whichEye == "left")
return VREyeLeft;
@@ -612,8 +618,11 @@ void VRDisplay::submitFrame() {
gl->ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
int idx = m_framePose->poseIndex;
// Careful with the arithmetic here. Float color 1.f is equivalent to int 255.
- gl->ClearColor((idx & 255) / 255.0f, ((idx >> 8) & 255) / 255.0f,
- ((idx >> 16) & 255) / 255.0f, 1.0f);
+ // Use the low byte of the index as the red component, and store an arbitrary
+ // magic number in green/blue. This number must match the reading code in
+ // vr_shell.cc. Avoid all-black/all-white.
+ gl->ClearColor((idx & 255) / 255.0f, kWebVrPosePixelMagicNumbers[0] / 255.0f,
+ kWebVrPosePixelMagicNumbers[1] / 255.0f, 1.0f);
gl->Clear(GL_COLOR_BUFFER_BIT);
// Set the GL state back to what was set by the WebVR application.
« no previous file with comments | « device/vr/android/gvr/gvr_device_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698