michael@0: /* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40; -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "SurfaceFactory.h" michael@0: michael@0: #include "SharedSurface.h" michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: michael@0: SurfaceFactory::~SurfaceFactory() michael@0: { michael@0: while (!mScraps.empty()) { michael@0: SharedSurface* cur = mScraps.front(); michael@0: mScraps.pop(); michael@0: michael@0: delete cur; michael@0: } michael@0: } michael@0: michael@0: SharedSurface* michael@0: SurfaceFactory::NewSharedSurface(const gfx::IntSize& size) michael@0: { michael@0: // Attempt to reuse an old surface. michael@0: while (!mScraps.empty()) { michael@0: SharedSurface* cur = mScraps.front(); michael@0: mScraps.pop(); michael@0: if (cur->Size() == size) michael@0: return cur; michael@0: michael@0: // Destroy old surfaces of the wrong size. michael@0: delete cur; michael@0: } michael@0: michael@0: SharedSurface* ret = CreateShared(size); michael@0: michael@0: return ret; michael@0: } michael@0: michael@0: // Auto-deletes surfs of the wrong type. michael@0: void michael@0: SurfaceFactory::Recycle(SharedSurface*& surf) michael@0: { michael@0: if (!surf) michael@0: return; michael@0: michael@0: if (surf->Type() == mType) { michael@0: mScraps.push(surf); michael@0: } else { michael@0: delete surf; michael@0: } michael@0: michael@0: surf = nullptr; michael@0: } michael@0: michael@0: } /* namespace gfx */ michael@0: } /* namespace mozilla */