Bug 1794956 - TransferToImageBitmap should reset bitmap but not state. r=gfx-reviewers,lsalzman

s/Reset/ResetBitmap/ and implement for WebGL and WebGPU.

Differential Revision: https://phabricator.services.mozilla.com/D159346
This commit is contained in:
Kelsey Gilbert 2022-10-15 09:01:46 +00:00
Родитель 62ca596efe
Коммит 4253cbe5b3
10 изменённых файлов: 23 добавлений и 29 удалений

Просмотреть файл

@ -1073,7 +1073,7 @@ CanvasRenderingContext2D::CanvasRenderingContext2D(
CanvasRenderingContext2D::~CanvasRenderingContext2D() {
RemovePostRefreshObserver();
RemoveShutdownObserver();
Reset();
ResetBitmap();
sNumLivingContexts.set(sNumLivingContexts.get() - 1);
if (sNumLivingContexts.get() == 0 && sErrorTarget.get()) {
@ -1117,7 +1117,7 @@ bool CanvasRenderingContext2D::ParseColor(const nsACString& aString,
return true;
}
nsresult CanvasRenderingContext2D::Reset() {
void CanvasRenderingContext2D::ResetBitmap() {
if (mCanvasElement) {
mCanvasElement->InvalidateCanvas();
}
@ -1138,8 +1138,6 @@ nsresult CanvasRenderingContext2D::Reset() {
mIsEntireFrameInvalid = false;
mPredictManyRedrawCalls = false;
mFrameCaptureState = FrameCaptureState::CLEAN;
return NS_OK;
}
void CanvasRenderingContext2D::OnShutdown() {
@ -1147,7 +1145,7 @@ void CanvasRenderingContext2D::OnShutdown() {
RefPtr<PersistentBufferProvider> provider = mBufferProvider;
Reset();
ResetBitmap();
if (provider) {
provider->OnShutdown();
@ -1652,7 +1650,7 @@ void CanvasRenderingContext2D::RemoveAssociatedMemory() {
}
void CanvasRenderingContext2D::ClearTarget(int32_t aWidth, int32_t aHeight) {
Reset();
ResetBitmap();
mResetLayer = true;

Просмотреть файл

@ -445,7 +445,7 @@ class CanvasRenderingContext2D : public nsICanvasRenderingContextInternal,
virtual void SetOpaqueValueFromOpaqueAttr(bool aOpaqueAttrValue) override;
bool GetIsOpaque() override { return mOpaque; }
NS_IMETHOD Reset() override;
void ResetBitmap() override;
bool UpdateWebRenderCanvasData(nsDisplayListBuilder* aBuilder,
WebRenderCanvasData* aCanvasData) override;

Просмотреть файл

@ -685,6 +685,11 @@ ClientWebGLContext::SetDimensions(const int32_t signedWidth,
return NS_OK;
}
void ClientWebGLContext::ResetBitmap() {
const auto size = DrawingBufferSize();
Run<RPROC(Resize)>(size); // No-change resize still clears/resets everything.
}
static bool IsWebglOutOfProcessEnabled() {
if (StaticPrefs::webgl_out_of_process_force()) {
return true;

Просмотреть файл

@ -962,10 +962,7 @@ class ClientWebGLContext final : public nsICanvasRenderingContextInternal,
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHOD Reset() override {
/* (InitializeWithSurface) */
return NS_ERROR_NOT_IMPLEMENTED;
}
void ResetBitmap() override;
UniquePtr<uint8_t[]> GetImageBuffer(int32_t* out_format) override;
NS_IMETHOD GetInputStream(const char* mimeType,

Просмотреть файл

@ -69,7 +69,7 @@ void ImageBitmapRenderingContext::TransferImageBitmap(
void ImageBitmapRenderingContext::TransferFromImageBitmap(
ImageBitmap* aImageBitmap) {
Reset();
ResetBitmap();
if (aImageBitmap) {
mImage = aImageBitmap->TransferAsImage();
@ -216,15 +216,13 @@ void ImageBitmapRenderingContext::SetOpaqueValueFromOpaqueAttr(
bool ImageBitmapRenderingContext::GetIsOpaque() { return false; }
NS_IMETHODIMP
ImageBitmapRenderingContext::Reset() {
void ImageBitmapRenderingContext::ResetBitmap() {
if (mCanvasElement) {
mCanvasElement->InvalidateCanvas();
}
mImage = nullptr;
mFrameCaptureState = FrameCaptureState::CLEAN;
return NS_OK;
}
bool ImageBitmapRenderingContext::UpdateWebRenderCanvasData(

Просмотреть файл

@ -80,7 +80,7 @@ class ImageBitmapRenderingContext final
virtual void SetOpaqueValueFromOpaqueAttr(bool aOpaqueAttrValue) override;
virtual bool GetIsOpaque() override;
NS_IMETHOD Reset() override;
void ResetBitmap() override;
virtual already_AddRefed<layers::Image> GetAsImage() override {
return ClipToIntrinsicSize();
}

Просмотреть файл

@ -259,17 +259,12 @@ already_AddRefed<ImageBitmap> OffscreenCanvas::TransferToImageBitmap(
RefPtr<ImageBitmap> result =
ImageBitmap::CreateFromOffscreenCanvas(GetOwnerGlobal(), *this, aRv);
if (aRv.Failed()) {
if (!result) {
return nullptr;
}
if (result && mCurrentContext) {
// FIXME(aosmond): The spec is unclear about the state of the canvas after
// clearing. Does it expect to preserve the WebGL state, other than the
// buffer state? Once we have clarity, we should ensure we clear the WebGL
// canvas as desired.
mCurrentContext->Reset();
mCurrentContext->SetDimensions(result->Width(), result->Height());
if (mCurrentContext) {
mCurrentContext->ResetBitmap();
}
return result.forget();
}

Просмотреть файл

@ -142,9 +142,8 @@ class nsICanvasRenderingContextInternal : public nsISupports,
// attributes.
virtual bool GetIsOpaque() = 0;
// Invalidate this context and release any held resources, in preperation
// for possibly reinitializing with SetDimensions/InitializeWithSurface.
NS_IMETHOD Reset() = 0;
// Clear and/or release backing bitmaps, such as for transferToImageBitmap.
virtual void ResetBitmap() = 0;
virtual already_AddRefed<mozilla::layers::Image> GetAsImage() {
return nullptr;

Просмотреть файл

@ -1339,7 +1339,7 @@ void HTMLCanvasElement::OnMemoryPressure() {
void HTMLCanvasElement::OnDeviceReset() {
if (!mOffscreenCanvas && mCurrentContext) {
mCurrentContext->Reset();
mCurrentContext->ResetBitmap();
}
}

Просмотреть файл

@ -65,7 +65,9 @@ class CanvasContext final : public nsICanvasRenderingContextInternal,
void SetOpaqueValueFromOpaqueAttr(bool aOpaqueAttrValue) override {}
bool GetIsOpaque() override { return true; }
NS_IMETHOD Reset() override { return NS_OK; }
void ResetBitmap() override { Unconfigure(); }
void MarkContextClean() override {}
NS_IMETHOD Redraw(const gfxRect& aDirty) override { return NS_OK; }