mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 06:43:32 +00:00
Bug 1609006 - 0x0 canvas yields 1x1 webgl context. r=lsalzman
Also, always resize, not just on change. (As per spec) Differential Revision: https://phabricator.services.mozilla.com/D59967 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
54fa076525
commit
2c2c0487c0
@ -254,7 +254,8 @@ void ClientWebGLContext::Event_webglcontextrestored() {
|
||||
mLossStatus = webgl::LossStatus::Ready;
|
||||
mNextError = 0;
|
||||
|
||||
if (!CreateHostContext()) {
|
||||
const uvec2 requestSize = {mCanvasElement->Width(), mCanvasElement->Height()};
|
||||
if (!CreateHostContext(requestSize)) {
|
||||
mLossStatus = webgl::LossStatus::LostForever;
|
||||
return;
|
||||
}
|
||||
@ -637,25 +638,29 @@ void ClientWebGLContext::GetContextAttributes(
|
||||
// -----------------------
|
||||
|
||||
NS_IMETHODIMP
|
||||
ClientWebGLContext::SetDimensions(int32_t signedWidth, int32_t signedHeight) {
|
||||
ClientWebGLContext::SetDimensions(const int32_t signedWidth,
|
||||
const int32_t signedHeight) {
|
||||
const FuncScope funcScope(*this, "<SetDimensions>");
|
||||
WEBGL_BRIDGE_LOGI("[%p] SetDimensions: (%d, %d)", this, signedWidth,
|
||||
signedHeight);
|
||||
|
||||
MOZ_ASSERT(mInitialOptions);
|
||||
|
||||
const auto size = uvec2::From(signedWidth, signedHeight);
|
||||
if (!size) {
|
||||
EnqueueWarning(
|
||||
"Canvas size is too large (seems like a negative value wrapped)");
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
uvec2 size = {static_cast<uint32_t>(signedWidth),
|
||||
static_cast<uint32_t>(signedHeight)};
|
||||
if (!size.x) {
|
||||
size.x = 1;
|
||||
}
|
||||
if (!size.y) {
|
||||
size.y = 1;
|
||||
}
|
||||
if (*size == mRequestedSize) return NS_OK;
|
||||
mRequestedSize = *size;
|
||||
mDrawingBufferSize = {};
|
||||
|
||||
if (mNotLost) {
|
||||
Run<RPROC(Resize)>(*size);
|
||||
auto& state = State();
|
||||
state.mDrawingBufferSize = {};
|
||||
|
||||
Run<RPROC(Resize)>(size);
|
||||
|
||||
MarkCanvasDirty();
|
||||
return NS_OK;
|
||||
}
|
||||
@ -668,13 +673,13 @@ ClientWebGLContext::SetDimensions(int32_t signedWidth, int32_t signedHeight) {
|
||||
// -
|
||||
// Context (re-)creation
|
||||
|
||||
if (!CreateHostContext()) {
|
||||
if (!CreateHostContext(size)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool ClientWebGLContext::CreateHostContext() {
|
||||
bool ClientWebGLContext::CreateHostContext(const uvec2& requestedSize) {
|
||||
const auto pNotLost = std::make_shared<webgl::NotLostData>(*this);
|
||||
auto& notLost = *pNotLost;
|
||||
|
||||
@ -688,7 +693,7 @@ bool ClientWebGLContext::CreateHostContext() {
|
||||
const auto& principal = GetCanvas()->NodePrincipal();
|
||||
const auto principalKey = principal->GetHashValue();
|
||||
const auto initDesc = webgl::InitContextDesc{
|
||||
mIsWebGL2, resistFingerprinting, mRequestedSize, options, principalKey};
|
||||
mIsWebGL2, resistFingerprinting, requestedSize, options, principalKey};
|
||||
|
||||
// -
|
||||
|
||||
@ -796,12 +801,15 @@ bool ClientWebGLContext::CreateHostContext() {
|
||||
|
||||
// -------
|
||||
|
||||
const uvec2& ClientWebGLContext::DrawingBufferSize() {
|
||||
if (!mDrawingBufferSize) {
|
||||
mDrawingBufferSize = Some(Run<RPROC(DrawingBufferSize)>());
|
||||
uvec2 ClientWebGLContext::DrawingBufferSize() {
|
||||
if (IsContextLost()) return {};
|
||||
auto& state = State();
|
||||
auto& size = state.mDrawingBufferSize;
|
||||
if (!size) {
|
||||
size = Some(Run<RPROC(DrawingBufferSize)>());
|
||||
}
|
||||
|
||||
return *mDrawingBufferSize;
|
||||
return *size;
|
||||
}
|
||||
|
||||
void ClientWebGLContext::OnMemoryPressure() {
|
||||
|
@ -180,9 +180,7 @@ class ContextGenerationInfo final {
|
||||
|
||||
std::vector<GLenum> mCompressedTextureFormats;
|
||||
|
||||
public:
|
||||
// explicit ContextGenerationInfo(ClientWebGLContext& context);
|
||||
//~ContextGenerationInfo();
|
||||
Maybe<uvec2> mDrawingBufferSize;
|
||||
|
||||
ObjectId NextId() { return mLastId += 1; }
|
||||
};
|
||||
@ -727,8 +725,6 @@ class ClientWebGLContext final : public nsICanvasRenderingContextInternal,
|
||||
private:
|
||||
virtual ~ClientWebGLContext();
|
||||
|
||||
uvec2 mRequestedSize;
|
||||
Maybe<uvec2> mDrawingBufferSize;
|
||||
const RefPtr<ClientWebGLExtensionLoseContext> mExtLoseContext;
|
||||
|
||||
webgl::LossStatus mLossStatus = webgl::LossStatus::Ready;
|
||||
@ -759,7 +755,7 @@ class ClientWebGLContext final : public nsICanvasRenderingContextInternal,
|
||||
void Event_webglcontextlost();
|
||||
void Event_webglcontextrestored();
|
||||
|
||||
bool CreateHostContext();
|
||||
bool CreateHostContext(const uvec2& requestedSize);
|
||||
void ThrowEvent_WebGLContextCreationError(const std::string&) const;
|
||||
|
||||
public:
|
||||
@ -987,7 +983,7 @@ class ClientWebGLContext final : public nsICanvasRenderingContextInternal,
|
||||
void ClearVRFrame() const;
|
||||
|
||||
private:
|
||||
const uvec2& DrawingBufferSize();
|
||||
uvec2 DrawingBufferSize();
|
||||
bool HasAlphaSupport() { return mSurfaceInfo.supportsAlpha; }
|
||||
|
||||
ICRData mSurfaceInfo;
|
||||
|
Loading…
Reference in New Issue
Block a user