[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor-browser] 06/08: Bug 1789729 - Implement webgl.max-size-per-texture-mib r=jgilbert a=RyanVM



This is an automated email from the git hooks/post-receive script.

richard pushed a commit to branch tor-browser-91.13.0esr-11.5-1
in repository tor-browser.

commit dfbfb21bef071a5504b5a67c6f384683b5cd37ae
Author: Ashly Hale <ahale@xxxxxxxxxxx>
AuthorDate: Mon Oct 3 13:27:12 2022 +0000

    Bug 1789729 - Implement webgl.max-size-per-texture-mib r=jgilbert a=RyanVM
    
    Differential Revision: https://phabricator.services.mozilla.com/D156903
---
 dom/canvas/WebGLTextureUpload.cpp        | 33 +++++++++++++++++++++++++-------
 modules/libpref/init/StaticPrefList.yaml |  5 +++++
 2 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/dom/canvas/WebGLTextureUpload.cpp b/dom/canvas/WebGLTextureUpload.cpp
index 56d29e1c3e97..fd70799e6777 100644
--- a/dom/canvas/WebGLTextureUpload.cpp
+++ b/dom/canvas/WebGLTextureUpload.cpp
@@ -752,9 +752,27 @@ static bool ValidateCompressedTexImageRestrictions(
   return true;
 }
 
-static bool ValidateTargetForFormat(const WebGLContext* webgl,
-                                    TexImageTarget target,
-                                    const webgl::FormatInfo* format) {
+static bool ValidateFormatAndSize(const WebGLContext* webgl,
+                                  TexImageTarget target,
+                                  const webgl::FormatInfo* format,
+                                  const uvec3& size) {
+  // Check if texture size will likely be rejected by the driver and give a more
+  // meaningful error message.
+  auto baseImageSize = CheckedInt<uint64_t>(format->estimatedBytesPerPixel) *
+                       (uint32_t)size.x * (uint32_t)size.y * (uint32_t)size.z;
+  if (target == LOCAL_GL_TEXTURE_CUBE_MAP) {
+    baseImageSize *= 6;
+  }
+  if (!baseImageSize.isValid() ||
+      baseImageSize.value() >
+          (uint64_t)StaticPrefs::webgl_max_size_per_texture_mib() *
+              (1024 * 1024)) {
+    webgl->ErrorOutOfMemory(
+        "Texture size too large; base image mebibytes > "
+        "webgl.max-size-per-texture-mib");
+    return false;
+  }
+
   // GLES 3.0.4 p127:
   // "Textures with a base internal format of DEPTH_COMPONENT or DEPTH_STENCIL
   // are supported by texture image specification commands only if `target` is
@@ -822,7 +840,7 @@ void WebGLTexture::TexStorage(TexTarget target, uint32_t levels,
   }
   auto dstFormat = dstUsage->format;
 
-  if (!ValidateTargetForFormat(mContext, testTarget, dstFormat)) return;
+  if (!ValidateFormatAndSize(mContext, testTarget, dstFormat, size)) return;
 
   if (dstFormat->compression) {
     if (!ValidateCompressedTexImageRestrictions(mContext, testTarget, 0,
@@ -987,7 +1005,7 @@ void WebGLTexture::TexImage(uint32_t level, GLenum respecFormat,
     }
 
     const auto& dstFormat = dstUsage->format;
-    if (!ValidateTargetForFormat(mContext, imageTarget, dstFormat)) return;
+    if (!ValidateFormatAndSize(mContext, imageTarget, dstFormat, size)) return;
 
     if (!mContext->IsWebGL2() && dstFormat->d) {
       if (imageTarget != LOCAL_GL_TEXTURE_2D || blob->HasData() || level != 0) {
@@ -1179,7 +1197,8 @@ void WebGLTexture::CompressedTexImage(bool sub, GLenum imageTarget,
     }
     MOZ_ASSERT(imageInfo);
 
-    if (!ValidateTargetForFormat(mContext, imageTarget, usage->format)) return;
+    if (!ValidateFormatAndSize(mContext, imageTarget, usage->format, size))
+      return;
     if (!ValidateCompressedTexImageRestrictions(mContext, imageTarget, level,
                                                 usage->format, size)) {
       return;
@@ -1815,7 +1834,7 @@ void WebGLTexture::CopyTexImage(GLenum imageTarget, uint32_t level,
     dstUsage = ValidateCopyDestUsage(mContext, srcFormat, respecFormat);
     if (!dstUsage) return;
 
-    if (!ValidateTargetForFormat(mContext, imageTarget, dstUsage->format))
+    if (!ValidateFormatAndSize(mContext, imageTarget, dstUsage->format, size))
       return;
   } else {
     if (!ValidateTexImageSelection(imageTarget, level, dstOffset, size,
diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml
index 243585deecbf..b87714065456 100644
--- a/modules/libpref/init/StaticPrefList.yaml
+++ b/modules/libpref/init/StaticPrefList.yaml
@@ -11419,6 +11419,11 @@
   value: 300
   mirror: always
 
+- name: webgl.max-size-per-texture-mib
+  type: RelaxedAtomicUint32
+  value: 1024
+  mirror: always
+
 - name: webgl.max-warnings-per-context
   type: RelaxedAtomicUint32
   value: 32

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits