Commit e62489f3 by Jamie Madill Committed by Commit Bot

Surface: Use ref count for bindTexImage.

This frees up one more use of ProxyContext. It will also keep the bound surface alive until it is unbound from a Texture. Two usages of the proxy context remains. * DisplayD3D::restoreLostDevice. * Display::destroyImage. Bug: angleproject:2714 Change-Id: Ied72c6ebe060d7fc1743b3313e162d540fcbfe02 Reviewed-on: https://chromium-review.googlesource.com/1137878 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 80d4ef10
......@@ -36,7 +36,7 @@ Surface::Surface(EGLint surfaceType,
: FramebufferAttachmentObject(),
mState(config, attributes),
mImplementation(nullptr),
mCurrentCount(0),
mRefCount(0),
mDestroyed(false),
mType(surfaceType),
mBuftype(buftype),
......@@ -123,20 +123,7 @@ Error Surface::destroyImpl(const Display *display)
mImplementation->destroy(display);
}
if (mTexture)
{
gl::Context *context = display->getProxyContext();
if (mImplementation)
{
ANGLE_TRY(mImplementation->releaseTexImage(context, EGL_BACK_BUFFER));
}
auto glErr = mTexture->releaseTexImageFromSurface(context);
if (glErr.isError())
{
return Error(EGL_BAD_SURFACE);
}
mTexture = nullptr;
}
ASSERT(!mTexture);
SafeDelete(mImplementation);
......@@ -188,24 +175,30 @@ Error Surface::setIsCurrent(const gl::Context *context, bool isCurrent)
{
if (isCurrent)
{
mCurrentCount++;
mRefCount++;
return NoError();
}
ASSERT(mCurrentCount > 0);
mCurrentCount--;
if (mCurrentCount == 0 && mDestroyed)
return releaseRef(context->getCurrentDisplay());
}
Error Surface::releaseRef(const Display *display)
{
ASSERT(mRefCount > 0);
mRefCount--;
if (mRefCount == 0 && mDestroyed)
{
ASSERT(context);
return destroyImpl(context->getCurrentDisplay());
ASSERT(display);
return destroyImpl(display);
}
return NoError();
}
Error Surface::onDestroy(const Display *display)
{
mDestroyed = true;
if (mCurrentCount == 0)
if (mRefCount == 0)
{
return destroyImpl(display);
}
......@@ -397,6 +390,7 @@ Error Surface::bindTexImage(const gl::Context *context, gl::Texture *texture, EG
return Error(EGL_BAD_SURFACE);
}
mTexture = texture;
mRefCount++;
return NoError();
}
......@@ -413,9 +407,8 @@ Error Surface::releaseTexImage(const gl::Context *context, EGLint buffer)
{
return Error(EGL_BAD_SURFACE);
}
mTexture = nullptr;
return NoError();
return releaseTexImageFromTexture(context);
}
Error Surface::getSyncValues(EGLuint64KHR *ust, EGLuint64KHR *msc, EGLuint64KHR *sbc)
......@@ -423,10 +416,11 @@ Error Surface::getSyncValues(EGLuint64KHR *ust, EGLuint64KHR *msc, EGLuint64KHR
return mImplementation->getSyncValues(ust, msc, sbc);
}
void Surface::releaseTexImageFromTexture(const gl::Context *context)
Error Surface::releaseTexImageFromTexture(const gl::Context *context)
{
ASSERT(mTexture);
mTexture = nullptr;
return releaseRef(context->getCurrentDisplay());
}
gl::Extents Surface::getAttachmentSize(const gl::ImageIndex & /*target*/) const
......
......@@ -146,11 +146,11 @@ class Surface : public LabeledObject, public gl::FramebufferAttachmentObject
// ANGLE-only method, used internally
friend class gl::Texture;
void releaseTexImageFromTexture(const gl::Context *context);
Error releaseTexImageFromTexture(const gl::Context *context);
SurfaceState mState;
rx::SurfaceImpl *mImplementation;
int mCurrentCount;
int mRefCount;
bool mDestroyed;
EGLint mType;
......@@ -197,6 +197,7 @@ class Surface : public LabeledObject, public gl::FramebufferAttachmentObject
Error destroyImpl(const Display *display);
void postSwap(const gl::Context *context);
Error releaseRef(const Display *display);
gl::InitState mInitState;
};
......
......@@ -1372,7 +1372,7 @@ Error Texture::releaseTexImageInternal(const Context *context)
if (mBoundSurface)
{
// Notify the surface
mBoundSurface->releaseTexImageFromTexture(context);
ANGLE_TRY(mBoundSurface->releaseTexImageFromTexture(context));
// Then, call the same method as from the surface
ANGLE_TRY(releaseTexImageFromSurface(context));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment