Files
palemoon27/dom/canvas/WebGLContextFramebufferOperations.cpp
T
roytam1 18ad48cb0e import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1217835 - Rewrite some code in CanvasRenderingContext2D::GetImageDataArray to avoid build warnings; r=gw280 (cedba0b14a)
- Bug 1232864 - Cauterize and release WebGL 2 to Nightly. - r=jrmuizel (5a16387f1d)
- Bug 1229585 - Add helpful error text for fb incompleteness. - r=kamidphish (1a3d7505e2)
- Bug 1231303 - Moz2Dify nsFilterInstance. r=roc. (44ec4c5df6)
- Bug 1229235 - Make RedirectChannelRegistrar thread-safe. r=jduell (5acca6a770)
- Bug 1211090 - Use Buffered IO for PrefixSet load/store. r=froydnj (00720fe291)
- Bug 1211090 - Add fallocate support to nsIOutputFileStream and use it. r=froydnj (6a49aa4a5f)
- Bug 1211090 - Don't fail to open databases if we can't do buffered IO. r=froydnj (70ab38e03b)
- Bug 1223808 - part 3 - replace nsAutoArrayPtr<T> with UniquePtr<T[]> in netwerk/; r=mcmanus (4a1d880135)
- Bug 1223808 - part 1 - optimize creating a WebSocketFrame with a payload; r=mcmanus (9a046a6f0a)
- Bug 1223808 - part 2 - use UniquePtr<uint8_t[]> instead of nsAutoArrayPtr<SHA1Sum::Hash> in HandleHashKey; r=michal (c6a0f6d5d3)
- Bug 1167053 - Convert NetUtil.newChannel2 callsites to use new API - remove newChannel2,asyncFetch2 (r=sicking,paolo) (875b9c78f0)
- Bug 1185982 - Remove the unused NotifyNetworkActivity::mObs member; r=bagder (f09d2676f7)
- bits of Bug 1152597 - Icons are shown for some apps. (9a289ab9ec)
- Bug 1223231 - Use channel.asyncOpen2 in devtools/client/shared/AppCacheUtils.jsm (r=sicking) (5c635d797c)
- Bug 1208905 - Fix a condition in PresentationResponderLoadingCallback::Init; r=baku (ff84b8a595)
- Bug 1231677 - verify the return of mDiscoveryTimer->Init, if it faild exit function with error code. r=jst (04b8be172c)
- Bug 1199564 - start/stop mDNS on demand - v3. r=mcmanus (66d7ef06e6)
- Bug 1225726 - enable nsDNSServiceDiscovery on OS X. r=mcmanus. (01ea13e4a6)
- Bug 1172383 - Stop mDNS properly during destruction. r=mcmanus (c041817b7e)
- Bug 1198058 - Fix crashes inspecting loadGroups in browser toolbox. r=mcmanus (462b5aa8bd)
- Bug 1220607 - Expand on the nsILoadGroup interface's comment to indicate how it is used. r=bz IGNORE IDL (49a95cc217)
- use response for response (348055fc69)
- Remove some old clobber-workarounds. No bug. (db7e7c4773)
- Bug 280280 - Make "no proxy for" do domain comparison. r=bagder (4804e39fd6)
- backout f600f0cd7bb3 (Bug 1170646) because of Thunderbird regressions with OSX, r=michal (d43ba00896)
- Bug 1220215 - Add '#' between client id and suffix in appcache groud id, r=jduell (240fcec72a)
- Bug 1198792 - Clear Application Cache internal hashtables on Clear Recent History, r=jduell (1313393dc5)
- Bug 1222782 - TSan: data race netwerk/cache2/CacheIOThread.cpp:148 Target (race on mXPCOMThread), r=jseward (d56470a300)
- Bug 1190951 - TSan: data race netwerk/cache2/CacheIndex.cpp:1397 CacheIndex::IsUpToDate, r=valentin.gosu (24934e1885)
2023-07-18 14:31:13 +08:00

258 lines
6.7 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* 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 "WebGLContext.h"
#include "WebGLTexture.h"
#include "WebGLRenderbuffer.h"
#include "WebGLFramebuffer.h"
#include "GLContext.h"
#include "GLScreenBuffer.h"
namespace mozilla {
void
WebGLContext::Clear(GLbitfield mask)
{
const char funcName[] = "clear";
if (IsContextLost())
return;
MakeContextCurrent();
uint32_t m = mask & (LOCAL_GL_COLOR_BUFFER_BIT | LOCAL_GL_DEPTH_BUFFER_BIT | LOCAL_GL_STENCIL_BUFFER_BIT);
if (mask != m)
return ErrorInvalidValue("%s: invalid mask bits", funcName);
if (mask == 0) {
GenerateWarning("Calling gl.clear(0) has no effect.");
} else if (mRasterizerDiscardEnabled) {
GenerateWarning("Calling gl.clear() with RASTERIZER_DISCARD enabled has no effects.");
}
if (mBoundDrawFramebuffer) {
if (!mBoundDrawFramebuffer->ValidateAndInitAttachments(funcName))
return;
gl->fClear(mask);
return;
} else {
ClearBackbufferIfNeeded();
}
// Ok, we're clearing the default framebuffer/screen.
{
ScopedMaskWorkaround autoMask(*this);
gl->fClear(mask);
}
Invalidate();
mShouldPresent = true;
}
static GLfloat
GLClampFloat(GLfloat val)
{
if (val < 0.0)
return 0.0;
if (val > 1.0)
return 1.0;
return val;
}
void
WebGLContext::ClearColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a)
{
if (IsContextLost())
return;
MakeContextCurrent();
const bool supportsFloatColorBuffers = (IsExtensionEnabled(WebGLExtensionID::EXT_color_buffer_half_float) ||
IsExtensionEnabled(WebGLExtensionID::WEBGL_color_buffer_float));
if (!supportsFloatColorBuffers) {
r = GLClampFloat(r);
g = GLClampFloat(g);
b = GLClampFloat(b);
a = GLClampFloat(a);
}
gl->fClearColor(r, g, b, a);
mColorClearValue[0] = r;
mColorClearValue[1] = g;
mColorClearValue[2] = b;
mColorClearValue[3] = a;
}
void
WebGLContext::ClearDepth(GLclampf v)
{
if (IsContextLost())
return;
MakeContextCurrent();
mDepthClearValue = GLClampFloat(v);
gl->fClearDepth(mDepthClearValue);
}
void
WebGLContext::ClearStencil(GLint v)
{
if (IsContextLost())
return;
MakeContextCurrent();
mStencilClearValue = v;
gl->fClearStencil(v);
}
void
WebGLContext::ColorMask(WebGLboolean r, WebGLboolean g, WebGLboolean b, WebGLboolean a)
{
if (IsContextLost())
return;
MakeContextCurrent();
mColorWriteMask[0] = r;
mColorWriteMask[1] = g;
mColorWriteMask[2] = b;
mColorWriteMask[3] = a;
gl->fColorMask(r, g, b, a);
}
void
WebGLContext::DepthMask(WebGLboolean b)
{
if (IsContextLost())
return;
MakeContextCurrent();
mDepthWriteMask = b;
gl->fDepthMask(b);
}
void
WebGLContext::DrawBuffers(const dom::Sequence<GLenum>& buffers)
{
const char funcName[] = "drawBuffers";
if (IsContextLost())
return;
if (!mBoundDrawFramebuffer) {
// GLES 3.0.4 p186:
// "If the GL is bound to the default framebuffer, then `n` must be 1 and the
// constant must be BACK or NONE. [...] If DrawBuffers is supplied with a
// constant other than BACK and NONE, or with a value of `n` other than 1, the
// error INVALID_OPERATION is generated."
if (buffers.Length() != 1) {
ErrorInvalidOperation("%s: For the default framebuffer, `buffers` must have a"
" length of 1.",
funcName);
return;
}
switch (buffers[0]) {
case LOCAL_GL_NONE:
case LOCAL_GL_BACK:
break;
default:
ErrorInvalidOperation("%s: For the default framebuffer, `buffers[0]` must be"
" BACK or NONE.",
funcName);
return;
}
mDefaultFB_DrawBuffer0 = buffers[0];
gl->Screen()->SetDrawBuffer(buffers[0]);
return;
}
// Framebuffer object (not default framebuffer)
if (buffers.Length() > mImplMaxDrawBuffers) {
// "An INVALID_VALUE error is generated if `n` is greater than MAX_DRAW_BUFFERS."
ErrorInvalidValue("%s: `buffers` must have a length <= MAX_DRAW_BUFFERS.",
funcName);
return;
}
for (size_t i = 0; i < buffers.Length(); i++) {
// "If the GL is bound to a draw framebuffer object, the `i`th buffer listed in
// bufs must be COLOR_ATTACHMENTi or NONE. Specifying a buffer out of order,
// BACK, or COLOR_ATTACHMENTm where `m` is greater than or equal to the value of
// MAX_COLOR_ATTACHMENTS, will generate the error INVALID_OPERATION.
// WEBGL_draw_buffers:
// "The value of the MAX_COLOR_ATTACHMENTS_WEBGL parameter must be greater than or
// equal to that of the MAX_DRAW_BUFFERS_WEBGL parameter."
// This means that if buffers.Length() isn't larger than MaxDrawBuffers, it won't
// be larger than MaxColorAttachments.
if (buffers[i] != LOCAL_GL_NONE &&
buffers[i] != LOCAL_GL_COLOR_ATTACHMENT0 + i)
{
ErrorInvalidOperation("%s: `buffers[i]` must be NONE or COLOR_ATTACHMENTi.",
funcName);
return;
}
}
MakeContextCurrent();
const GLenum* ptr = nullptr;
if (buffers.Length()) {
ptr = buffers.Elements();
}
gl->fDrawBuffers(buffers.Length(), ptr);
const auto end = ptr + buffers.Length();
mBoundDrawFramebuffer->mDrawBuffers.assign(ptr, end);
}
void
WebGLContext::StencilMask(GLuint mask)
{
if (IsContextLost())
return;
mStencilWriteMaskFront = mask;
mStencilWriteMaskBack = mask;
MakeContextCurrent();
gl->fStencilMask(mask);
}
void
WebGLContext::StencilMaskSeparate(GLenum face, GLuint mask)
{
if (IsContextLost())
return;
if (!ValidateFaceEnum(face, "stencilMaskSeparate: face"))
return;
switch (face) {
case LOCAL_GL_FRONT_AND_BACK:
mStencilWriteMaskFront = mask;
mStencilWriteMaskBack = mask;
break;
case LOCAL_GL_FRONT:
mStencilWriteMaskFront = mask;
break;
case LOCAL_GL_BACK:
mStencilWriteMaskBack = mask;
break;
}
MakeContextCurrent();
gl->fStencilMaskSeparate(face, mask);
}
} // namespace mozilla