2018-11-30 19:52:05 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-08-03 21:34:46 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "WebGLTexture.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
2016-05-08 22:33:00 +00:00
|
|
|
|
2015-08-03 21:34:46 +00:00
|
|
|
#include "CanvasUtils.h"
|
2016-07-22 06:25:41 +00:00
|
|
|
#include "gfxPrefs.h"
|
2015-08-03 21:34:46 +00:00
|
|
|
#include "GLBlitHelper.h"
|
|
|
|
#include "GLContext.h"
|
2016-05-08 22:33:00 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2018-11-06 22:31:34 +00:00
|
|
|
#include "mozilla/dom/HTMLCanvasElement.h"
|
2015-08-03 21:34:46 +00:00
|
|
|
#include "mozilla/dom/HTMLVideoElement.h"
|
2016-12-20 22:59:51 +00:00
|
|
|
#include "mozilla/dom/ImageBitmap.h"
|
2015-08-03 21:34:46 +00:00
|
|
|
#include "mozilla/dom/ImageData.h"
|
|
|
|
#include "mozilla/MathAlgorithms.h"
|
|
|
|
#include "mozilla/Scoped.h"
|
2016-08-23 04:09:32 +00:00
|
|
|
#include "mozilla/Unused.h"
|
2015-08-03 21:34:46 +00:00
|
|
|
#include "ScopedGLHelpers.h"
|
2015-11-25 04:15:29 +00:00
|
|
|
#include "TexUnpackBlob.h"
|
2016-09-10 04:02:54 +00:00
|
|
|
#include "WebGLBuffer.h"
|
2015-08-03 21:34:46 +00:00
|
|
|
#include "WebGLContext.h"
|
|
|
|
#include "WebGLContextUtils.h"
|
|
|
|
#include "WebGLFramebuffer.h"
|
|
|
|
#include "WebGLTexelConversions.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
/* This file handles:
|
|
|
|
* TexStorage2D(texTarget, levels, internalFormat, width, height)
|
|
|
|
* TexStorage3D(texTarget, levels, intenralFormat, width, height, depth)
|
|
|
|
*
|
2018-11-27 10:08:58 +00:00
|
|
|
* TexImage2D(texImageTarget, level, internalFormat, width, height, border,
|
2015-11-25 04:15:29 +00:00
|
|
|
* unpackFormat, unpackType, data)
|
2018-11-27 10:08:58 +00:00
|
|
|
* TexImage3D(texImageTarget, level, internalFormat, width, height, depth,
|
|
|
|
* border, unpackFormat, unpackType, data)
|
|
|
|
* TexSubImage2D(texImageTarget, level, xOffset, yOffset, width, height,
|
2015-11-25 04:15:29 +00:00
|
|
|
* unpackFormat, unpackType, data)
|
2018-11-27 10:08:58 +00:00
|
|
|
* TexSubImage3D(texImageTarget, level, xOffset, yOffset, zOffset, width,
|
|
|
|
* height, depth, unpackFormat, unpackType, data)
|
2015-11-25 04:15:29 +00:00
|
|
|
*
|
2018-11-27 10:08:58 +00:00
|
|
|
* CompressedTexImage2D(texImageTarget, level, internalFormat, width, height,
|
2015-11-25 04:15:29 +00:00
|
|
|
* border, imageSize, data)
|
2018-11-27 10:08:58 +00:00
|
|
|
* CompressedTexImage3D(texImageTarget, level, internalFormat, width, height,
|
|
|
|
* depth, border, imageSize, data)
|
|
|
|
* CompressedTexSubImage2D(texImageTarget, level, xOffset, yOffset, width,
|
|
|
|
* height, sizedUnpackFormat, imageSize, data)
|
|
|
|
* CompressedTexSubImage3D(texImageTarget, level, xOffset, yOffset, zOffset,
|
|
|
|
* width, height, depth, sizedUnpackFormat, imageSize,
|
|
|
|
* data)
|
2015-11-25 04:15:29 +00:00
|
|
|
*
|
2018-11-27 10:08:58 +00:00
|
|
|
* CopyTexImage2D(texImageTarget, level, internalFormat, x, y, width, height,
|
|
|
|
* border)
|
|
|
|
* CopyTexImage3D - "Because the framebuffer is inhererntly two-dimensional,
|
|
|
|
* there is no CopyTexImage3D command."
|
|
|
|
* CopyTexSubImage2D(texImageTarget, level, xOffset, yOffset, x, y, width,
|
2015-11-25 04:15:29 +00:00
|
|
|
* height)
|
2018-11-27 10:08:58 +00:00
|
|
|
* CopyTexSubImage3D(texImageTarget, level, xOffset, yOffset, zOffset, x, y,
|
|
|
|
* width, height)
|
2015-11-25 04:15:29 +00:00
|
|
|
*/
|
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
static bool ValidateExtents(WebGLContext* webgl, GLsizei width, GLsizei height,
|
2016-06-22 17:28:11 +00:00
|
|
|
GLsizei depth, GLint border,
|
|
|
|
uint32_t* const out_width,
|
|
|
|
uint32_t* const out_height,
|
|
|
|
uint32_t* const out_depth) {
|
|
|
|
// Check border
|
|
|
|
if (border != 0) {
|
2018-07-27 04:46:33 +00:00
|
|
|
webgl->ErrorInvalidValue("`border` must be 0.");
|
2016-06-22 17:28:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (width < 0 || height < 0 || depth < 0) {
|
|
|
|
/* GL ES Version 2.0.25 - 3.7.1 Texture Image Specification
|
|
|
|
* "If wt and ht are the specified image width and height,
|
|
|
|
* and if either wt or ht are less than zero, then the error
|
|
|
|
* INVALID_VALUE is generated."
|
|
|
|
*/
|
2018-07-27 04:46:33 +00:00
|
|
|
webgl->ErrorInvalidValue("`width`/`height`/`depth` must be >= 0.");
|
2016-06-22 17:28:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*out_width = width;
|
|
|
|
*out_height = height;
|
|
|
|
*out_depth = depth;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////////
|
|
|
|
// ArrayBufferView?
|
|
|
|
|
|
|
|
static inline bool DoesJSTypeMatchUnpackType(GLenum unpackType,
|
|
|
|
js::Scalar::Type jsType) {
|
|
|
|
switch (unpackType) {
|
|
|
|
case LOCAL_GL_BYTE:
|
|
|
|
return jsType == js::Scalar::Type::Int8;
|
|
|
|
|
|
|
|
case LOCAL_GL_UNSIGNED_BYTE:
|
|
|
|
return jsType == js::Scalar::Type::Uint8 ||
|
|
|
|
jsType == js::Scalar::Type::Uint8Clamped;
|
|
|
|
|
|
|
|
case LOCAL_GL_SHORT:
|
|
|
|
return jsType == js::Scalar::Type::Int16;
|
|
|
|
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT:
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT_4_4_4_4:
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT_5_5_5_1:
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT_5_6_5:
|
|
|
|
case LOCAL_GL_HALF_FLOAT:
|
|
|
|
case LOCAL_GL_HALF_FLOAT_OES:
|
|
|
|
return jsType == js::Scalar::Type::Uint16;
|
|
|
|
|
|
|
|
case LOCAL_GL_INT:
|
|
|
|
return jsType == js::Scalar::Type::Int32;
|
|
|
|
|
|
|
|
case LOCAL_GL_UNSIGNED_INT:
|
|
|
|
case LOCAL_GL_UNSIGNED_INT_2_10_10_10_REV:
|
|
|
|
case LOCAL_GL_UNSIGNED_INT_10F_11F_11F_REV:
|
|
|
|
case LOCAL_GL_UNSIGNED_INT_5_9_9_9_REV:
|
|
|
|
case LOCAL_GL_UNSIGNED_INT_24_8:
|
|
|
|
return jsType == js::Scalar::Type::Uint32;
|
|
|
|
|
|
|
|
case LOCAL_GL_FLOAT:
|
|
|
|
return jsType == js::Scalar::Type::Float32;
|
2015-11-24 03:27:13 +00:00
|
|
|
|
2015-11-24 05:55:59 +00:00
|
|
|
default:
|
2015-11-25 04:15:29 +00:00
|
|
|
return false;
|
2015-11-24 03:27:13 +00:00
|
|
|
}
|
2015-11-25 04:15:29 +00:00
|
|
|
}
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
static bool ValidateViewType(WebGLContext* webgl, GLenum unpackType,
|
2016-10-21 01:03:40 +00:00
|
|
|
const TexImageSource& src) {
|
|
|
|
if (!src.mView) return true;
|
|
|
|
const auto& view = *(src.mView);
|
2016-07-22 02:20:21 +00:00
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
const auto& jsType = view.Type();
|
|
|
|
if (!DoesJSTypeMatchUnpackType(unpackType, jsType)) {
|
2018-07-27 04:46:33 +00:00
|
|
|
webgl->ErrorInvalidOperation(
|
|
|
|
"ArrayBufferView type not compatible with"
|
|
|
|
" `type`.");
|
2016-07-22 02:20:21 +00:00
|
|
|
return false;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
return true;
|
2016-07-22 02:20:21 +00:00
|
|
|
}
|
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
static bool ValidateUnpackInfo(WebGLContext* webgl,
|
|
|
|
const webgl::PackingInfo& pi) {
|
2016-10-21 01:03:40 +00:00
|
|
|
if (!webgl->mFormatUsage->AreUnpackEnumsValid(pi.format, pi.type)) {
|
2018-07-27 04:46:33 +00:00
|
|
|
webgl->ErrorInvalidEnum("Invalid unpack format/type: 0x%04x/0x%04x",
|
2016-10-21 01:03:40 +00:00
|
|
|
pi.format, pi.type);
|
2016-07-22 02:20:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2016-07-22 02:20:21 +00:00
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
static UniquePtr<webgl::TexUnpackBytes> FromView(
|
2018-07-27 04:46:33 +00:00
|
|
|
WebGLContext* webgl, TexImageTarget target, uint32_t width, uint32_t height,
|
2016-10-28 02:03:20 +00:00
|
|
|
uint32_t depth, const dom::ArrayBufferView* view, GLuint viewElemOffset,
|
|
|
|
GLuint viewElemLengthOverride) {
|
2016-10-21 01:03:40 +00:00
|
|
|
const bool isClientData = true;
|
2016-07-22 03:03:16 +00:00
|
|
|
const uint8_t* bytes = nullptr;
|
2016-10-21 01:03:40 +00:00
|
|
|
size_t availByteCount = 0;
|
|
|
|
if (view) {
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!webgl->ValidateArrayBufferView(
|
2016-10-28 02:03:20 +00:00
|
|
|
*view, viewElemOffset, viewElemLengthOverride,
|
2016-10-21 01:03:40 +00:00
|
|
|
const_cast<uint8_t**>(&bytes), &availByteCount)) {
|
|
|
|
return nullptr;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2016-10-12 01:54:59 +00:00
|
|
|
}
|
2016-10-21 01:03:40 +00:00
|
|
|
return MakeUnique<webgl::TexUnpackBytes>(webgl, target, width, height, depth,
|
|
|
|
isClientData, bytes, availByteCount);
|
2015-11-25 04:15:29 +00:00
|
|
|
}
|
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
static UniquePtr<webgl::TexUnpackBytes> FromPboOffset(
|
2018-07-27 04:46:33 +00:00
|
|
|
WebGLContext* webgl, TexImageTarget target, uint32_t width, uint32_t height,
|
2017-07-18 18:02:57 +00:00
|
|
|
uint32_t depth, WebGLsizeiptr pboOffset,
|
|
|
|
const Maybe<GLsizei>& expectedImageSize) {
|
2016-10-21 01:03:40 +00:00
|
|
|
if (pboOffset < 0) {
|
2018-07-27 04:46:33 +00:00
|
|
|
webgl->ErrorInvalidValue("offset cannot be negative.");
|
2016-10-21 01:03:40 +00:00
|
|
|
return nullptr;
|
2016-06-22 17:28:11 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
const auto& buffer =
|
|
|
|
webgl->ValidateBufferSelection(LOCAL_GL_PIXEL_UNPACK_BUFFER);
|
2016-11-18 01:50:38 +00:00
|
|
|
if (!buffer) return nullptr;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-11-18 01:50:38 +00:00
|
|
|
size_t availBufferBytes = buffer->ByteLength();
|
2016-10-21 01:03:40 +00:00
|
|
|
if (size_t(pboOffset) > availBufferBytes) {
|
2018-07-27 04:46:33 +00:00
|
|
|
webgl->ErrorInvalidOperation("Offset is passed end of buffer.");
|
2016-10-21 01:03:40 +00:00
|
|
|
return nullptr;
|
2016-07-22 02:20:21 +00:00
|
|
|
}
|
2016-10-21 01:03:40 +00:00
|
|
|
availBufferBytes -= pboOffset;
|
2017-07-18 18:02:57 +00:00
|
|
|
if (expectedImageSize.isSome()) {
|
|
|
|
if (expectedImageSize.ref() < 0) {
|
2018-07-27 04:46:33 +00:00
|
|
|
webgl->ErrorInvalidValue("ImageSize can't be less than 0.");
|
2017-07-18 18:02:57 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (size_t(expectedImageSize.ref()) != availBufferBytes) {
|
2018-07-27 04:46:33 +00:00
|
|
|
webgl->ErrorInvalidOperation(
|
|
|
|
"ImageSize doesn't match the required upload byte size.");
|
2017-07-18 18:02:57 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
availBufferBytes = size_t(expectedImageSize.ref());
|
|
|
|
}
|
2016-07-22 02:20:21 +00:00
|
|
|
const bool isClientData = false;
|
2016-10-21 01:03:40 +00:00
|
|
|
const auto ptr = (const uint8_t*)pboOffset;
|
|
|
|
return MakeUnique<webgl::TexUnpackBytes>(webgl, target, width, height, depth,
|
|
|
|
isClientData, ptr, availBufferBytes);
|
2015-11-25 04:15:29 +00:00
|
|
|
}
|
|
|
|
|
2016-12-20 22:59:51 +00:00
|
|
|
static UniquePtr<webgl::TexUnpackBlob> FromImageBitmap(
|
2018-07-27 04:46:33 +00:00
|
|
|
WebGLContext* webgl, TexImageTarget target, uint32_t width, uint32_t height,
|
2018-11-06 22:31:34 +00:00
|
|
|
uint32_t depth, const dom::ImageBitmap& imageBitmap, ErrorResult* aRv) {
|
|
|
|
if (imageBitmap.IsWriteOnly()) {
|
|
|
|
aRv->Throw(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-06-01 15:59:07 +00:00
|
|
|
UniquePtr<dom::ImageBitmapCloneData> cloneData = imageBitmap.ToCloneData();
|
2018-03-14 16:37:34 +00:00
|
|
|
if (!cloneData) {
|
2018-11-06 22:31:34 +00:00
|
|
|
return nullptr;
|
2018-03-14 16:37:34 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-12-20 22:59:51 +00:00
|
|
|
const RefPtr<gfx::DataSourceSurface> surf = cloneData->mSurface;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-12-20 22:59:51 +00:00
|
|
|
if (!width) {
|
|
|
|
width = surf->GetSize().width;
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-12-20 22:59:51 +00:00
|
|
|
if (!height) {
|
|
|
|
height = surf->GetSize().height;
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-12-20 22:59:51 +00:00
|
|
|
// WhatWG "HTML Living Standard" (30 October 2015):
|
|
|
|
// "The getImageData(sx, sy, sw, sh) method [...] Pixels must be returned as
|
2018-11-27 10:08:58 +00:00
|
|
|
// non-premultiplied alpha values."
|
2016-12-20 22:59:51 +00:00
|
|
|
return MakeUnique<webgl::TexUnpackSurface>(
|
|
|
|
webgl, target, width, height, depth, surf, cloneData->mAlphaType);
|
|
|
|
}
|
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
static UniquePtr<webgl::TexUnpackBlob> FromImageData(
|
2018-07-27 04:46:33 +00:00
|
|
|
WebGLContext* webgl, TexImageTarget target, uint32_t width, uint32_t height,
|
2016-08-10 00:16:09 +00:00
|
|
|
uint32_t depth, const dom::ImageData& imageData,
|
2015-11-25 04:15:29 +00:00
|
|
|
dom::Uint8ClampedArray* scopedArr) {
|
2018-07-27 04:46:33 +00:00
|
|
|
DebugOnly<bool> inited = scopedArr->Init(imageData.GetDataObject());
|
|
|
|
MOZ_ASSERT(inited);
|
2016-06-22 17:28:11 +00:00
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
scopedArr->ComputeLengthAndData();
|
|
|
|
const DebugOnly<size_t> dataSize = scopedArr->Length();
|
|
|
|
const void* const data = scopedArr->Data();
|
2015-11-25 04:15:29 +00:00
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
const gfx::IntSize size(imageData.Width(), imageData.Height());
|
|
|
|
const size_t stride = size.width * 4;
|
|
|
|
const gfx::SurfaceFormat surfFormat = gfx::SurfaceFormat::R8G8B8A8;
|
2015-11-25 04:15:29 +00:00
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
// WhatWG "HTML Living Standard" (30 October 2015):
|
|
|
|
// "The getImageData(sx, sy, sw, sh) method [...] Pixels must be returned as
|
2016-10-21 01:03:40 +00:00
|
|
|
// non-premultiplied alpha values."
|
2018-11-06 22:31:34 +00:00
|
|
|
const auto alphaType = gfxAlphaType::NonPremult;
|
|
|
|
|
2017-04-13 08:40:45 +00:00
|
|
|
MOZ_ASSERT(dataSize == stride * size.height);
|
2016-07-12 05:51:19 +00:00
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
uint8_t* wrappableData = (uint8_t*)data;
|
2016-07-12 05:51:19 +00:00
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
const RefPtr<gfx::DataSourceSurface> surf =
|
|
|
|
gfx::Factory::CreateWrappingDataSourceSurface(wrappableData, stride, size,
|
2016-05-08 22:33:00 +00:00
|
|
|
surfFormat);
|
2016-10-21 01:03:40 +00:00
|
|
|
if (!surf) {
|
2016-07-12 05:51:19 +00:00
|
|
|
webgl->ErrorOutOfMemory("OOM in FromImageData.");
|
|
|
|
return nullptr;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2016-07-12 05:51:19 +00:00
|
|
|
|
|
|
|
////
|
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
if (!width) {
|
2016-06-22 17:28:11 +00:00
|
|
|
width = imageData.Width();
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2015-11-25 04:15:29 +00:00
|
|
|
|
2016-06-22 17:28:11 +00:00
|
|
|
if (!height) {
|
|
|
|
height = imageData.Height();
|
|
|
|
}
|
|
|
|
|
2018-11-30 10:46:48 +00:00
|
|
|
////
|
2016-07-12 05:51:19 +00:00
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
return MakeUnique<webgl::TexUnpackSurface>(webgl, target, width, height,
|
2016-07-12 05:51:19 +00:00
|
|
|
depth, surf, alphaType);
|
2016-06-22 17:28:11 +00:00
|
|
|
}
|
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
UniquePtr<webgl::TexUnpackBlob> WebGLContext::FromDomElem(
|
|
|
|
TexImageTarget target, uint32_t width, uint32_t height, uint32_t depth,
|
2016-08-10 00:16:09 +00:00
|
|
|
const dom::Element& elem, ErrorResult* const out_error) {
|
2018-11-06 22:31:34 +00:00
|
|
|
if (elem.IsHTMLElement(nsGkAtoms::canvas)) {
|
|
|
|
const dom::HTMLCanvasElement* canvas =
|
|
|
|
static_cast<const dom::HTMLCanvasElement*>(&elem);
|
|
|
|
if (canvas->IsWriteOnly()) {
|
|
|
|
out_error->Throw(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return nullptr;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-13 08:40:45 +00:00
|
|
|
// The canvas spec says that drawImage should draw the first frame of
|
|
|
|
// animated images. The webgl spec doesn't mention the issue, so we do the
|
|
|
|
// same as drawImage.
|
|
|
|
uint32_t flags = nsLayoutUtils::SFE_WANT_FIRST_FRAME_IF_IMAGE |
|
|
|
|
nsLayoutUtils::SFE_WANT_IMAGE_SURFACE |
|
2016-07-12 05:51:19 +00:00
|
|
|
nsLayoutUtils::SFE_USE_ELEMENT_SIZE_IF_VECTOR;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
if (mPixelStore_ColorspaceConversion == LOCAL_GL_NONE)
|
2016-07-12 05:51:19 +00:00
|
|
|
flags |= nsLayoutUtils::SFE_NO_COLORSPACE_CONVERSION;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
if (!mPixelStore_PremultiplyAlpha)
|
2016-07-12 05:51:19 +00:00
|
|
|
flags |= nsLayoutUtils::SFE_PREFER_NO_PREMULTIPLY_ALPHA;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-07-12 05:51:19 +00:00
|
|
|
RefPtr<gfx::DrawTarget> idealDrawTarget = nullptr; // Don't care for now.
|
2016-08-10 00:16:09 +00:00
|
|
|
auto sfer = nsLayoutUtils::SurfaceFromElement(
|
|
|
|
const_cast<dom::Element*>(&elem), flags, idealDrawTarget);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
|
|
|
//////
|
|
|
|
|
2016-06-22 17:28:11 +00:00
|
|
|
uint32_t elemWidth = 0;
|
|
|
|
uint32_t elemHeight = 0;
|
|
|
|
layers::Image* layersImage = nullptr;
|
|
|
|
if (!gfxPrefs::WebGLDisableDOMBlitUploads() && sfer.mLayersImage) {
|
|
|
|
layersImage = sfer.mLayersImage;
|
|
|
|
elemWidth = layersImage->GetSize().width;
|
|
|
|
elemHeight = layersImage->GetSize().height;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
|
|
|
|
2016-07-12 05:51:19 +00:00
|
|
|
RefPtr<gfx::DataSourceSurface> dataSurf;
|
2016-06-22 17:28:11 +00:00
|
|
|
if (!layersImage && sfer.GetSourceSurface()) {
|
2016-07-12 05:51:19 +00:00
|
|
|
const auto surf = sfer.GetSourceSurface();
|
2016-06-22 17:28:11 +00:00
|
|
|
elemWidth = surf->GetSize().width;
|
|
|
|
elemHeight = surf->GetSize().height;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-07-12 05:51:19 +00:00
|
|
|
// WARNING: OSX can lose our MakeCurrent here.
|
|
|
|
dataSurf = surf->GetDataSurface();
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////
|
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
if (!width) {
|
|
|
|
width = elemWidth;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
if (!height) {
|
|
|
|
height = elemHeight;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////
|
|
|
|
|
2016-07-12 05:51:19 +00:00
|
|
|
if (!layersImage && !dataSurf) {
|
2016-07-22 02:20:21 +00:00
|
|
|
const bool isClientData = true;
|
2016-10-21 01:03:40 +00:00
|
|
|
return MakeUnique<webgl::TexUnpackBytes>(this, target, width, height, depth,
|
|
|
|
isClientData, nullptr, 0);
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////
|
|
|
|
|
2016-07-12 05:51:19 +00:00
|
|
|
// While it's counter-intuitive, the shape of the SFEResult API means that we
|
|
|
|
// should try to pull out a surface first, and then, if we do pull out a
|
|
|
|
// surface, check CORS/write-only/etc..
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-06-22 17:28:11 +00:00
|
|
|
if (!sfer.mCORSUsed) {
|
|
|
|
auto& srcPrincipal = sfer.mPrincipal;
|
2016-10-21 01:03:40 +00:00
|
|
|
nsIPrincipal* dstPrincipal = GetCanvas()->NodePrincipal();
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-06-22 17:28:11 +00:00
|
|
|
if (!dstPrincipal->Subsumes(srcPrincipal)) {
|
2018-07-27 04:46:33 +00:00
|
|
|
GenerateWarning("Cross-origin elements require CORS.");
|
2015-11-25 04:15:29 +00:00
|
|
|
out_error->Throw(NS_ERROR_DOM_SECURITY_ERR);
|
2016-10-21 01:03:40 +00:00
|
|
|
return nullptr;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-22 17:28:11 +00:00
|
|
|
if (sfer.mIsWriteOnly) {
|
|
|
|
// mIsWriteOnly defaults to true, and so will be true even if SFE merely
|
|
|
|
// failed. Thus we must test mIsWriteOnly after successfully retrieving an
|
|
|
|
// Image or SourceSurface.
|
2018-07-27 04:46:33 +00:00
|
|
|
GenerateWarning("Element is write-only, thus cannot be uploaded.");
|
2015-11-25 04:15:29 +00:00
|
|
|
out_error->Throw(NS_ERROR_DOM_SECURITY_ERR);
|
2016-10-21 01:03:40 +00:00
|
|
|
return nullptr;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////
|
2016-06-22 17:28:11 +00:00
|
|
|
// Ok, we're good!
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-06-22 17:28:11 +00:00
|
|
|
if (layersImage) {
|
2016-10-21 01:03:40 +00:00
|
|
|
return MakeUnique<webgl::TexUnpackImage>(this, target, width, height, depth,
|
2017-04-12 09:55:23 +00:00
|
|
|
layersImage, sfer.mAlphaType);
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
MOZ_ASSERT(dataSurf);
|
|
|
|
return MakeUnique<webgl::TexUnpackSurface>(this, target, width, height, depth,
|
2017-04-12 09:55:23 +00:00
|
|
|
dataSurf, sfer.mAlphaType);
|
2016-10-21 01:03:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////
|
2016-06-22 17:28:11 +00:00
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
UniquePtr<webgl::TexUnpackBlob> WebGLContext::From(
|
2018-07-27 04:46:33 +00:00
|
|
|
TexImageTarget target, GLsizei rawWidth, GLsizei rawHeight,
|
2016-10-21 01:03:40 +00:00
|
|
|
GLsizei rawDepth, GLint border, const TexImageSource& src,
|
|
|
|
dom::Uint8ClampedArray* const scopedArr) {
|
|
|
|
uint32_t width, height, depth;
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!ValidateExtents(this, rawWidth, rawHeight, rawDepth, border, &width,
|
2016-10-21 01:03:40 +00:00
|
|
|
&height, &depth)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
if (src.mPboOffset) {
|
2018-07-27 04:46:33 +00:00
|
|
|
return FromPboOffset(this, target, width, height, depth, *(src.mPboOffset),
|
2017-07-18 18:02:57 +00:00
|
|
|
Nothing());
|
2016-10-21 01:03:40 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
if (mBoundPixelUnpackBuffer) {
|
2018-07-27 04:46:33 +00:00
|
|
|
ErrorInvalidOperation("PIXEL_UNPACK_BUFFER must be null.");
|
2016-10-21 01:03:40 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-12-20 22:59:51 +00:00
|
|
|
if (src.mImageBitmap) {
|
2018-07-27 04:46:33 +00:00
|
|
|
return FromImageBitmap(this, target, width, height, depth,
|
2018-11-06 22:31:34 +00:00
|
|
|
*(src.mImageBitmap), src.mOut_error);
|
2016-12-20 22:59:51 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
if (src.mImageData) {
|
2018-07-27 04:46:33 +00:00
|
|
|
return FromImageData(this, target, width, height, depth, *(src.mImageData),
|
2016-10-21 01:03:40 +00:00
|
|
|
scopedArr);
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
if (src.mDomElem) {
|
2018-07-27 04:46:33 +00:00
|
|
|
return FromDomElem(target, width, height, depth, *(src.mDomElem),
|
2016-10-21 01:03:40 +00:00
|
|
|
src.mOut_error);
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
return FromView(this, target, width, height, depth, src.mView,
|
2016-10-28 02:03:20 +00:00
|
|
|
src.mViewElemOffset, src.mViewElemLengthOverride);
|
2015-11-25 04:15:29 +00:00
|
|
|
}
|
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2015-11-25 04:15:29 +00:00
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
static UniquePtr<webgl::TexUnpackBlob> ValidateTexOrSubImage(
|
2018-07-27 04:46:33 +00:00
|
|
|
WebGLContext* webgl, TexImageTarget target, GLsizei rawWidth,
|
2016-10-21 01:03:40 +00:00
|
|
|
GLsizei rawHeight, GLsizei rawDepth, GLint border,
|
|
|
|
const webgl::PackingInfo& pi, const TexImageSource& src,
|
|
|
|
dom::Uint8ClampedArray* const scopedArr) {
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!ValidateUnpackInfo(webgl, pi)) return nullptr;
|
2016-10-21 01:03:40 +00:00
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!ValidateViewType(webgl, pi.type, src)) return nullptr;
|
2016-10-21 01:03:40 +00:00
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
auto blob = webgl->From(target, rawWidth, rawHeight, rawDepth, border, src,
|
2016-10-21 01:03:40 +00:00
|
|
|
scopedArr);
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!blob || !blob->Validate(webgl, pi)) return nullptr;
|
2016-10-21 01:03:40 +00:00
|
|
|
|
2018-06-01 15:59:07 +00:00
|
|
|
return blob;
|
2016-10-21 01:03:40 +00:00
|
|
|
}
|
2015-11-25 04:15:29 +00:00
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
void WebGLTexture::TexImage(TexImageTarget target, GLint level,
|
2016-10-21 01:03:40 +00:00
|
|
|
GLenum internalFormat, GLsizei width,
|
|
|
|
GLsizei height, GLsizei depth, GLint border,
|
|
|
|
const webgl::PackingInfo& pi,
|
|
|
|
const TexImageSource& src) {
|
2017-08-11 01:04:54 +00:00
|
|
|
dom::RootedSpiderMonkeyInterface<dom::Uint8ClampedArray> scopedArr(
|
|
|
|
dom::RootingCx());
|
2018-07-27 04:46:33 +00:00
|
|
|
const auto blob = ValidateTexOrSubImage(mContext, target, width, height,
|
2016-10-21 01:03:40 +00:00
|
|
|
depth, border, pi, src, &scopedArr);
|
|
|
|
if (!blob) return;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
TexImage(target, level, internalFormat, pi, blob.get());
|
2016-10-21 01:03:40 +00:00
|
|
|
}
|
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
void WebGLTexture::TexSubImage(TexImageTarget target, GLint level,
|
2016-10-21 01:03:40 +00:00
|
|
|
GLint xOffset, GLint yOffset, GLint zOffset,
|
|
|
|
GLsizei width, GLsizei height, GLsizei depth,
|
|
|
|
const webgl::PackingInfo& pi,
|
|
|
|
const TexImageSource& src) {
|
|
|
|
const GLint border = 0;
|
2017-08-11 01:04:54 +00:00
|
|
|
dom::RootedSpiderMonkeyInterface<dom::Uint8ClampedArray> scopedArr(
|
|
|
|
dom::RootingCx());
|
2018-07-27 04:46:33 +00:00
|
|
|
const auto blob = ValidateTexOrSubImage(mContext, target, width, height,
|
2016-10-21 01:03:40 +00:00
|
|
|
depth, border, pi, src, &scopedArr);
|
|
|
|
if (!blob) return;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-12-20 01:43:12 +00:00
|
|
|
if (!blob->HasData()) {
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorInvalidValue("Source must not be null.");
|
2016-12-20 01:43:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
TexSubImage(target, level, xOffset, yOffset, zOffset, pi, blob.get());
|
2015-11-25 04:15:29 +00:00
|
|
|
}
|
2015-11-24 03:27:13 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
static bool ValidateTexImage(WebGLContext* webgl, WebGLTexture* texture,
|
2015-11-25 04:15:29 +00:00
|
|
|
TexImageTarget target, GLint level,
|
2018-10-17 04:18:15 +00:00
|
|
|
webgl::ImageInfo** const out_imageInfo) {
|
2015-11-25 04:15:29 +00:00
|
|
|
// Check level
|
|
|
|
if (level < 0) {
|
2018-07-27 04:46:33 +00:00
|
|
|
webgl->ErrorInvalidValue("`level` must be >= 0.");
|
2015-11-25 04:15:29 +00:00
|
|
|
return false;
|
2015-08-03 21:34:46 +00:00
|
|
|
}
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
if (level >= WebGLTexture::kMaxLevelCount) {
|
2018-07-27 04:46:33 +00:00
|
|
|
webgl->ErrorInvalidValue("`level` is too large.");
|
2015-11-25 04:15:29 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2018-10-17 04:18:15 +00:00
|
|
|
auto& imageInfo = texture->ImageInfoAt(target, level);
|
2015-11-25 04:15:29 +00:00
|
|
|
*out_imageInfo = &imageInfo;
|
|
|
|
return true;
|
2015-11-24 03:27:13 +00:00
|
|
|
}
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
// For *TexImage*
|
2018-07-27 04:46:33 +00:00
|
|
|
bool WebGLTexture::ValidateTexImageSpecification(
|
2016-12-15 03:03:25 +00:00
|
|
|
TexImageTarget target, GLint rawLevel, uint32_t width, uint32_t height,
|
2018-10-17 04:18:15 +00:00
|
|
|
uint32_t depth, webgl::ImageInfo** const out_imageInfo) {
|
2018-07-27 04:46:33 +00:00
|
|
|
if (mImmutable) {
|
|
|
|
mContext->ErrorInvalidOperation("Specified texture is immutable.");
|
2015-12-03 23:38:06 +00:00
|
|
|
return false;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2015-11-25 04:15:29 +00:00
|
|
|
|
|
|
|
// Do this early to validate `level`.
|
|
|
|
webgl::ImageInfo* imageInfo;
|
|
|
|
if (!ValidateTexImage(mContext, this, target, rawLevel, &imageInfo))
|
|
|
|
return false;
|
2016-12-15 03:03:25 +00:00
|
|
|
const uint32_t level(rawLevel);
|
2015-11-25 04:15:29 +00:00
|
|
|
|
2015-12-03 23:38:06 +00:00
|
|
|
if (mTarget == LOCAL_GL_TEXTURE_CUBE_MAP && width != height) {
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorInvalidValue("Cube map images must be square.");
|
2015-11-25 04:15:29 +00:00
|
|
|
return false;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
/* GLES 3.0.4, p133-134:
|
|
|
|
* GL_MAX_TEXTURE_SIZE is *not* the max allowed texture size. Rather, it is
|
|
|
|
* the max (width/height) size guaranteed not to generate an INVALID_VALUE for
|
|
|
|
* too-large dimensions. Sizes larger than GL_MAX_TEXTURE_SIZE *may or may
|
|
|
|
* not* result in an INVALID_VALUE, or possibly GL_OOM.
|
2018-11-30 10:46:48 +00:00
|
|
|
*
|
2015-11-25 04:15:29 +00:00
|
|
|
* However, we have needed to set our maximums lower in the past to prevent
|
2017-07-27 07:48:58 +00:00
|
|
|
* resource corruption. Therefore we have mGLMaxTextureSize, which is neither
|
2015-11-25 04:15:29 +00:00
|
|
|
* necessarily lower nor higher than MAX_TEXTURE_SIZE.
|
2018-11-30 10:46:48 +00:00
|
|
|
*
|
2017-07-27 07:48:58 +00:00
|
|
|
* Note that mGLMaxTextureSize must be >= than the advertized
|
|
|
|
* MAX_TEXTURE_SIZE. For simplicity, we advertize MAX_TEXTURE_SIZE as
|
|
|
|
* mGLMaxTextureSize.
|
2018-11-30 10:46:48 +00:00
|
|
|
*/
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
uint32_t maxWidthHeight = 0;
|
|
|
|
uint32_t maxDepth = 0;
|
2018-04-02 19:31:00 +00:00
|
|
|
uint32_t maxLevel = 0;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
MOZ_ASSERT(level <= 31);
|
|
|
|
switch (target.get()) {
|
|
|
|
case LOCAL_GL_TEXTURE_2D:
|
2017-07-27 07:48:58 +00:00
|
|
|
maxWidthHeight = mContext->mGLMaxTextureSize >> level;
|
2015-11-25 04:15:29 +00:00
|
|
|
maxDepth = 1;
|
2017-07-27 07:48:58 +00:00
|
|
|
maxLevel = CeilingLog2(mContext->mGLMaxTextureSize);
|
2015-11-25 04:15:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_TEXTURE_3D:
|
2017-07-27 07:48:58 +00:00
|
|
|
maxWidthHeight = mContext->mGLMax3DTextureSize >> level;
|
2015-11-25 04:15:29 +00:00
|
|
|
maxDepth = maxWidthHeight;
|
2017-07-27 07:48:58 +00:00
|
|
|
maxLevel = CeilingLog2(mContext->mGLMax3DTextureSize);
|
2015-11-25 04:15:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_TEXTURE_2D_ARRAY:
|
2017-07-27 07:48:58 +00:00
|
|
|
maxWidthHeight = mContext->mGLMaxTextureSize >> level;
|
2015-11-25 04:15:29 +00:00
|
|
|
// "The maximum number of layers for two-dimensional array textures
|
2018-11-27 10:08:58 +00:00
|
|
|
// (depth) must be at least MAX_ARRAY_TEXTURE_LAYERS for all levels."
|
2017-07-27 07:48:58 +00:00
|
|
|
maxDepth = mContext->mGLMaxArrayTextureLayers;
|
|
|
|
maxLevel = CeilingLog2(mContext->mGLMaxTextureSize);
|
2018-11-30 10:46:48 +00:00
|
|
|
break;
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
default: // cube maps
|
|
|
|
MOZ_ASSERT(IsCubeMap());
|
2017-07-27 07:48:58 +00:00
|
|
|
maxWidthHeight = mContext->mGLMaxCubeMapTextureSize >> level;
|
2015-11-25 04:15:29 +00:00
|
|
|
maxDepth = 1;
|
2017-07-27 07:48:58 +00:00
|
|
|
maxLevel = CeilingLog2(mContext->mGLMaxCubeMapTextureSize);
|
2015-11-25 04:15:29 +00:00
|
|
|
break;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
|
|
|
|
2016-12-15 03:03:25 +00:00
|
|
|
if (level > maxLevel) {
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorInvalidValue("Requested level is not supported for target.");
|
2016-12-15 03:03:25 +00:00
|
|
|
return false;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2015-11-25 04:15:29 +00:00
|
|
|
|
2017-07-27 07:48:58 +00:00
|
|
|
if (width > maxWidthHeight || height > maxWidthHeight || depth > maxDepth) {
|
|
|
|
mContext->ErrorInvalidValue("Requested size at this level is unsupported.");
|
|
|
|
return false;
|
2015-11-25 04:15:29 +00:00
|
|
|
}
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2016-12-15 03:03:25 +00:00
|
|
|
{
|
2018-07-27 04:46:33 +00:00
|
|
|
/* GL ES Version 2.0.25 - 3.7.1 Texture Image Specification
|
|
|
|
* "If level is greater than zero, and either width or
|
|
|
|
* height is not a power-of-two, the error INVALID_VALUE is
|
|
|
|
* generated."
|
2018-11-30 10:46:48 +00:00
|
|
|
*
|
2018-07-27 04:46:33 +00:00
|
|
|
* This restriction does not apply to GL ES Version 3.0+.
|
2018-11-30 10:46:48 +00:00
|
|
|
*/
|
2018-07-27 04:46:33 +00:00
|
|
|
bool requirePOT = (!mContext->IsWebGL2() && level != 0);
|
2016-12-15 03:03:25 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
if (requirePOT) {
|
2016-06-22 17:28:11 +00:00
|
|
|
if (!IsPowerOfTwo(width) || !IsPowerOfTwo(height)) {
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorInvalidValue(
|
|
|
|
"For level > 0, width and height must be"
|
|
|
|
" powers of two.");
|
2015-11-25 04:15:29 +00:00
|
|
|
return false;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2015-08-03 21:34:46 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
*out_imageInfo = imageInfo;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For *TexSubImage*
|
2018-07-27 04:46:33 +00:00
|
|
|
bool WebGLTexture::ValidateTexImageSelection(
|
2015-11-25 04:15:29 +00:00
|
|
|
TexImageTarget target, GLint level, GLint xOffset, GLint yOffset,
|
2016-06-22 17:28:11 +00:00
|
|
|
GLint zOffset, uint32_t width, uint32_t height, uint32_t depth,
|
2018-10-17 04:18:15 +00:00
|
|
|
webgl::ImageInfo** const out_imageInfo) {
|
2015-11-25 04:15:29 +00:00
|
|
|
// The conformance test wants bad arg checks before imageInfo checks.
|
2016-06-22 17:28:11 +00:00
|
|
|
if (xOffset < 0 || yOffset < 0 || zOffset < 0) {
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorInvalidValue("Offsets must be >=0.");
|
2015-11-25 04:15:29 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
webgl::ImageInfo* imageInfo;
|
|
|
|
if (!ValidateTexImage(mContext, this, target, level, &imageInfo))
|
|
|
|
return false;
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
if (!imageInfo->IsDefined()) {
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorInvalidOperation(
|
|
|
|
"The specified TexImage has not yet been"
|
|
|
|
" specified.");
|
2015-11-25 04:15:29 +00:00
|
|
|
return false;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
const auto totalX = CheckedUint32(xOffset) + width;
|
|
|
|
const auto totalY = CheckedUint32(yOffset) + height;
|
|
|
|
const auto totalZ = CheckedUint32(zOffset) + depth;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
if (!totalX.isValid() || totalX.value() > imageInfo->mWidth ||
|
|
|
|
!totalY.isValid() || totalY.value() > imageInfo->mHeight ||
|
|
|
|
!totalZ.isValid() || totalZ.value() > imageInfo->mDepth) {
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorInvalidValue(
|
|
|
|
"Offset+size must be <= the size of the existing"
|
|
|
|
" specified image.");
|
2015-11-25 04:15:29 +00:00
|
|
|
return false;
|
2015-11-24 03:27:13 +00:00
|
|
|
}
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
*out_imageInfo = imageInfo;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
static bool ValidateCompressedTexUnpack(WebGLContext* webgl, GLsizei width,
|
2015-11-25 04:15:29 +00:00
|
|
|
GLsizei height, GLsizei depth,
|
|
|
|
const webgl::FormatInfo* format,
|
|
|
|
size_t dataSize) {
|
|
|
|
auto compression = format->compression;
|
|
|
|
|
|
|
|
auto bytesPerBlock = compression->bytesPerBlock;
|
|
|
|
auto blockWidth = compression->blockWidth;
|
|
|
|
auto blockHeight = compression->blockHeight;
|
|
|
|
|
|
|
|
auto widthInBlocks = CheckedUint32(width) / blockWidth;
|
|
|
|
auto heightInBlocks = CheckedUint32(height) / blockHeight;
|
|
|
|
if (width % blockWidth) widthInBlocks += 1;
|
|
|
|
if (height % blockHeight) heightInBlocks += 1;
|
|
|
|
|
|
|
|
const CheckedUint32 blocksPerImage = widthInBlocks * heightInBlocks;
|
|
|
|
const CheckedUint32 bytesPerImage = bytesPerBlock * blocksPerImage;
|
|
|
|
const CheckedUint32 bytesNeeded = bytesPerImage * depth;
|
|
|
|
|
|
|
|
if (!bytesNeeded.isValid()) {
|
2018-07-27 04:46:33 +00:00
|
|
|
webgl->ErrorOutOfMemory("Overflow while computing the needed buffer size.");
|
2015-11-25 04:15:29 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dataSize != bytesNeeded.value()) {
|
2018-07-27 04:46:33 +00:00
|
|
|
webgl->ErrorInvalidValue(
|
|
|
|
"Provided buffer's size must match expected size."
|
2017-07-26 20:03:57 +00:00
|
|
|
" (needs %u, has %zu)",
|
2018-07-27 04:46:33 +00:00
|
|
|
bytesNeeded.value(), dataSize);
|
2015-11-25 04:15:29 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool DoChannelsMatchForCopyTexImage(const webgl::FormatInfo* srcFormat,
|
|
|
|
const webgl::FormatInfo* dstFormat) {
|
|
|
|
// GLES 3.0.4 p140 Table 3.16 "Valid CopyTexImage source
|
|
|
|
// framebuffer/destination texture base internal format combinations."
|
|
|
|
|
|
|
|
switch (srcFormat->unsizedFormat) {
|
|
|
|
case webgl::UnsizedFormat::RGBA:
|
|
|
|
switch (dstFormat->unsizedFormat) {
|
|
|
|
case webgl::UnsizedFormat::A:
|
|
|
|
case webgl::UnsizedFormat::L:
|
|
|
|
case webgl::UnsizedFormat::LA:
|
|
|
|
case webgl::UnsizedFormat::R:
|
|
|
|
case webgl::UnsizedFormat::RG:
|
|
|
|
case webgl::UnsizedFormat::RGB:
|
|
|
|
case webgl::UnsizedFormat::RGBA:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
case webgl::UnsizedFormat::RGB:
|
|
|
|
switch (dstFormat->unsizedFormat) {
|
|
|
|
case webgl::UnsizedFormat::L:
|
|
|
|
case webgl::UnsizedFormat::R:
|
|
|
|
case webgl::UnsizedFormat::RG:
|
|
|
|
case webgl::UnsizedFormat::RGB:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
case webgl::UnsizedFormat::RG:
|
|
|
|
switch (dstFormat->unsizedFormat) {
|
|
|
|
case webgl::UnsizedFormat::L:
|
|
|
|
case webgl::UnsizedFormat::R:
|
|
|
|
case webgl::UnsizedFormat::RG:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
case webgl::UnsizedFormat::R:
|
|
|
|
switch (dstFormat->unsizedFormat) {
|
|
|
|
case webgl::UnsizedFormat::L:
|
|
|
|
case webgl::UnsizedFormat::R:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
static bool EnsureImageDataInitializedForUpload(
|
2015-11-25 04:15:29 +00:00
|
|
|
WebGLTexture* tex, TexImageTarget target, GLint level, GLint xOffset,
|
|
|
|
GLint yOffset, GLint zOffset, uint32_t width, uint32_t height,
|
2018-10-17 04:18:15 +00:00
|
|
|
uint32_t depth, webgl::ImageInfo* imageInfo) {
|
|
|
|
if (!imageInfo->mHasData) {
|
2015-11-25 04:15:29 +00:00
|
|
|
const bool isFullUpload =
|
|
|
|
(!xOffset && !yOffset && !zOffset && width == imageInfo->mWidth &&
|
|
|
|
height == imageInfo->mHeight && depth == imageInfo->mDepth);
|
2018-10-17 04:18:15 +00:00
|
|
|
if (!isFullUpload) {
|
2015-11-25 04:15:29 +00:00
|
|
|
WebGLContext* webgl = tex->mContext;
|
2018-07-27 04:46:33 +00:00
|
|
|
webgl->GenerateWarning(
|
|
|
|
"Texture has not been initialized prior to a"
|
2015-11-25 04:15:29 +00:00
|
|
|
" partial upload, forcing the browser to clear it."
|
2018-07-27 04:46:33 +00:00
|
|
|
" This may be slow.");
|
2018-10-17 04:18:15 +00:00
|
|
|
if (!tex->EnsureImageDataInitialized(target, level)) {
|
2015-11-25 04:15:29 +00:00
|
|
|
MOZ_ASSERT(false, "Unexpected failure to init image data.");
|
|
|
|
return false;
|
2015-11-24 05:55:59 +00:00
|
|
|
}
|
2015-11-24 03:27:13 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2015-11-24 03:27:13 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
return true;
|
2015-11-24 03:27:13 +00:00
|
|
|
}
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Actual calls
|
|
|
|
|
|
|
|
static inline GLenum DoTexStorage(gl::GLContext* gl, TexTarget target,
|
|
|
|
GLsizei levels, GLenum sizedFormat,
|
|
|
|
GLsizei width, GLsizei height,
|
|
|
|
GLsizei depth) {
|
|
|
|
gl::GLContext::LocalErrorScope errorScope(*gl);
|
|
|
|
|
|
|
|
switch (target.get()) {
|
|
|
|
case LOCAL_GL_TEXTURE_2D:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP:
|
|
|
|
MOZ_ASSERT(depth == 1);
|
|
|
|
gl->fTexStorage2D(target.get(), levels, sizedFormat, width, height);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_TEXTURE_3D:
|
|
|
|
case LOCAL_GL_TEXTURE_2D_ARRAY:
|
|
|
|
gl->fTexStorage3D(target.get(), levels, sizedFormat, width, height,
|
|
|
|
depth);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-06-06 15:17:23 +00:00
|
|
|
MOZ_CRASH("GFX: bad target");
|
2015-11-24 03:27:13 +00:00
|
|
|
}
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
return errorScope.GetError();
|
|
|
|
}
|
2015-11-24 03:27:13 +00:00
|
|
|
|
2016-07-12 05:51:19 +00:00
|
|
|
bool IsTarget3D(TexImageTarget target) {
|
2015-11-25 04:15:29 +00:00
|
|
|
switch (target.get()) {
|
|
|
|
case LOCAL_GL_TEXTURE_2D:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
|
|
|
|
return false;
|
2015-11-24 03:27:13 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
case LOCAL_GL_TEXTURE_3D:
|
|
|
|
case LOCAL_GL_TEXTURE_2D_ARRAY:
|
|
|
|
return true;
|
2015-11-24 03:27:13 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
default:
|
2016-06-06 15:17:23 +00:00
|
|
|
MOZ_CRASH("GFX: bad target");
|
2015-11-24 05:55:59 +00:00
|
|
|
}
|
2015-11-25 04:15:29 +00:00
|
|
|
}
|
2015-11-24 03:27:13 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
GLenum DoTexImage(gl::GLContext* gl, TexImageTarget target, GLint level,
|
|
|
|
const webgl::DriverUnpackInfo* dui, GLsizei width,
|
|
|
|
GLsizei height, GLsizei depth, const void* data) {
|
|
|
|
const GLint border = 0;
|
2015-11-24 03:27:13 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
gl::GLContext::LocalErrorScope errorScope(*gl);
|
2015-11-24 03:27:13 +00:00
|
|
|
|
2016-07-12 05:51:19 +00:00
|
|
|
if (IsTarget3D(target)) {
|
2015-11-25 04:15:29 +00:00
|
|
|
gl->fTexImage3D(target.get(), level, dui->internalFormat, width, height,
|
|
|
|
depth, border, dui->unpackFormat, dui->unpackType, data);
|
2015-11-24 05:55:59 +00:00
|
|
|
} else {
|
2015-11-25 04:15:29 +00:00
|
|
|
MOZ_ASSERT(depth == 1);
|
|
|
|
gl->fTexImage2D(target.get(), level, dui->internalFormat, width, height,
|
|
|
|
border, dui->unpackFormat, dui->unpackType, data);
|
|
|
|
}
|
2015-11-24 03:27:13 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
return errorScope.GetError();
|
|
|
|
}
|
2015-11-24 03:27:13 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
GLenum DoTexSubImage(gl::GLContext* gl, TexImageTarget target, GLint level,
|
|
|
|
GLint xOffset, GLint yOffset, GLint zOffset, GLsizei width,
|
|
|
|
GLsizei height, GLsizei depth,
|
2016-06-22 17:28:11 +00:00
|
|
|
const webgl::PackingInfo& pi, const void* data) {
|
2015-11-25 04:15:29 +00:00
|
|
|
gl::GLContext::LocalErrorScope errorScope(*gl);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-07-12 05:51:19 +00:00
|
|
|
if (IsTarget3D(target)) {
|
2015-11-25 04:15:29 +00:00
|
|
|
gl->fTexSubImage3D(target.get(), level, xOffset, yOffset, zOffset, width,
|
|
|
|
height, depth, pi.format, pi.type, data);
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(zOffset == 0);
|
|
|
|
MOZ_ASSERT(depth == 1);
|
|
|
|
gl->fTexSubImage2D(target.get(), level, xOffset, yOffset, width, height,
|
|
|
|
pi.format, pi.type, data);
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
return errorScope.GetError();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline GLenum DoCompressedTexImage(gl::GLContext* gl,
|
|
|
|
TexImageTarget target, GLint level,
|
|
|
|
GLenum internalFormat, GLsizei width,
|
|
|
|
GLsizei height, GLsizei depth,
|
|
|
|
GLsizei dataSize, const void* data) {
|
2016-06-22 17:28:11 +00:00
|
|
|
const GLint border = 0;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
gl::GLContext::LocalErrorScope errorScope(*gl);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-07-12 05:51:19 +00:00
|
|
|
if (IsTarget3D(target)) {
|
2015-11-25 04:15:29 +00:00
|
|
|
gl->fCompressedTexImage3D(target.get(), level, internalFormat, width,
|
|
|
|
height, depth, border, dataSize, data);
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(depth == 1);
|
|
|
|
gl->fCompressedTexImage2D(target.get(), level, internalFormat, width,
|
|
|
|
height, border, dataSize, data);
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
return errorScope.GetError();
|
|
|
|
}
|
|
|
|
|
|
|
|
GLenum DoCompressedTexSubImage(gl::GLContext* gl, TexImageTarget target,
|
|
|
|
GLint level, GLint xOffset, GLint yOffset,
|
|
|
|
GLint zOffset, GLsizei width, GLsizei height,
|
|
|
|
GLsizei depth, GLenum sizedUnpackFormat,
|
|
|
|
GLsizei dataSize, const void* data) {
|
|
|
|
gl::GLContext::LocalErrorScope errorScope(*gl);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-07-12 05:51:19 +00:00
|
|
|
if (IsTarget3D(target)) {
|
2015-11-25 04:15:29 +00:00
|
|
|
gl->fCompressedTexSubImage3D(target.get(), level, xOffset, yOffset, zOffset,
|
|
|
|
width, height, depth, sizedUnpackFormat,
|
|
|
|
dataSize, data);
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(zOffset == 0);
|
|
|
|
MOZ_ASSERT(depth == 1);
|
|
|
|
gl->fCompressedTexSubImage2D(target.get(), level, xOffset, yOffset, width,
|
|
|
|
height, sizedUnpackFormat, dataSize, data);
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
return errorScope.GetError();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline GLenum DoCopyTexSubImage(gl::GLContext* gl, TexImageTarget target,
|
|
|
|
GLint level, GLint xOffset,
|
|
|
|
GLint yOffset, GLint zOffset, GLint x,
|
2016-06-22 17:28:11 +00:00
|
|
|
GLint y, GLsizei width, GLsizei height) {
|
2015-11-25 04:15:29 +00:00
|
|
|
gl::GLContext::LocalErrorScope errorScope(*gl);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-07-12 05:51:19 +00:00
|
|
|
if (IsTarget3D(target)) {
|
2018-11-27 10:08:58 +00:00
|
|
|
gl->fCopyTexSubImage3D(target.get(), level, xOffset, yOffset, zOffset, x, y,
|
2018-07-27 04:46:33 +00:00
|
|
|
width, height);
|
2018-11-30 10:46:48 +00:00
|
|
|
} else {
|
2015-11-25 04:15:29 +00:00
|
|
|
MOZ_ASSERT(zOffset == 0);
|
2018-11-27 10:08:58 +00:00
|
|
|
gl->fCopyTexSubImage2D(target.get(), level, xOffset, yOffset, x, y, width,
|
2018-11-30 10:46:48 +00:00
|
|
|
height);
|
|
|
|
}
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
return errorScope.GetError();
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Actual (mostly generic) function implementations
|
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
static bool ValidateCompressedTexImageRestrictions(
|
2015-11-25 04:15:29 +00:00
|
|
|
WebGLContext* webgl, TexImageTarget target, uint32_t level,
|
|
|
|
const webgl::FormatInfo* format, uint32_t width, uint32_t height,
|
|
|
|
uint32_t depth) {
|
|
|
|
const auto fnIsDimValid_S3TC = [level](uint32_t size, uint32_t blockSize) {
|
|
|
|
if (size % blockSize == 0) return true;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
if (level == 0) return false;
|
|
|
|
|
|
|
|
return (size == 0 || size == 1 || size == 2);
|
|
|
|
};
|
|
|
|
|
|
|
|
switch (format->compression->family) {
|
2016-11-23 02:59:35 +00:00
|
|
|
case webgl::CompressionFamily::ASTC:
|
|
|
|
if (target == LOCAL_GL_TEXTURE_3D &&
|
|
|
|
!webgl->gl->IsExtensionSupported(
|
|
|
|
gl::GLContext::KHR_texture_compression_astc_hdr)) {
|
2018-07-27 04:46:33 +00:00
|
|
|
webgl->ErrorInvalidOperation("TEXTURE_3D requires ASTC's hdr profile.");
|
2016-11-23 02:59:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
case webgl::CompressionFamily::PVRTC:
|
|
|
|
if (!IsPowerOfTwo(width) || !IsPowerOfTwo(height)) {
|
2018-07-27 04:46:33 +00:00
|
|
|
webgl->ErrorInvalidValue("%s requires power-of-two width and height.",
|
|
|
|
format->name);
|
2015-11-25 04:15:29 +00:00
|
|
|
return false;
|
2015-08-03 21:34:46 +00:00
|
|
|
}
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case webgl::CompressionFamily::S3TC:
|
|
|
|
if (!fnIsDimValid_S3TC(width, format->compression->blockWidth) ||
|
|
|
|
!fnIsDimValid_S3TC(height, format->compression->blockHeight)) {
|
2018-07-27 04:46:33 +00:00
|
|
|
webgl->ErrorInvalidOperation(
|
|
|
|
"%s requires that width and height are"
|
2015-11-25 04:15:29 +00:00
|
|
|
" block-aligned, or, if level>0, equal to 0, 1,"
|
|
|
|
" or 2.",
|
2018-07-27 04:46:33 +00:00
|
|
|
format->name);
|
2015-11-25 04:15:29 +00:00
|
|
|
return false;
|
2015-08-03 21:34:46 +00:00
|
|
|
}
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
break;
|
2015-11-24 03:27:13 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
// Default: There are no restrictions on CompressedTexImage.
|
2018-10-06 01:06:16 +00:00
|
|
|
default: // ETC1, ES3
|
2015-11-25 04:15:29 +00:00
|
|
|
break;
|
2015-11-24 05:55:59 +00:00
|
|
|
}
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
static bool ValidateTargetForFormat(WebGLContext* webgl, TexImageTarget target,
|
2015-11-25 04:15:29 +00:00
|
|
|
const webgl::FormatInfo* format) {
|
|
|
|
// GLES 3.0.4 p127:
|
|
|
|
// "Textures with a base internal format of DEPTH_COMPONENT or DEPTH_STENCIL
|
2018-11-27 10:08:58 +00:00
|
|
|
// are supported by texture image specification commands only if `target` is
|
|
|
|
// TEXTURE_2D, TEXTURE_2D_ARRAY, or TEXTURE_CUBE_MAP. Using these formats in
|
|
|
|
// conjunction with any other `target` will result in an INVALID_OPERATION
|
|
|
|
// error."
|
2018-09-27 23:37:40 +00:00
|
|
|
const bool ok = [&]() {
|
|
|
|
if (bool(format->d) & (target == LOCAL_GL_TEXTURE_3D)) return false;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-09-27 23:37:40 +00:00
|
|
|
if (format->compression) {
|
|
|
|
switch (format->compression->family) {
|
|
|
|
case webgl::CompressionFamily::ES3:
|
2015-11-25 04:15:29 +00:00
|
|
|
case webgl::CompressionFamily::S3TC:
|
2018-09-27 23:37:40 +00:00
|
|
|
if (target == LOCAL_GL_TEXTURE_3D) return false;
|
2018-11-30 10:46:48 +00:00
|
|
|
break;
|
|
|
|
|
2018-09-27 23:37:40 +00:00
|
|
|
case webgl::CompressionFamily::ETC1:
|
2015-11-25 04:15:29 +00:00
|
|
|
case webgl::CompressionFamily::PVRTC:
|
2018-09-27 23:37:40 +00:00
|
|
|
case webgl::CompressionFamily::RGTC:
|
|
|
|
if (target == LOCAL_GL_TEXTURE_3D ||
|
|
|
|
target == LOCAL_GL_TEXTURE_2D_ARRAY) {
|
2015-11-25 04:15:29 +00:00
|
|
|
return false;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2018-09-27 23:37:40 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2015-11-25 04:15:29 +00:00
|
|
|
}
|
2015-11-24 05:55:59 +00:00
|
|
|
}
|
2015-11-25 04:15:29 +00:00
|
|
|
return true;
|
2018-07-27 04:46:33 +00:00
|
|
|
}();
|
2015-11-25 04:15:29 +00:00
|
|
|
if (!ok) {
|
2018-07-27 04:46:33 +00:00
|
|
|
webgl->ErrorInvalidOperation("Format %s cannot be used with target %s.",
|
|
|
|
format->name, GetEnumName(target.get()));
|
2018-04-02 19:31:00 +00:00
|
|
|
return false;
|
2015-11-25 04:15:29 +00:00
|
|
|
}
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2017-06-22 18:32:00 +00:00
|
|
|
return true;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2017-06-22 18:32:00 +00:00
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
void WebGLTexture::TexStorage(TexTarget target, GLsizei levels,
|
2015-11-25 04:15:29 +00:00
|
|
|
GLenum sizedFormat, GLsizei width, GLsizei height,
|
|
|
|
GLsizei depth) {
|
|
|
|
// Check levels
|
|
|
|
if (levels < 1) {
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorInvalidValue("`levels` must be >= 1.");
|
2018-11-30 10:46:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
if (!width || !height || !depth) {
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorInvalidValue("Dimensions must be non-zero.");
|
2018-11-30 10:46:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
const TexImageTarget testTarget =
|
|
|
|
IsCubeMap() ? LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X : target.get();
|
2018-10-17 04:18:15 +00:00
|
|
|
webgl::ImageInfo* baseImageInfo;
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!ValidateTexImageSpecification(testTarget, 0, width, height, depth,
|
2018-04-02 19:31:00 +00:00
|
|
|
&baseImageInfo)) {
|
2018-11-30 10:46:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-03-27 01:39:46 +00:00
|
|
|
MOZ_ALWAYS_TRUE(baseImageInfo);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
auto dstUsage = mContext->mFormatUsage->GetSizedTexUsage(sizedFormat);
|
|
|
|
if (!dstUsage) {
|
2018-10-17 19:13:14 +00:00
|
|
|
mContext->ErrorInvalidEnumInfo("internalformat", sizedFormat);
|
2018-11-30 10:46:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-11-25 04:15:29 +00:00
|
|
|
auto dstFormat = dstUsage->format;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!ValidateTargetForFormat(mContext, testTarget, dstFormat)) return;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
if (dstFormat->compression) {
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!ValidateCompressedTexImageRestrictions(
|
2015-11-25 04:15:29 +00:00
|
|
|
mContext, testTarget, 0, dstFormat, width, height, depth)) {
|
2018-11-30 10:46:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-04-02 19:31:00 +00:00
|
|
|
const bool levelsOk = [&]() {
|
|
|
|
// Right-shift is only defined for bits-1, which is too large anyways.
|
|
|
|
const auto lastLevel = uint32_t(levels - 1);
|
|
|
|
if (lastLevel > 31) return false;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-04-02 19:31:00 +00:00
|
|
|
const auto lastLevelWidth = uint32_t(width) >> lastLevel;
|
|
|
|
const auto lastLevelHeight = uint32_t(height) >> lastLevel;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-04-02 19:31:00 +00:00
|
|
|
// If these are all zero, then some earlier level was the final 1x1(x1)
|
|
|
|
// level.
|
2018-05-16 00:00:31 +00:00
|
|
|
bool ok = lastLevelWidth || lastLevelHeight;
|
2018-04-02 19:31:00 +00:00
|
|
|
if (target == LOCAL_GL_TEXTURE_3D) {
|
|
|
|
const auto lastLevelDepth = uint32_t(depth) >> lastLevel;
|
2018-05-16 00:00:31 +00:00
|
|
|
ok |= bool(lastLevelDepth);
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2018-04-02 19:31:00 +00:00
|
|
|
return ok;
|
2018-11-30 10:46:48 +00:00
|
|
|
}();
|
2018-04-02 19:31:00 +00:00
|
|
|
if (!levelsOk) {
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorInvalidOperation(
|
|
|
|
"Too many levels requested for the given"
|
2015-11-25 04:15:29 +00:00
|
|
|
" dimensions. (levels: %u, width: %u, height: %u,"
|
|
|
|
" depth: %u)",
|
2018-07-27 04:46:33 +00:00
|
|
|
levels, width, height, depth);
|
2018-11-30 10:46:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Do the thing!
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
GLenum error = DoTexStorage(mContext->gl, target.get(), levels, sizedFormat,
|
2018-07-27 04:46:33 +00:00
|
|
|
width, height, depth);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2017-06-22 18:32:00 +00:00
|
|
|
mContext->OnDataAllocCall();
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
if (error == LOCAL_GL_OUT_OF_MEMORY) {
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorOutOfMemory("Ran out of memory during texture allocation.");
|
2015-08-03 21:34:46 +00:00
|
|
|
return;
|
2015-11-25 04:15:29 +00:00
|
|
|
}
|
|
|
|
if (error) {
|
2016-06-06 15:17:23 +00:00
|
|
|
MOZ_RELEASE_ASSERT(false, "GFX: We should have caught all other errors.");
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorInvalidOperation(
|
|
|
|
"Unexpected error during texture allocation.");
|
2015-11-25 04:15:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////
|
|
|
|
// Update our specification data.
|
|
|
|
|
|
|
|
const bool isDataInitialized = false;
|
2018-10-17 04:18:15 +00:00
|
|
|
const webgl::ImageInfo newInfo{dstUsage, uint32_t(width), uint32_t(height),
|
|
|
|
uint32_t(depth), isDataInitialized};
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2018-10-17 04:18:15 +00:00
|
|
|
{
|
|
|
|
const auto base_level = mBaseMipmapLevel;
|
|
|
|
mBaseMipmapLevel = 0;
|
|
|
|
|
|
|
|
ImageInfoAtFace(0, 0) = newInfo;
|
|
|
|
PopulateMipChain(levels - 1);
|
|
|
|
|
|
|
|
mBaseMipmapLevel = base_level;
|
|
|
|
}
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
mImmutable = true;
|
2016-08-02 18:20:00 +00:00
|
|
|
mImmutableLevelCount = levels;
|
2018-10-17 04:18:15 +00:00
|
|
|
ClampLevelBaseAndMax();
|
2015-08-03 21:34:46 +00:00
|
|
|
}
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////////
|
|
|
|
// Tex(Sub)Image
|
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
void WebGLTexture::TexImage(TexImageTarget target, GLint level,
|
2016-06-22 17:28:11 +00:00
|
|
|
GLenum internalFormat, const webgl::PackingInfo& pi,
|
|
|
|
const webgl::TexUnpackBlob* blob) {
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Get dest info
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-10-17 04:18:15 +00:00
|
|
|
webgl::ImageInfo* imageInfo;
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!ValidateTexImageSpecification(target, level, blob->mWidth, blob->mHeight,
|
2016-06-22 17:28:11 +00:00
|
|
|
blob->mDepth, &imageInfo)) {
|
2015-11-25 04:15:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(imageInfo);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
const auto& fua = mContext->mFormatUsage;
|
2016-06-22 17:28:11 +00:00
|
|
|
if (!fua->IsInternalFormatEnumValid(internalFormat)) {
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorInvalidValue("Invalid internalformat: 0x%04x",
|
|
|
|
internalFormat);
|
2016-06-22 17:28:11 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
auto dstUsage = fua->GetSizedTexUsage(internalFormat);
|
|
|
|
if (!dstUsage) {
|
2016-06-22 17:28:11 +00:00
|
|
|
if (internalFormat != pi.format) {
|
2016-01-20 15:39:00 +00:00
|
|
|
/* GL ES Version 3.0.4 - 3.8.3 Texture Image Specification
|
|
|
|
* "Specifying a combination of values for format, type, and
|
|
|
|
* internalformat that is not listed as a valid combination
|
|
|
|
* in tables 3.2 or 3.3 generates the error INVALID_OPERATION."
|
|
|
|
*/
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorInvalidOperation(
|
|
|
|
"Unsized internalFormat must match"
|
|
|
|
" unpack format.");
|
2015-11-25 04:15:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-06-22 17:28:11 +00:00
|
|
|
dstUsage = fua->GetUnsizedTexUsage(pi);
|
2015-11-25 04:15:29 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
if (!dstUsage) {
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorInvalidOperation(
|
|
|
|
"Invalid internalformat/format/type:"
|
2015-11-25 04:15:29 +00:00
|
|
|
" 0x%04x/0x%04x/0x%04x",
|
2018-07-27 04:46:33 +00:00
|
|
|
internalFormat, pi.format, pi.type);
|
2015-11-25 04:15:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
const webgl::DriverUnpackInfo* driverUnpackInfo;
|
2016-06-22 17:28:11 +00:00
|
|
|
if (!dstUsage->IsUnpackValid(pi, &driverUnpackInfo)) {
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorInvalidOperation(
|
|
|
|
"Mismatched internalFormat and format/type:"
|
2015-11-25 04:15:29 +00:00
|
|
|
" 0x%04x and 0x%04x/0x%04x",
|
2018-07-27 04:46:33 +00:00
|
|
|
internalFormat, pi.format, pi.type);
|
2015-11-25 04:15:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Check that source and dest info are compatible
|
|
|
|
auto dstFormat = dstUsage->format;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!ValidateTargetForFormat(mContext, target, dstFormat)) return;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-07-08 21:57:18 +00:00
|
|
|
if (!mContext->IsWebGL2() && dstFormat->d) {
|
2015-11-25 04:15:29 +00:00
|
|
|
if (target != LOCAL_GL_TEXTURE_2D || blob->HasData() || level != 0) {
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorInvalidOperation(
|
|
|
|
"With format %s, this function may only"
|
2015-11-25 04:15:29 +00:00
|
|
|
" be called with target=TEXTURE_2D,"
|
|
|
|
" data=null, and level=0.",
|
2018-07-27 04:46:33 +00:00
|
|
|
dstFormat->name);
|
2015-11-25 04:15:29 +00:00
|
|
|
return;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2015-11-25 04:15:29 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Do the thing!
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
// It's tempting to do allocation first, and TexSubImage second, but this is
|
|
|
|
// generally slower.
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-10-17 04:18:15 +00:00
|
|
|
const webgl::ImageInfo newImageInfo{dstUsage, blob->mWidth, blob->mHeight,
|
|
|
|
blob->mDepth, blob->HasData()};
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
const bool isSubImage = false;
|
|
|
|
const bool needsRespec = (imageInfo->mWidth != newImageInfo.mWidth ||
|
|
|
|
imageInfo->mHeight != newImageInfo.mHeight ||
|
|
|
|
imageInfo->mDepth != newImageInfo.mDepth ||
|
|
|
|
imageInfo->mFormat != newImageInfo.mFormat);
|
|
|
|
const GLint xOffset = 0;
|
|
|
|
const GLint yOffset = 0;
|
|
|
|
const GLint zOffset = 0;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
GLenum glError;
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!blob->TexOrSubImage(isSubImage, needsRespec, this, target, level,
|
2017-06-15 19:29:00 +00:00
|
|
|
driverUnpackInfo, xOffset, yOffset, zOffset, pi,
|
|
|
|
&glError)) {
|
2016-11-16 01:52:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2017-06-22 18:32:00 +00:00
|
|
|
mContext->OnDataAllocCall();
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
if (glError == LOCAL_GL_OUT_OF_MEMORY) {
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorOutOfMemory("Driver ran out of memory during upload.");
|
2015-11-25 04:15:29 +00:00
|
|
|
return;
|
2015-08-03 21:34:46 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
if (glError) {
|
2018-07-27 04:46:33 +00:00
|
|
|
const auto enumStr = EnumString(glError);
|
|
|
|
const nsPrintfCString dui(
|
|
|
|
"Unexpected error %s during upload. (dui: %x/%x/%x)", enumStr.c_str(),
|
|
|
|
driverUnpackInfo->internalFormat, driverUnpackInfo->unpackFormat,
|
|
|
|
driverUnpackInfo->unpackType);
|
|
|
|
mContext->ErrorInvalidOperation("%s", dui.BeginReading());
|
|
|
|
gfxCriticalError() << mContext->FuncName() << ": " << dui.BeginReading();
|
2015-11-25 04:15:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Update our specification data.
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-10-17 04:18:15 +00:00
|
|
|
*imageInfo = newImageInfo;
|
|
|
|
InvalidateCaches();
|
2015-11-25 04:15:29 +00:00
|
|
|
}
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
void WebGLTexture::TexSubImage(TexImageTarget target, GLint level,
|
2015-11-25 04:15:29 +00:00
|
|
|
GLint xOffset, GLint yOffset, GLint zOffset,
|
2016-06-22 17:28:11 +00:00
|
|
|
const webgl::PackingInfo& pi,
|
|
|
|
const webgl::TexUnpackBlob* blob) {
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Get dest info
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-10-17 04:18:15 +00:00
|
|
|
webgl::ImageInfo* imageInfo;
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!ValidateTexImageSelection(target, level, xOffset, yOffset, zOffset,
|
2015-11-25 04:15:29 +00:00
|
|
|
blob->mWidth, blob->mHeight, blob->mDepth,
|
|
|
|
&imageInfo)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(imageInfo);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
auto dstUsage = imageInfo->mFormat;
|
|
|
|
auto dstFormat = dstUsage->format;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-07-08 21:57:18 +00:00
|
|
|
if (!mContext->IsWebGL2() && dstFormat->d) {
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorInvalidOperation(
|
|
|
|
"Function may not be called on a texture of"
|
2015-11-25 04:15:29 +00:00
|
|
|
" format %s.",
|
2018-07-27 04:46:33 +00:00
|
|
|
dstFormat->name);
|
2015-11-25 04:15:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Get source info
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
const webgl::DriverUnpackInfo* driverUnpackInfo;
|
2016-06-22 17:28:11 +00:00
|
|
|
if (!dstUsage->IsUnpackValid(pi, &driverUnpackInfo)) {
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorInvalidOperation(
|
|
|
|
"Mismatched internalFormat and format/type:"
|
2015-11-25 04:15:29 +00:00
|
|
|
" %s and 0x%04x/0x%04x",
|
2018-07-27 04:46:33 +00:00
|
|
|
dstFormat->name, pi.format, pi.type);
|
2015-11-25 04:15:29 +00:00
|
|
|
return;
|
2015-08-03 21:34:46 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Do the thing!
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!EnsureImageDataInitializedForUpload(
|
2015-11-25 04:15:29 +00:00
|
|
|
this, target, level, xOffset, yOffset, zOffset, blob->mWidth,
|
2018-10-17 04:18:15 +00:00
|
|
|
blob->mHeight, blob->mDepth, imageInfo)) {
|
2015-11-25 04:15:29 +00:00
|
|
|
return;
|
2015-08-03 21:34:46 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
const bool isSubImage = true;
|
|
|
|
const bool needsRespec = false;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
GLenum glError;
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!blob->TexOrSubImage(isSubImage, needsRespec, this, target, level,
|
2017-06-15 19:29:00 +00:00
|
|
|
driverUnpackInfo, xOffset, yOffset, zOffset, pi,
|
|
|
|
&glError)) {
|
2016-11-16 01:52:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
if (glError == LOCAL_GL_OUT_OF_MEMORY) {
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorOutOfMemory("Driver ran out of memory during upload.");
|
2015-11-25 04:15:29 +00:00
|
|
|
return;
|
2015-08-03 21:34:46 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
if (glError) {
|
2018-07-27 04:46:33 +00:00
|
|
|
const auto enumStr = EnumString(glError);
|
|
|
|
const nsPrintfCString dui(
|
|
|
|
"Unexpected error %s during upload. (dui: %x/%x/%x)", enumStr.c_str(),
|
|
|
|
driverUnpackInfo->internalFormat, driverUnpackInfo->unpackFormat,
|
|
|
|
driverUnpackInfo->unpackType);
|
|
|
|
mContext->ErrorInvalidOperation("%s", dui.BeginReading());
|
|
|
|
gfxCriticalError() << mContext->FuncName() << ": " << dui.BeginReading();
|
2015-11-25 04:15:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Update our specification data?
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-10-17 04:18:15 +00:00
|
|
|
imageInfo->mHasData = true;
|
2015-11-24 05:55:59 +00:00
|
|
|
}
|
2015-11-24 03:27:13 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////////
|
|
|
|
// CompressedTex(Sub)Image
|
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
UniquePtr<webgl::TexUnpackBytes> WebGLContext::FromCompressed(
|
|
|
|
TexImageTarget target, GLsizei rawWidth, GLsizei rawHeight,
|
2017-07-18 18:02:57 +00:00
|
|
|
GLsizei rawDepth, GLint border, const TexImageSource& src,
|
|
|
|
const Maybe<GLsizei>& expectedImageSize) {
|
2016-10-21 01:03:40 +00:00
|
|
|
uint32_t width, height, depth;
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!ValidateExtents(this, rawWidth, rawHeight, rawDepth, border, &width,
|
2016-10-21 01:03:40 +00:00
|
|
|
&height, &depth)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
if (src.mPboOffset) {
|
2018-07-27 04:46:33 +00:00
|
|
|
return FromPboOffset(this, target, width, height, depth, *(src.mPboOffset),
|
2017-07-18 18:02:57 +00:00
|
|
|
expectedImageSize);
|
2016-10-21 01:03:40 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-10-21 01:03:40 +00:00
|
|
|
if (mBoundPixelUnpackBuffer) {
|
2018-07-27 04:46:33 +00:00
|
|
|
ErrorInvalidOperation("PIXEL_UNPACK_BUFFER must be null.");
|
2016-10-21 01:03:40 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
return FromView(this, target, width, height, depth, src.mView,
|
2016-10-28 02:03:20 +00:00
|
|
|
src.mViewElemOffset, src.mViewElemLengthOverride);
|
2016-10-21 01:03:40 +00:00
|
|
|
}
|
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
void WebGLTexture::CompressedTexImage(TexImageTarget target, GLint level,
|
2016-06-22 17:28:11 +00:00
|
|
|
GLenum internalFormat, GLsizei rawWidth,
|
|
|
|
GLsizei rawHeight, GLsizei rawDepth,
|
2017-07-18 18:02:57 +00:00
|
|
|
GLint border, const TexImageSource& src,
|
|
|
|
const Maybe<GLsizei>& expectedImageSize) {
|
2018-07-27 04:46:33 +00:00
|
|
|
const auto blob = mContext->FromCompressed(
|
2017-07-18 18:02:57 +00:00
|
|
|
target, rawWidth, rawHeight, rawDepth, border, src, expectedImageSize);
|
2016-10-21 01:03:40 +00:00
|
|
|
if (!blob) return;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Get dest info
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-10-17 04:18:15 +00:00
|
|
|
webgl::ImageInfo* imageInfo;
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!ValidateTexImageSpecification(target, level, blob->mWidth, blob->mHeight,
|
2016-10-21 01:03:40 +00:00
|
|
|
blob->mDepth, &imageInfo)) {
|
2015-11-24 03:27:13 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-11-25 04:15:29 +00:00
|
|
|
MOZ_ASSERT(imageInfo);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
auto usage = mContext->mFormatUsage->GetSizedTexUsage(internalFormat);
|
2018-10-17 19:13:14 +00:00
|
|
|
if (!usage || !usage->format->compression) {
|
|
|
|
mContext->ErrorInvalidEnumArg("internalFormat", internalFormat);
|
2015-11-25 04:15:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto format = usage->format;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!ValidateTargetForFormat(mContext, target, format)) return;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Get source info
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!ValidateCompressedTexUnpack(mContext, blob->mWidth, blob->mHeight,
|
2016-10-21 01:03:40 +00:00
|
|
|
blob->mDepth, format, blob->mAvailBytes)) {
|
2015-11-25 04:15:29 +00:00
|
|
|
return;
|
2015-08-03 21:34:46 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Check that source is compatible with dest
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!ValidateCompressedTexImageRestrictions(mContext, target, level, format,
|
2016-10-21 01:03:40 +00:00
|
|
|
blob->mWidth, blob->mHeight,
|
|
|
|
blob->mDepth)) {
|
2015-11-25 04:15:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Do the thing!
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2017-07-18 18:02:57 +00:00
|
|
|
const ScopedLazyBind bindPBO(mContext->gl, LOCAL_GL_PIXEL_UNPACK_BUFFER,
|
|
|
|
mContext->mBoundPixelUnpackBuffer);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-26 11:47:53 +00:00
|
|
|
// Warning: Possibly shared memory. See bug 1225033.
|
2015-11-25 04:15:29 +00:00
|
|
|
GLenum error = DoCompressedTexImage(
|
|
|
|
mContext->gl, target, level, internalFormat, blob->mWidth, blob->mHeight,
|
2016-10-21 01:03:40 +00:00
|
|
|
blob->mDepth, blob->mAvailBytes, blob->mPtr);
|
2017-06-22 18:32:00 +00:00
|
|
|
mContext->OnDataAllocCall();
|
2015-11-25 04:15:29 +00:00
|
|
|
if (error == LOCAL_GL_OUT_OF_MEMORY) {
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorOutOfMemory("Ran out of memory during upload.");
|
2015-11-25 04:15:29 +00:00
|
|
|
return;
|
2015-08-03 21:34:46 +00:00
|
|
|
}
|
|
|
|
if (error) {
|
2016-06-06 15:17:23 +00:00
|
|
|
MOZ_RELEASE_ASSERT(false, "GFX: We should have caught all other errors.");
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->GenerateWarning(
|
|
|
|
"Unexpected error during texture upload. Context"
|
|
|
|
" lost.");
|
2015-11-25 04:15:29 +00:00
|
|
|
mContext->ForceLoseContext();
|
2015-08-03 21:34:46 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Update our specification data.
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
const bool isDataInitialized = true;
|
2018-10-17 04:18:15 +00:00
|
|
|
const webgl::ImageInfo newImageInfo{usage, blob->mWidth, blob->mHeight,
|
|
|
|
blob->mDepth, isDataInitialized};
|
|
|
|
*imageInfo = newImageInfo;
|
|
|
|
InvalidateCaches();
|
2015-08-03 21:34:46 +00:00
|
|
|
}
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
static inline bool IsSubImageBlockAligned(
|
|
|
|
const webgl::CompressedFormatInfo* compression,
|
2018-10-17 04:18:15 +00:00
|
|
|
const webgl::ImageInfo* imageInfo, GLint xOffset, GLint yOffset,
|
2015-11-25 04:15:29 +00:00
|
|
|
uint32_t width, uint32_t height) {
|
|
|
|
if (xOffset % compression->blockWidth != 0 ||
|
|
|
|
yOffset % compression->blockHeight != 0) {
|
|
|
|
return false;
|
2015-08-03 21:34:46 +00:00
|
|
|
}
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
if (width % compression->blockWidth != 0 &&
|
|
|
|
xOffset + width != imageInfo->mWidth)
|
|
|
|
return false;
|
2015-11-24 03:27:13 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
if (height % compression->blockHeight != 0 &&
|
|
|
|
yOffset + height != imageInfo->mHeight)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2015-08-03 21:34:46 +00:00
|
|
|
}
|
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
void WebGLTexture::CompressedTexSubImage(
|
2015-11-25 04:15:29 +00:00
|
|
|
TexImageTarget target, GLint level, GLint xOffset, GLint yOffset,
|
2016-06-22 17:28:11 +00:00
|
|
|
GLint zOffset, GLsizei rawWidth, GLsizei rawHeight, GLsizei rawDepth,
|
|
|
|
GLenum sizedUnpackFormat, const TexImageSource& src,
|
2017-07-18 18:02:57 +00:00
|
|
|
const Maybe<GLsizei>& expectedImageSize) {
|
2016-10-21 01:03:40 +00:00
|
|
|
const GLint border = 0;
|
2018-07-27 04:46:33 +00:00
|
|
|
const auto blob = mContext->FromCompressed(
|
2017-07-18 18:02:57 +00:00
|
|
|
target, rawWidth, rawHeight, rawDepth, border, src, expectedImageSize);
|
2016-10-21 01:03:40 +00:00
|
|
|
if (!blob) return;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Get dest info
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-10-17 04:18:15 +00:00
|
|
|
webgl::ImageInfo* imageInfo;
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!ValidateTexImageSelection(target, level, xOffset, yOffset, zOffset,
|
2016-10-21 01:03:40 +00:00
|
|
|
blob->mWidth, blob->mHeight, blob->mDepth,
|
|
|
|
&imageInfo)) {
|
2015-11-24 05:55:59 +00:00
|
|
|
return;
|
2015-11-25 04:15:29 +00:00
|
|
|
}
|
|
|
|
MOZ_ASSERT(imageInfo);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
auto dstUsage = imageInfo->mFormat;
|
|
|
|
auto dstFormat = dstUsage->format;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Get source info
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
auto srcUsage = mContext->mFormatUsage->GetSizedTexUsage(sizedUnpackFormat);
|
2018-10-17 19:13:14 +00:00
|
|
|
if (!srcUsage || !srcUsage->format->compression) {
|
|
|
|
mContext->ErrorInvalidEnumArg("sizedUnpackFormat", sizedUnpackFormat);
|
2015-08-03 21:34:46 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-11-25 04:15:29 +00:00
|
|
|
if (srcUsage != dstUsage) {
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorInvalidOperation(
|
|
|
|
"`format` must match the format of the"
|
|
|
|
" existing texture image.");
|
2015-08-03 21:34:46 +00:00
|
|
|
return;
|
2015-11-24 03:27:13 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
auto format = srcUsage->format;
|
|
|
|
MOZ_ASSERT(format == dstFormat);
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!ValidateCompressedTexUnpack(mContext, blob->mWidth, blob->mHeight,
|
2016-10-21 01:03:40 +00:00
|
|
|
blob->mDepth, format, blob->mAvailBytes)) {
|
2015-11-24 03:27:13 +00:00
|
|
|
return;
|
2015-11-25 04:15:29 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Check that source is compatible with dest
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
switch (format->compression->family) {
|
|
|
|
// Forbidden:
|
|
|
|
case webgl::CompressionFamily::ETC1:
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorInvalidOperation(
|
|
|
|
"Format does not allow sub-image"
|
|
|
|
" updates.");
|
2015-11-25 04:15:29 +00:00
|
|
|
return;
|
2015-11-24 05:55:59 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
// Block-aligned:
|
|
|
|
case webgl::CompressionFamily::ES3: // Yes, the ES3 formats don't match the
|
|
|
|
// ES3
|
|
|
|
case webgl::CompressionFamily::S3TC: // default behavior.
|
2018-09-27 23:37:40 +00:00
|
|
|
case webgl::CompressionFamily::BPTC:
|
|
|
|
case webgl::CompressionFamily::RGTC:
|
2015-11-25 04:15:29 +00:00
|
|
|
if (!IsSubImageBlockAligned(dstFormat->compression, imageInfo, xOffset,
|
2016-10-21 01:03:40 +00:00
|
|
|
yOffset, blob->mWidth, blob->mHeight)) {
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorInvalidOperation(
|
|
|
|
"Format requires block-aligned sub-image"
|
|
|
|
" updates.");
|
2015-08-03 21:34:46 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-07-18 18:02:57 +00:00
|
|
|
break;
|
|
|
|
|
2015-11-26 11:47:53 +00:00
|
|
|
// Full-only: (The ES3 default)
|
|
|
|
default: // PVRTC
|
2016-10-21 01:03:40 +00:00
|
|
|
if (xOffset || yOffset || blob->mWidth != imageInfo->mWidth ||
|
|
|
|
blob->mHeight != imageInfo->mHeight) {
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorInvalidOperation(
|
|
|
|
"Format does not allow partial sub-image"
|
|
|
|
" updates.");
|
2015-11-25 04:15:29 +00:00
|
|
|
return;
|
2015-08-03 21:34:46 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Do the thing!
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!EnsureImageDataInitializedForUpload(
|
2018-11-27 10:08:58 +00:00
|
|
|
this, target, level, xOffset, yOffset, zOffset, blob->mWidth,
|
2018-10-17 04:18:15 +00:00
|
|
|
blob->mHeight, blob->mDepth, imageInfo)) {
|
2018-11-30 10:46:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-18 18:02:57 +00:00
|
|
|
const ScopedLazyBind bindPBO(mContext->gl, LOCAL_GL_PIXEL_UNPACK_BUFFER,
|
|
|
|
mContext->mBoundPixelUnpackBuffer);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-26 11:47:53 +00:00
|
|
|
// Warning: Possibly shared memory. See bug 1225033.
|
2015-11-25 04:15:29 +00:00
|
|
|
GLenum error = DoCompressedTexSubImage(
|
2018-11-27 10:08:58 +00:00
|
|
|
mContext->gl, target, level, xOffset, yOffset, zOffset, blob->mWidth,
|
2016-10-21 01:03:40 +00:00
|
|
|
blob->mHeight, blob->mDepth, sizedUnpackFormat, blob->mAvailBytes,
|
|
|
|
blob->mPtr);
|
2015-11-25 04:15:29 +00:00
|
|
|
if (error == LOCAL_GL_OUT_OF_MEMORY) {
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorOutOfMemory("Ran out of memory during upload.");
|
2018-11-30 10:46:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-11-25 04:15:29 +00:00
|
|
|
if (error) {
|
2016-06-06 15:17:23 +00:00
|
|
|
MOZ_RELEASE_ASSERT(false, "GFX: We should have caught all other errors.");
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->GenerateWarning(
|
|
|
|
"Unexpected error during texture upload. Context"
|
2018-11-30 10:46:48 +00:00
|
|
|
" lost.");
|
2015-11-25 04:15:29 +00:00
|
|
|
mContext->ForceLoseContext();
|
2018-11-30 10:46:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Update our specification data?
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2018-10-17 04:18:15 +00:00
|
|
|
imageInfo->mHasData = true;
|
2015-11-25 04:15:29 +00:00
|
|
|
}
|
2015-11-24 05:55:59 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////////
|
|
|
|
// CopyTex(Sub)Image
|
2015-11-24 05:55:59 +00:00
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
static bool ValidateCopyTexImageFormats(WebGLContext* webgl,
|
2015-11-25 04:15:29 +00:00
|
|
|
const webgl::FormatInfo* srcFormat,
|
|
|
|
const webgl::FormatInfo* dstFormat) {
|
|
|
|
MOZ_ASSERT(!srcFormat->compression);
|
|
|
|
if (dstFormat->compression) {
|
2018-07-27 04:46:33 +00:00
|
|
|
webgl->ErrorInvalidEnum(
|
|
|
|
"Specified destination must not have a compressed"
|
|
|
|
" format.");
|
2015-11-25 04:15:29 +00:00
|
|
|
return false;
|
2015-08-03 21:34:46 +00:00
|
|
|
}
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
if (dstFormat->effectiveFormat == webgl::EffectiveFormat::RGB9_E5) {
|
2018-07-27 04:46:33 +00:00
|
|
|
webgl->ErrorInvalidOperation(
|
|
|
|
"RGB9_E5 is an invalid destination for"
|
|
|
|
" CopyTex(Sub)Image. (GLES 3.0.4 p145)");
|
2015-11-25 04:15:29 +00:00
|
|
|
return false;
|
2015-11-24 03:27:13 +00:00
|
|
|
}
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
if (!DoChannelsMatchForCopyTexImage(srcFormat, dstFormat)) {
|
2018-07-27 04:46:33 +00:00
|
|
|
webgl->ErrorInvalidOperation(
|
|
|
|
"Destination channels must be compatible with"
|
|
|
|
" source channels. (GLES 3.0.4 p140 Table 3.16)");
|
2015-11-25 04:15:29 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
return true;
|
2015-11-24 05:55:59 +00:00
|
|
|
}
|
2015-11-24 03:27:13 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class ScopedCopyTexImageSource {
|
|
|
|
WebGLContext* const mWebGL;
|
|
|
|
GLuint mRB;
|
|
|
|
GLuint mFB;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
public:
|
2018-07-27 04:46:33 +00:00
|
|
|
ScopedCopyTexImageSource(WebGLContext* webgl, uint32_t srcWidth,
|
2015-11-25 04:15:29 +00:00
|
|
|
uint32_t srcHeight,
|
|
|
|
const webgl::FormatInfo* srcFormat,
|
|
|
|
const webgl::FormatUsageInfo* dstUsage);
|
|
|
|
~ScopedCopyTexImageSource();
|
|
|
|
};
|
|
|
|
|
|
|
|
ScopedCopyTexImageSource::ScopedCopyTexImageSource(
|
|
|
|
WebGLContext* webgl, uint32_t srcWidth, uint32_t srcHeight,
|
|
|
|
const webgl::FormatInfo* srcFormat, const webgl::FormatUsageInfo* dstUsage)
|
|
|
|
: mWebGL(webgl), mRB(0), mFB(0) {
|
|
|
|
switch (dstUsage->format->unsizedFormat) {
|
|
|
|
case webgl::UnsizedFormat::L:
|
|
|
|
case webgl::UnsizedFormat::A:
|
|
|
|
case webgl::UnsizedFormat::LA:
|
2018-07-27 04:46:33 +00:00
|
|
|
webgl->GenerateWarning(
|
|
|
|
"Copying to a LUMINANCE, ALPHA, or LUMINANCE_ALPHA"
|
2015-11-25 04:15:29 +00:00
|
|
|
" is deprecated, and has severely reduced performance"
|
2018-07-27 04:46:33 +00:00
|
|
|
" on some platforms.");
|
2015-11-25 04:15:29 +00:00
|
|
|
break;
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
default:
|
|
|
|
MOZ_ASSERT(!dstUsage->textureSwizzleRGBA);
|
|
|
|
return;
|
|
|
|
}
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
if (!dstUsage->textureSwizzleRGBA) return;
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
gl::GLContext* gl = webgl->gl;
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
GLenum sizedFormat;
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
switch (srcFormat->componentType) {
|
|
|
|
case webgl::ComponentType::NormUInt:
|
|
|
|
sizedFormat = LOCAL_GL_RGBA8;
|
|
|
|
break;
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
case webgl::ComponentType::Float:
|
|
|
|
if (webgl->IsExtensionEnabled(
|
|
|
|
WebGLExtensionID::WEBGL_color_buffer_float)) {
|
|
|
|
sizedFormat = LOCAL_GL_RGBA32F;
|
|
|
|
break;
|
|
|
|
}
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
if (webgl->IsExtensionEnabled(
|
|
|
|
WebGLExtensionID::EXT_color_buffer_half_float)) {
|
|
|
|
sizedFormat = LOCAL_GL_RGBA16F;
|
|
|
|
break;
|
|
|
|
}
|
2016-06-06 15:17:23 +00:00
|
|
|
MOZ_CRASH("GFX: Should be able to request CopyTexImage from Float.");
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
default:
|
2016-06-06 15:17:23 +00:00
|
|
|
MOZ_CRASH("GFX: Should be able to request CopyTexImage from this type.");
|
2015-08-03 21:34:46 +00:00
|
|
|
}
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
gl::ScopedTexture scopedTex(gl);
|
|
|
|
gl::ScopedBindTexture scopedBindTex(gl, scopedTex.Texture(),
|
|
|
|
LOCAL_GL_TEXTURE_2D);
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER,
|
|
|
|
LOCAL_GL_NEAREST);
|
|
|
|
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER,
|
|
|
|
LOCAL_GL_NEAREST);
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
GLint blitSwizzle[4] = {LOCAL_GL_ZERO};
|
|
|
|
switch (dstUsage->format->unsizedFormat) {
|
|
|
|
case webgl::UnsizedFormat::L:
|
|
|
|
blitSwizzle[0] = LOCAL_GL_RED;
|
|
|
|
break;
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
case webgl::UnsizedFormat::A:
|
|
|
|
blitSwizzle[0] = LOCAL_GL_ALPHA;
|
|
|
|
break;
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
case webgl::UnsizedFormat::LA:
|
|
|
|
blitSwizzle[0] = LOCAL_GL_RED;
|
|
|
|
blitSwizzle[1] = LOCAL_GL_ALPHA;
|
|
|
|
break;
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
default:
|
2016-06-06 15:17:23 +00:00
|
|
|
MOZ_CRASH("GFX: Unhandled unsizedFormat.");
|
2015-08-03 21:34:46 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_SWIZZLE_R,
|
|
|
|
blitSwizzle[0]);
|
|
|
|
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_SWIZZLE_G,
|
|
|
|
blitSwizzle[1]);
|
|
|
|
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_SWIZZLE_B,
|
|
|
|
blitSwizzle[2]);
|
|
|
|
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_SWIZZLE_A,
|
|
|
|
blitSwizzle[3]);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
gl->fCopyTexImage2D(LOCAL_GL_TEXTURE_2D, 0, sizedFormat, 0, 0, srcWidth,
|
|
|
|
srcHeight, 0);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
// Now create the swizzled FB we'll be exposing.
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
GLuint rgbaRB = 0;
|
|
|
|
gl->fGenRenderbuffers(1, &rgbaRB);
|
|
|
|
gl::ScopedBindRenderbuffer scopedRB(gl, rgbaRB);
|
|
|
|
gl->fRenderbufferStorage(LOCAL_GL_RENDERBUFFER, sizedFormat, srcWidth,
|
|
|
|
srcHeight);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
GLuint rgbaFB = 0;
|
|
|
|
gl->fGenFramebuffers(1, &rgbaFB);
|
|
|
|
gl->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, rgbaFB);
|
|
|
|
gl->fFramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_COLOR_ATTACHMENT0,
|
|
|
|
LOCAL_GL_RENDERBUFFER, rgbaRB);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
const GLenum status = gl->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
|
|
|
|
if (status != LOCAL_GL_FRAMEBUFFER_COMPLETE) {
|
2016-06-06 15:17:23 +00:00
|
|
|
MOZ_CRASH("GFX: Temp framebuffer is not complete.");
|
2015-08-03 21:34:46 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
// Restore RB binding.
|
|
|
|
scopedRB.Unwrap(); // This function should really have a better name.
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
// Draw-blit rgbaTex into rgbaFB.
|
|
|
|
const gfx::IntSize srcSize(srcWidth, srcHeight);
|
2017-07-18 02:17:41 +00:00
|
|
|
{
|
|
|
|
const gl::ScopedBindFramebuffer bindFB(gl, rgbaFB);
|
|
|
|
gl->BlitHelper()->DrawBlitTextureToFramebuffer(scopedTex.Texture(), srcSize,
|
|
|
|
srcSize);
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
// Restore Tex2D binding and destroy the temp tex.
|
|
|
|
scopedBindTex.Unwrap();
|
|
|
|
scopedTex.Unwrap();
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
// Leave RB and FB alive, and FB bound.
|
|
|
|
mRB = rgbaRB;
|
|
|
|
mFB = rgbaFB;
|
2015-08-03 21:34:46 +00:00
|
|
|
}
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
template <typename T>
|
|
|
|
static inline GLenum ToGLHandle(const T& obj) {
|
|
|
|
return (obj ? obj->mGLName : 0);
|
2015-08-03 21:34:46 +00:00
|
|
|
}
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
ScopedCopyTexImageSource::~ScopedCopyTexImageSource() {
|
|
|
|
if (!mFB) {
|
|
|
|
MOZ_ASSERT(!mRB);
|
|
|
|
return;
|
2015-08-03 21:34:46 +00:00
|
|
|
}
|
2015-11-25 04:15:29 +00:00
|
|
|
MOZ_ASSERT(mRB);
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
gl::GLContext* gl = mWebGL->gl;
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
// If we're swizzling, it's because we're on a GL core (3.2+) profile, which
|
|
|
|
// has split framebuffer support.
|
|
|
|
gl->fBindFramebuffer(LOCAL_GL_DRAW_FRAMEBUFFER,
|
|
|
|
ToGLHandle(mWebGL->mBoundDrawFramebuffer));
|
|
|
|
gl->fBindFramebuffer(LOCAL_GL_READ_FRAMEBUFFER,
|
|
|
|
ToGLHandle(mWebGL->mBoundReadFramebuffer));
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
gl->fDeleteFramebuffers(1, &mFB);
|
|
|
|
gl->fDeleteRenderbuffers(1, &mRB);
|
2015-11-24 05:55:59 +00:00
|
|
|
}
|
2015-11-24 03:27:13 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-06-06 20:42:50 +00:00
|
|
|
static bool GetUnsizedFormatForCopy(GLenum internalFormat,
|
|
|
|
webgl::UnsizedFormat* const out) {
|
|
|
|
switch (internalFormat) {
|
|
|
|
case LOCAL_GL_RED:
|
|
|
|
*out = webgl::UnsizedFormat::R;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_RG:
|
|
|
|
*out = webgl::UnsizedFormat::RG;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_RGB:
|
|
|
|
*out = webgl::UnsizedFormat::RGB;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_RGBA:
|
|
|
|
*out = webgl::UnsizedFormat::RGBA;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_LUMINANCE:
|
|
|
|
*out = webgl::UnsizedFormat::L;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_ALPHA:
|
|
|
|
*out = webgl::UnsizedFormat::A;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_LUMINANCE_ALPHA:
|
|
|
|
*out = webgl::UnsizedFormat::LA;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const webgl::FormatUsageInfo* ValidateCopyDestUsage(
|
|
|
|
WebGLContext* webgl, const webgl::FormatInfo* srcFormat,
|
|
|
|
GLenum internalFormat) {
|
|
|
|
const auto& fua = webgl->mFormatUsage;
|
|
|
|
|
|
|
|
auto dstUsage = fua->GetSizedTexUsage(internalFormat);
|
|
|
|
if (!dstUsage) {
|
|
|
|
// Ok, maybe it's unsized.
|
|
|
|
webgl::UnsizedFormat unsizedFormat;
|
|
|
|
if (!GetUnsizedFormatForCopy(internalFormat, &unsizedFormat)) {
|
2018-07-27 04:46:33 +00:00
|
|
|
webgl->ErrorInvalidEnumInfo("internalFormat", internalFormat);
|
2016-06-06 20:42:50 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto dstFormat = srcFormat->GetCopyDecayFormat(unsizedFormat);
|
2018-10-24 15:31:43 +00:00
|
|
|
if (dstFormat) {
|
2018-07-27 04:46:33 +00:00
|
|
|
dstUsage = fua->GetUsage(dstFormat->effectiveFormat);
|
2016-06-06 20:42:50 +00:00
|
|
|
}
|
|
|
|
if (!dstUsage) {
|
|
|
|
webgl->ErrorInvalidOperation(
|
2018-07-27 04:46:33 +00:00
|
|
|
"0x%04x is not a valid unsized format for"
|
2016-06-06 20:42:50 +00:00
|
|
|
" source format %s.",
|
2018-07-27 04:46:33 +00:00
|
|
|
internalFormat, srcFormat->name);
|
2016-06-06 20:42:50 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dstUsage;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2016-06-06 20:42:50 +00:00
|
|
|
// Alright, it's sized.
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-12-08 00:56:52 +00:00
|
|
|
const auto dstFormat = dstUsage->format;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-10-24 15:31:43 +00:00
|
|
|
if (dstFormat->componentType != srcFormat->componentType) {
|
2018-07-27 04:46:33 +00:00
|
|
|
webgl->ErrorInvalidOperation(
|
|
|
|
"For sized internalFormats, source and dest"
|
2016-06-06 20:42:50 +00:00
|
|
|
" component types must match. (source: %s, dest:"
|
2018-11-30 10:46:48 +00:00
|
|
|
" %s)",
|
2018-07-27 04:46:33 +00:00
|
|
|
srcFormat->name, dstFormat->name);
|
2016-06-06 20:42:50 +00:00
|
|
|
return nullptr;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
|
|
|
|
2016-06-06 20:42:50 +00:00
|
|
|
bool componentSizesMatch = true;
|
|
|
|
if (dstFormat->r) {
|
|
|
|
componentSizesMatch &= (dstFormat->r == srcFormat->r);
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2016-06-06 20:42:50 +00:00
|
|
|
if (dstFormat->g) {
|
|
|
|
componentSizesMatch &= (dstFormat->g == srcFormat->g);
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2016-06-06 20:42:50 +00:00
|
|
|
if (dstFormat->b) {
|
|
|
|
componentSizesMatch &= (dstFormat->b == srcFormat->b);
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2016-06-06 20:42:50 +00:00
|
|
|
if (dstFormat->a) {
|
|
|
|
componentSizesMatch &= (dstFormat->a == srcFormat->a);
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
|
|
|
|
2016-06-06 20:42:50 +00:00
|
|
|
if (!componentSizesMatch) {
|
2018-07-27 04:46:33 +00:00
|
|
|
webgl->ErrorInvalidOperation(
|
|
|
|
"For sized internalFormats, source and dest"
|
2016-06-06 20:42:50 +00:00
|
|
|
" component sizes must match exactly. (source: %s,"
|
|
|
|
" dest: %s)",
|
2018-07-27 04:46:33 +00:00
|
|
|
srcFormat->name, dstFormat->name);
|
2016-06-06 20:42:50 +00:00
|
|
|
return nullptr;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
|
|
|
|
2016-06-06 20:42:50 +00:00
|
|
|
return dstUsage;
|
|
|
|
}
|
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
bool WebGLTexture::ValidateCopyTexImageForFeedback(uint32_t level,
|
|
|
|
GLint layer) const {
|
2016-07-13 07:48:55 +00:00
|
|
|
const auto& fb = mContext->mBoundReadFramebuffer;
|
|
|
|
if (fb) {
|
2016-07-19 07:36:54 +00:00
|
|
|
const auto& attach = fb->ColorReadBuffer();
|
|
|
|
MOZ_ASSERT(attach);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-07-19 07:36:54 +00:00
|
|
|
if (attach->Texture() == this && attach->Layer() == layer &&
|
|
|
|
uint32_t(attach->MipLevel()) == level) {
|
2016-07-13 07:48:55 +00:00
|
|
|
// Note that the TexImageTargets *don't* have to match for this to be
|
|
|
|
// undefined per GLES 3.0.4 p211, thus an INVALID_OP in WebGL.
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorInvalidOperation(
|
|
|
|
"Feedback loop detected, as this texture"
|
2016-07-13 07:48:55 +00:00
|
|
|
" is already attached to READ_FRAMEBUFFER's"
|
|
|
|
" READ_BUFFER-selected COLOR_ATTACHMENT%u.",
|
2018-07-27 04:46:33 +00:00
|
|
|
attach->mAttachmentPoint);
|
2016-07-13 07:48:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
static bool DoCopyTexOrSubImage(WebGLContext* webgl, bool isSubImage,
|
2016-12-08 00:56:52 +00:00
|
|
|
const WebGLTexture* tex, TexImageTarget target,
|
|
|
|
GLint level, GLint xWithinSrc, GLint yWithinSrc,
|
|
|
|
uint32_t srcTotalWidth, uint32_t srcTotalHeight,
|
|
|
|
const webgl::FormatUsageInfo* srcUsage,
|
|
|
|
GLint xOffset, GLint yOffset, GLint zOffset,
|
2017-02-27 23:24:14 +00:00
|
|
|
uint32_t dstWidth, uint32_t dstHeight,
|
2018-07-27 04:46:33 +00:00
|
|
|
const webgl::FormatUsageInfo* dstUsage) {
|
2016-12-08 00:56:52 +00:00
|
|
|
const auto& gl = webgl->gl;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
|
|
|
////
|
|
|
|
|
2016-12-08 00:56:52 +00:00
|
|
|
int32_t readX, readY;
|
2017-02-27 23:24:14 +00:00
|
|
|
int32_t writeX, writeY;
|
|
|
|
int32_t rwWidth, rwHeight;
|
|
|
|
if (!Intersect(srcTotalWidth, xWithinSrc, dstWidth, &readX, &writeX,
|
2016-12-08 22:58:23 +00:00
|
|
|
&rwWidth) ||
|
|
|
|
!Intersect(srcTotalHeight, yWithinSrc, dstHeight, &readY, &writeY,
|
|
|
|
&rwHeight)) {
|
2018-07-27 04:46:33 +00:00
|
|
|
webgl->ErrorOutOfMemory("Bad subrect selection.");
|
2016-12-08 00:56:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-05 01:07:53 +00:00
|
|
|
writeX += xOffset;
|
2016-12-08 00:56:52 +00:00
|
|
|
writeY += yOffset;
|
|
|
|
|
2018-11-30 10:46:48 +00:00
|
|
|
////
|
2016-12-08 00:56:52 +00:00
|
|
|
|
|
|
|
GLenum error = 0;
|
2018-11-30 10:46:48 +00:00
|
|
|
do {
|
2016-12-08 00:56:52 +00:00
|
|
|
const auto& idealUnpack = dstUsage->idealUnpack;
|
|
|
|
if (!isSubImage) {
|
2016-12-08 22:58:23 +00:00
|
|
|
UniqueBuffer buffer;
|
2016-12-08 00:56:52 +00:00
|
|
|
|
|
|
|
if (uint32_t(rwWidth) != dstWidth || uint32_t(rwHeight) != dstHeight) {
|
2018-07-27 04:46:33 +00:00
|
|
|
const auto& pi = idealUnpack->ToPacking();
|
|
|
|
CheckedUint32 byteCount = BytesPerPixel(pi);
|
|
|
|
byteCount *= dstWidth;
|
2016-12-08 00:56:52 +00:00
|
|
|
byteCount *= dstHeight;
|
|
|
|
|
2016-12-20 01:53:52 +00:00
|
|
|
if (byteCount.isValid()) {
|
2018-07-27 04:46:33 +00:00
|
|
|
buffer = calloc(1, byteCount.value());
|
2016-12-20 01:53:52 +00:00
|
|
|
}
|
|
|
|
|
2016-12-08 00:56:52 +00:00
|
|
|
if (!buffer.get()) {
|
2018-07-27 04:46:33 +00:00
|
|
|
webgl->ErrorOutOfMemory("Ran out of memory allocating zeros.");
|
2016-12-08 00:56:52 +00:00
|
|
|
return false;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2016-12-08 00:56:52 +00:00
|
|
|
}
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
const ScopedUnpackReset unpackReset(webgl);
|
|
|
|
gl->fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, 1);
|
2018-07-27 04:46:33 +00:00
|
|
|
error = DoTexImage(gl, target, level, idealUnpack, dstWidth, dstHeight, 1,
|
2016-12-08 22:58:23 +00:00
|
|
|
buffer.get());
|
2018-07-27 04:46:33 +00:00
|
|
|
if (error) break;
|
2016-06-22 17:28:11 +00:00
|
|
|
}
|
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!rwWidth || !rwHeight) {
|
2015-11-25 04:15:29 +00:00
|
|
|
// There aren't any pixels to copy, so we're 'done'.
|
|
|
|
return true;
|
2016-12-08 00:56:52 +00:00
|
|
|
}
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2016-12-08 00:56:52 +00:00
|
|
|
const auto& srcFormat = srcUsage->format;
|
2018-07-27 04:46:33 +00:00
|
|
|
ScopedCopyTexImageSource maybeSwizzle(webgl, srcTotalWidth, srcTotalHeight,
|
|
|
|
srcFormat, dstUsage);
|
2016-06-06 20:42:50 +00:00
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
error = DoCopyTexSubImage(gl, target, level, writeX, writeY, zOffset, readX,
|
|
|
|
readY, rwWidth, rwHeight);
|
|
|
|
if (error) break;
|
2015-11-24 05:55:59 +00:00
|
|
|
|
2015-08-03 21:34:46 +00:00
|
|
|
return true;
|
2016-12-08 00:56:52 +00:00
|
|
|
} while (false);
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2017-06-22 18:32:00 +00:00
|
|
|
if (error == LOCAL_GL_OUT_OF_MEMORY) {
|
|
|
|
webgl->ErrorOutOfMemory("Ran out of memory during texture copy.");
|
|
|
|
return false;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2017-06-22 18:32:00 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
if (gl->IsANGLE() && error == LOCAL_GL_INVALID_OPERATION) {
|
|
|
|
webgl->ErrorImplementationBug(
|
|
|
|
"ANGLE is particular about CopyTexSubImage"
|
|
|
|
" formats matching exactly.");
|
|
|
|
return false;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2015-11-25 04:15:29 +00:00
|
|
|
|
2018-10-17 04:18:15 +00:00
|
|
|
MOZ_RELEASE_ASSERT(false, "GFX: We should have caught all other errors.");
|
|
|
|
webgl->GenerateWarning("Unexpected error during texture copy. Context lost.");
|
|
|
|
webgl->ForceLoseContext();
|
|
|
|
return false;
|
2015-08-03 21:34:46 +00:00
|
|
|
}
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
// There is no CopyTexImage3D.
|
2018-07-27 04:46:33 +00:00
|
|
|
void WebGLTexture::CopyTexImage2D(TexImageTarget target, GLint level,
|
2015-11-25 04:15:29 +00:00
|
|
|
GLenum internalFormat, GLint x, GLint y,
|
2016-06-22 17:28:11 +00:00
|
|
|
GLsizei rawWidth, GLsizei rawHeight,
|
|
|
|
GLint border) {
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Get dest info
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-06-22 17:28:11 +00:00
|
|
|
uint32_t width, height, depth;
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!ValidateExtents(mContext, rawWidth, rawHeight, 1, border, &width,
|
2016-06-22 17:28:11 +00:00
|
|
|
&height, &depth)) {
|
|
|
|
return;
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-10-17 04:18:15 +00:00
|
|
|
webgl::ImageInfo* imageInfo;
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!ValidateTexImageSpecification(target, level, width, height, depth,
|
|
|
|
&imageInfo))
|
2018-11-30 10:46:48 +00:00
|
|
|
return;
|
2015-11-25 04:15:29 +00:00
|
|
|
MOZ_ASSERT(imageInfo);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Get source info
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-10-17 04:18:15 +00:00
|
|
|
const webgl::FormatUsageInfo* srcUsage;
|
2015-11-25 04:15:29 +00:00
|
|
|
uint32_t srcTotalWidth;
|
|
|
|
uint32_t srcTotalHeight;
|
2016-07-08 21:57:18 +00:00
|
|
|
if (!mContext->BindCurFBForColorRead(&srcUsage, &srcTotalWidth,
|
2018-07-27 04:46:33 +00:00
|
|
|
&srcTotalHeight)) {
|
2018-11-30 10:46:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!ValidateCopyTexImageForFeedback(level)) return;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Check that source and dest info are compatible
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
const auto& srcFormat = srcUsage->format;
|
|
|
|
const auto dstUsage =
|
2018-07-27 04:46:33 +00:00
|
|
|
ValidateCopyDestUsage(mContext, srcFormat, internalFormat);
|
|
|
|
if (!dstUsage) return;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-12-08 00:56:52 +00:00
|
|
|
const auto& dstFormat = dstUsage->format;
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!ValidateTargetForFormat(mContext, target, dstFormat)) return;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-07-08 21:57:18 +00:00
|
|
|
if (!mContext->IsWebGL2() && dstFormat->d) {
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorInvalidOperation(
|
|
|
|
"Function may not be called with format %s.", dstFormat->name);
|
2018-11-30 10:46:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!ValidateCopyTexImageFormats(mContext, srcFormat, dstFormat)) return;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Do the thing!
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-12-08 00:56:52 +00:00
|
|
|
const bool isSubImage = false;
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!DoCopyTexOrSubImage(mContext, isSubImage, this, target, level, x, y,
|
2016-12-08 00:56:52 +00:00
|
|
|
srcTotalWidth, srcTotalHeight, srcUsage, 0, 0, 0,
|
|
|
|
width, height, dstUsage)) {
|
2015-11-25 04:15:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2017-06-22 18:32:00 +00:00
|
|
|
mContext->OnDataAllocCall();
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Update our specification data.
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
const bool isDataInitialized = true;
|
2018-10-17 04:18:15 +00:00
|
|
|
const webgl::ImageInfo newImageInfo{dstUsage, width, height, depth,
|
|
|
|
isDataInitialized};
|
|
|
|
*imageInfo = newImageInfo;
|
|
|
|
InvalidateCaches();
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2015-08-03 21:34:46 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
void WebGLTexture::CopyTexSubImage(TexImageTarget target, GLint level,
|
|
|
|
GLint xOffset, GLint yOffset, GLint zOffset,
|
2016-06-22 17:28:11 +00:00
|
|
|
GLint x, GLint y, GLsizei rawWidth,
|
|
|
|
GLsizei rawHeight) {
|
|
|
|
uint32_t width, height, depth;
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!ValidateExtents(mContext, rawWidth, rawHeight, 1, 0, &width, &height,
|
2018-11-30 10:46:48 +00:00
|
|
|
&depth)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Get dest info
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-10-17 04:18:15 +00:00
|
|
|
webgl::ImageInfo* imageInfo;
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!ValidateTexImageSelection(target, level, xOffset, yOffset, zOffset,
|
2015-11-25 04:15:29 +00:00
|
|
|
width, height, depth, &imageInfo)) {
|
2018-11-30 10:46:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-11-25 04:15:29 +00:00
|
|
|
MOZ_ASSERT(imageInfo);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
auto dstUsage = imageInfo->mFormat;
|
|
|
|
MOZ_ASSERT(dstUsage);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-12-08 00:56:52 +00:00
|
|
|
auto dstFormat = dstUsage->format;
|
2016-07-08 21:57:18 +00:00
|
|
|
if (!mContext->IsWebGL2() && dstFormat->d) {
|
2018-07-27 04:46:33 +00:00
|
|
|
mContext->ErrorInvalidOperation(
|
|
|
|
"Function may not be called on a texture of"
|
2015-11-25 04:15:29 +00:00
|
|
|
" format %s.",
|
2018-07-27 04:46:33 +00:00
|
|
|
dstFormat->name);
|
2018-11-30 10:46:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Get source info
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
const webgl::FormatUsageInfo* srcUsage;
|
2016-12-08 00:56:52 +00:00
|
|
|
uint32_t srcTotalWidth;
|
|
|
|
uint32_t srcTotalHeight;
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!mContext->BindCurFBForColorRead(&srcUsage, &srcTotalWidth,
|
2017-12-19 02:30:56 +00:00
|
|
|
&srcTotalHeight)) {
|
2018-11-30 10:46:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!ValidateCopyTexImageForFeedback(level, zOffset)) return;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Check that source and dest info are compatible
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-12-08 00:56:52 +00:00
|
|
|
auto srcFormat = srcUsage->format;
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!ValidateCopyTexImageFormats(mContext, srcFormat, dstFormat)) return;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Do the thing!
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!EnsureImageDataInitializedForUpload(this, target, level, xOffset,
|
2015-11-25 04:15:29 +00:00
|
|
|
yOffset, zOffset, width, height,
|
2018-10-17 04:18:15 +00:00
|
|
|
depth, imageInfo)) {
|
2018-11-30 10:46:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-08 00:56:52 +00:00
|
|
|
const bool isSubImage = true;
|
2018-07-27 04:46:33 +00:00
|
|
|
if (!DoCopyTexOrSubImage(mContext, isSubImage, this, target, level, x, y,
|
2016-12-08 00:56:52 +00:00
|
|
|
srcTotalWidth, srcTotalHeight, srcUsage, xOffset,
|
2015-11-25 04:15:29 +00:00
|
|
|
yOffset, zOffset, width, height, dstUsage)) {
|
2018-11-30 10:46:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Update our specification data?
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-10-17 04:18:15 +00:00
|
|
|
imageInfo->mHasData = true;
|
2015-11-25 04:15:29 +00:00
|
|
|
}
|
2015-11-24 05:55:59 +00:00
|
|
|
|
2015-08-03 21:34:46 +00:00
|
|
|
} // namespace mozilla
|