From 87e5be45a91a4d3b63957167d4ff3a7e1f402638 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 5 Feb 2016 16:34:02 -0300 Subject: [PATCH] Avoid deleting two times the direct SkSurface --- src/she/skia/skia_window_win.cpp | 16 +++++++++++++--- src/she/skia/skia_window_win.h | 5 +++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/she/skia/skia_window_win.cpp b/src/she/skia/skia_window_win.cpp index f5df7fac3..544f27be3 100644 --- a/src/she/skia/skia_window_win.cpp +++ b/src/she/skia/skia_window_win.cpp @@ -39,6 +39,7 @@ SkiaWindow::SkiaWindow(EventQueue* queue, SkiaDisplay* display, , m_display(display) , m_backend(Backend::NONE) #if SK_SUPPORT_GPU + , m_skSurface(nullptr) , m_sampleCount(0) , m_stencilBits(0) #endif @@ -191,8 +192,8 @@ void SkiaWindow::detachGL() if (m_glCtx && m_display) m_display->resetSkiaSurface(); + setSurface(nullptr); m_skSurfaceDirect.reset(nullptr); - m_skSurface.reset(nullptr); m_grRenderTarget.reset(nullptr); m_grCtx.reset(nullptr); m_glCtx.reset(nullptr); @@ -212,14 +213,16 @@ void SkiaWindow::createRenderTarget(const gfx::Size& size) desc.fStencilBits = m_stencilBits; desc.fRenderTargetHandle = 0; // direct frame buffer m_grRenderTarget.reset(m_grCtx->textureProvider()->wrapBackendRenderTarget(desc)); + + setSurface(nullptr); // set m_skSurface comparing with the old m_skSurfaceDirect m_skSurfaceDirect.reset( SkSurface::NewRenderTargetDirect(m_grRenderTarget)); if (scale == 1) { - m_skSurface.reset(m_skSurfaceDirect); + setSurface(m_skSurfaceDirect); } else { - m_skSurface.reset( + setSurface( SkSurface::NewRenderTarget( m_grCtx, SkSurface::kYes_Budgeted, @@ -234,6 +237,13 @@ void SkiaWindow::createRenderTarget(const gfx::Size& size) 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 void SkiaWindow::resizeImpl(const gfx::Size& size) diff --git a/src/she/skia/skia_window_win.h b/src/she/skia/skia_window_win.h index 79470be4a..34e9c0d21 100644 --- a/src/she/skia/skia_window_win.h +++ b/src/she/skia/skia_window_win.h @@ -1,5 +1,5 @@ // 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. // Read LICENSE.txt for more information. @@ -45,6 +45,7 @@ private: #endif // SK_ANGLE void detachGL(); void createRenderTarget(const gfx::Size& size); + void setSurface(SkSurface* surface); #endif // SK_SUPPORT_GPU EventQueue* m_queue; @@ -55,7 +56,7 @@ private: SkAutoTUnref m_grCtx; SkAutoTUnref m_grRenderTarget; SkAutoTDelete m_skSurfaceDirect; - SkAutoTDelete m_skSurface; + SkSurface* m_skSurface; int m_sampleCount; int m_stencilBits; gfx::Size m_lastSize;