Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit df8e8db

Browse files
committed
Bug 1427668 - Move the webgl backbuffer into webgl. - r=daoshengmu
MozReview-Commit-ID: 2WpG7mfMRQ8
1 parent 3f0aacf commit df8e8db

20 files changed

Lines changed: 514 additions & 565 deletions

dom/canvas/OffscreenCanvas.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,7 @@ OffscreenCanvas::TransferToImageBitmap(ErrorResult& aRv)
225225
return nullptr;
226226
}
227227

228-
// Clear the content.
229-
if ((mCurrentContextType == CanvasContextType::WebGL1 ||
230-
mCurrentContextType == CanvasContextType::WebGL2))
231-
{
232-
WebGLContext* webGL = static_cast<WebGLContext*>(mCurrentContext.get());
233-
webGL->ClearScreen();
234-
}
235-
228+
// TODO: Clear the content?
236229
return result.forget();
237230
}
238231

dom/canvas/WebGL2ContextFramebuffers.cpp

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,18 @@ WebGL2Context::BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY
4040

4141
////
4242

43-
const auto& readFB = mBoundReadFramebuffer;
44-
if (readFB &&
45-
!readFB->ValidateAndInitAttachments("blitFramebuffer's READ_FRAMEBUFFER"))
43+
if (!ValidateAndInitFB("blitFramebuffer: READ_FRAMEBUFFER", mBoundReadFramebuffer) ||
44+
!ValidateAndInitFB("blitFramebuffer: DRAW_FRAMEBUFFER", mBoundDrawFramebuffer))
4645
{
4746
return;
4847
}
4948

50-
const auto& drawFB = mBoundDrawFramebuffer;
51-
if (drawFB &&
52-
!drawFB->ValidateAndInitAttachments("blitFramebuffer's DRAW_FRAMEBUFFER"))
53-
{
54-
return;
55-
}
56-
57-
////
58-
59-
if (!mBoundReadFramebuffer) {
60-
ClearBackbufferIfNeeded();
61-
}
49+
DoBindFB(mBoundReadFramebuffer, LOCAL_GL_READ_FRAMEBUFFER);
50+
DoBindFB(mBoundDrawFramebuffer, LOCAL_GL_DRAW_FRAMEBUFFER);
6251

6352
WebGLFramebuffer::BlitFramebuffer(this,
64-
readFB, srcX0, srcY0, srcX1, srcY1,
65-
drawFB, dstX0, dstY0, dstX1, dstY1,
53+
srcX0, srcY0, srcX1, srcY1,
54+
dstX0, dstY0, dstX1, dstY1,
6655
mask, filter);
6756
}
6857

@@ -170,23 +159,25 @@ WebGLContext::ValidateInvalidateFramebuffer(const char* funcName, GLenum target,
170159
return false;
171160

172161
const WebGLFramebuffer* fb;
173-
bool isDefaultFB;
162+
bool isDefaultFB = false;
174163
switch (target) {
175164
case LOCAL_GL_FRAMEBUFFER:
176165
case LOCAL_GL_DRAW_FRAMEBUFFER:
177166
fb = mBoundDrawFramebuffer;
178-
isDefaultFB = gl->Screen()->IsDrawFramebufferDefault();
179167
break;
180168

181169
case LOCAL_GL_READ_FRAMEBUFFER:
182170
fb = mBoundReadFramebuffer;
183-
isDefaultFB = gl->Screen()->IsReadFramebufferDefault();
184171
break;
185172

186173
default:
187174
MOZ_CRASH("GFX: Bad target.");
188175
}
189176

177+
if (!ValidateAndInitFB(funcName, fb))
178+
return false;
179+
DoBindFB(fb, target);
180+
190181
*out_glNumAttachments = attachments.Length();
191182
*out_glAttachments = attachments.Elements();
192183

@@ -230,13 +221,9 @@ WebGLContext::ValidateInvalidateFramebuffer(const char* funcName, GLenum target,
230221
////
231222

232223
if (!fb) {
233-
ClearBackbufferIfNeeded();
234-
235-
// Don't do more validation after these.
236-
Invalidate();
237-
mShouldPresent = true;
224+
mDefaultFB_IsInvalid = true;
225+
mResolvedDefaultFB = nullptr;
238226
}
239-
240227
return true;
241228
}
242229

@@ -331,7 +318,7 @@ WebGL2Context::ReadBuffer(GLenum mode)
331318
return;
332319
}
333320

334-
gl->Screen()->SetReadBuffer(mode);
321+
mDefaultFB_ReadBuffer = mode;
335322
}
336323

337324
} // namespace mozilla

dom/canvas/WebGL2ContextMRTs.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ WebGL2Context::ValidateClearBuffer(const char* funcName, GLenum buffer, GLint dr
6262

6363
////
6464

65+
if (!BindCurFBForDraw(funcName))
66+
return false;
67+
6568
const auto& fb = mBoundDrawFramebuffer;
6669
if (fb) {
67-
if (!fb->ValidateAndInitAttachments(funcName))
68-
return false;
69-
7070
if (!fb->ValidateClearBufferType(funcName, buffer, drawBuffer, funcType))
7171
return false;
7272
} else if (buffer == LOCAL_GL_COLOR) {
@@ -110,6 +110,13 @@ WebGL2Context::ClearBufferfv(GLenum buffer, GLint drawBuffer, const Float32Arr&
110110
return;
111111
}
112112

113+
if (!mBoundDrawFramebuffer &&
114+
buffer == LOCAL_GL_DEPTH &&
115+
mNeedsFakeNoDepth)
116+
{
117+
return;
118+
}
119+
113120
ScopedDrawCallWrapper wrapper(*this);
114121
const auto ptr = src.elemBytes + srcElemOffset;
115122
gl->fClearBufferfv(buffer, drawBuffer, ptr);
@@ -136,6 +143,13 @@ WebGL2Context::ClearBufferiv(GLenum buffer, GLint drawBuffer, const Int32Arr& sr
136143
return;
137144
}
138145

146+
if (!mBoundDrawFramebuffer &&
147+
buffer == LOCAL_GL_STENCIL &&
148+
mNeedsFakeNoStencil)
149+
{
150+
return;
151+
}
152+
139153
ScopedDrawCallWrapper wrapper(*this);
140154
const auto ptr = src.elemBytes + srcElemOffset;
141155
gl->fClearBufferiv(buffer, drawBuffer, ptr);
@@ -179,8 +193,18 @@ WebGL2Context::ClearBufferfi(GLenum buffer, GLint drawBuffer, GLfloat depth,
179193
if (!ValidateClearBuffer(funcName, buffer, drawBuffer, 2, 0, 0))
180194
return;
181195

196+
auto driverDepth = depth;
197+
auto driverStencil = stencil;
198+
if (!mBoundDrawFramebuffer) {
199+
if (mNeedsFakeNoDepth) {
200+
driverDepth = 1.0f;
201+
} else if (mNeedsFakeNoStencil) {
202+
driverStencil = 0;
203+
}
204+
}
205+
182206
ScopedDrawCallWrapper wrapper(*this);
183-
gl->fClearBufferfi(buffer, drawBuffer, depth, stencil);
207+
gl->fClearBufferfi(buffer, drawBuffer, driverDepth, driverStencil);
184208
}
185209

186210
} // namespace mozilla

dom/canvas/WebGL2ContextState.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ WebGL2Context::GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv)
4545
/* GLenum */
4646
case LOCAL_GL_READ_BUFFER: {
4747
if (!mBoundReadFramebuffer)
48-
return JS::Int32Value(gl->Screen()->GetReadBufferMode());
48+
return JS::Int32Value(mDefaultFB_ReadBuffer);
4949

5050
if (!mBoundReadFramebuffer->ColorReadBuffer())
5151
return JS::Int32Value(LOCAL_GL_NONE);

0 commit comments

Comments
 (0)