Avoid deleting two times the direct SkSurface

This commit is contained in:
David Capello 2016-02-05 16:34:02 -03:00
parent 9c653ef86e
commit 87e5be45a9
2 changed files with 16 additions and 5 deletions

View File

@ -39,6 +39,7 @@ SkiaWindow::SkiaWindow(EventQueue* queue, SkiaDisplay* display,
, m_display(display) , m_display(display)
, m_backend(Backend::NONE) , m_backend(Backend::NONE)
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
, m_skSurface(nullptr)
, m_sampleCount(0) , m_sampleCount(0)
, m_stencilBits(0) , m_stencilBits(0)
#endif #endif
@ -191,8 +192,8 @@ void SkiaWindow::detachGL()
if (m_glCtx && m_display) if (m_glCtx && m_display)
m_display->resetSkiaSurface(); m_display->resetSkiaSurface();
setSurface(nullptr);
m_skSurfaceDirect.reset(nullptr); m_skSurfaceDirect.reset(nullptr);
m_skSurface.reset(nullptr);
m_grRenderTarget.reset(nullptr); m_grRenderTarget.reset(nullptr);
m_grCtx.reset(nullptr); m_grCtx.reset(nullptr);
m_glCtx.reset(nullptr); m_glCtx.reset(nullptr);
@ -212,14 +213,16 @@ void SkiaWindow::createRenderTarget(const gfx::Size& size)
desc.fStencilBits = m_stencilBits; desc.fStencilBits = m_stencilBits;
desc.fRenderTargetHandle = 0; // direct frame buffer desc.fRenderTargetHandle = 0; // direct frame buffer
m_grRenderTarget.reset(m_grCtx->textureProvider()->wrapBackendRenderTarget(desc)); m_grRenderTarget.reset(m_grCtx->textureProvider()->wrapBackendRenderTarget(desc));
setSurface(nullptr); // set m_skSurface comparing with the old m_skSurfaceDirect
m_skSurfaceDirect.reset( m_skSurfaceDirect.reset(
SkSurface::NewRenderTargetDirect(m_grRenderTarget)); SkSurface::NewRenderTargetDirect(m_grRenderTarget));
if (scale == 1) { if (scale == 1) {
m_skSurface.reset(m_skSurfaceDirect); setSurface(m_skSurfaceDirect);
} }
else { else {
m_skSurface.reset( setSurface(
SkSurface::NewRenderTarget( SkSurface::NewRenderTarget(
m_grCtx, m_grCtx,
SkSurface::kYes_Budgeted, SkSurface::kYes_Budgeted,
@ -234,6 +237,13 @@ void SkiaWindow::createRenderTarget(const gfx::Size& size)
m_display->setSkiaSurface(new SkiaSurface(m_skSurface)); m_display->setSkiaSurface(new SkiaSurface(m_skSurface));
} }
void SkiaWindow::setSurface(SkSurface* surface)
{
if (m_skSurface && m_skSurface != m_skSurfaceDirect)
delete m_skSurface;
m_skSurface = surface;
}
#endif // SK_SUPPORT_GPU #endif // SK_SUPPORT_GPU
void SkiaWindow::resizeImpl(const gfx::Size& size) void SkiaWindow::resizeImpl(const gfx::Size& size)

View File

@ -1,5 +1,5 @@
// SHE library // SHE library
// Copyright (C) 2012-2015 David Capello // Copyright (C) 2012-2016 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information. // Read LICENSE.txt for more information.
@ -45,6 +45,7 @@ private:
#endif // SK_ANGLE #endif // SK_ANGLE
void detachGL(); void detachGL();
void createRenderTarget(const gfx::Size& size); void createRenderTarget(const gfx::Size& size);
void setSurface(SkSurface* surface);
#endif // SK_SUPPORT_GPU #endif // SK_SUPPORT_GPU
EventQueue* m_queue; EventQueue* m_queue;
@ -55,7 +56,7 @@ private:
SkAutoTUnref<GrContext> m_grCtx; SkAutoTUnref<GrContext> m_grCtx;
SkAutoTUnref<GrRenderTarget> m_grRenderTarget; SkAutoTUnref<GrRenderTarget> m_grRenderTarget;
SkAutoTDelete<SkSurface> m_skSurfaceDirect; SkAutoTDelete<SkSurface> m_skSurfaceDirect;
SkAutoTDelete<SkSurface> m_skSurface; SkSurface* m_skSurface;
int m_sampleCount; int m_sampleCount;
int m_stencilBits; int m_stencilBits;
gfx::Size m_lastSize; gfx::Size m_lastSize;