Bug 1936278 - Prevent search mode chiclet from being dismissed when clicking in page...
[gecko.git] / dom / canvas / WebGL2ContextMRTs.cpp
blob544f8e024a2dc6074f060f399c6d2fecc7b93e71
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "WebGL2Context.h"
8 #include "GLContext.h"
9 #include "WebGLFramebuffer.h"
11 namespace mozilla {
13 bool WebGL2Context::ValidateClearBuffer(const GLenum buffer,
14 const GLint drawBuffer,
15 const webgl::AttribBaseType funcType) {
16 GLint maxDrawBuffer;
17 switch (buffer) {
18 case LOCAL_GL_COLOR:
19 maxDrawBuffer = Limits().maxColorDrawBuffers - 1;
20 break;
22 case LOCAL_GL_DEPTH:
23 case LOCAL_GL_STENCIL:
24 maxDrawBuffer = 0;
25 break;
27 case LOCAL_GL_DEPTH_STENCIL:
28 maxDrawBuffer = 0;
29 break;
31 default:
32 ErrorInvalidEnumInfo("buffer", buffer);
33 return false;
36 if (drawBuffer < 0 || drawBuffer > maxDrawBuffer) {
37 ErrorInvalidValue(
38 "Invalid drawbuffer %d. This buffer only supports"
39 " `drawbuffer` values between 0 and %u.",
40 drawBuffer, maxDrawBuffer);
41 return false;
44 ////
46 if (!BindCurFBForDraw()) return false;
48 const auto& fb = mBoundDrawFramebuffer;
49 if (fb) {
50 if (!fb->ValidateClearBufferType(buffer, drawBuffer, funcType))
51 return false;
52 } else if (buffer == LOCAL_GL_COLOR) {
53 if (drawBuffer != 0) return true;
55 if (mDefaultFB_DrawBuffer0 == LOCAL_GL_NONE) return true;
57 if (funcType != webgl::AttribBaseType::Float) {
58 ErrorInvalidOperation(
59 "For default framebuffer, COLOR is always of type"
60 " FLOAT.");
61 return false;
65 return true;
68 ////
70 void WebGL2Context::ClearBufferTv(GLenum buffer, GLint drawBuffer,
71 const webgl::TypedQuad& data) {
72 const FuncScope funcScope(*this, "clearBufferu?[fi]v");
73 if (IsContextLost()) return;
75 switch (data.type) {
76 case webgl::AttribBaseType::Boolean:
77 MOZ_ASSERT(false);
78 return;
80 case webgl::AttribBaseType::Float:
81 if (buffer != LOCAL_GL_COLOR && buffer != LOCAL_GL_DEPTH) {
82 ErrorInvalidEnum("`buffer` must be COLOR or DEPTH.");
83 return;
85 break;
87 case webgl::AttribBaseType::Int:
88 if (buffer != LOCAL_GL_COLOR && buffer != LOCAL_GL_STENCIL) {
89 ErrorInvalidEnum("`buffer` must be COLOR or STENCIL.");
90 return;
92 break;
94 case webgl::AttribBaseType::Uint:
95 if (buffer != LOCAL_GL_COLOR) {
96 ErrorInvalidEnum("`buffer` must be COLOR.");
97 return;
99 break;
102 if (!ValidateClearBuffer(buffer, drawBuffer, data.type)) {
103 return;
106 if (!mBoundDrawFramebuffer && buffer == LOCAL_GL_DEPTH && mNeedsFakeNoDepth) {
107 return;
109 if (!mBoundDrawFramebuffer && buffer == LOCAL_GL_STENCIL &&
110 mNeedsFakeNoStencil) {
111 return;
114 ScopedDrawCallWrapper wrapper(*this);
115 switch (data.type) {
116 case webgl::AttribBaseType::Boolean:
117 MOZ_ASSERT(false);
118 return;
120 case webgl::AttribBaseType::Float:
121 gl->fClearBufferfv(buffer, drawBuffer,
122 reinterpret_cast<const float*>(data.data.data()));
123 break;
125 case webgl::AttribBaseType::Int:
126 gl->fClearBufferiv(buffer, drawBuffer,
127 reinterpret_cast<const int32_t*>(data.data.data()));
128 break;
130 case webgl::AttribBaseType::Uint:
131 gl->fClearBufferuiv(buffer, drawBuffer,
132 reinterpret_cast<const uint32_t*>(data.data.data()));
133 break;
137 ////
139 void WebGL2Context::ClearBufferfi(GLenum buffer, GLint drawBuffer,
140 GLfloat depth, GLint stencil) {
141 const FuncScope funcScope(*this, "clearBufferfi");
142 if (IsContextLost()) return;
144 if (buffer != LOCAL_GL_DEPTH_STENCIL)
145 return ErrorInvalidEnum("`buffer` must be DEPTH_STENCIL.");
147 const auto ignored = webgl::AttribBaseType::Float;
148 if (!ValidateClearBuffer(buffer, drawBuffer, ignored)) return;
150 auto driverDepth = depth;
151 auto driverStencil = stencil;
152 if (!mBoundDrawFramebuffer) {
153 if (mNeedsFakeNoDepth) {
154 driverDepth = 1.0f;
155 } else if (mNeedsFakeNoStencil) {
156 driverStencil = 0;
160 ScopedDrawCallWrapper wrapper(*this);
161 gl->fClearBufferfi(buffer, drawBuffer, driverDepth, driverStencil);
164 } // namespace mozilla