gfx/gl/SurfaceFactory.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/gl/SurfaceFactory.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,59 @@
     1.4 +/* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40; -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "SurfaceFactory.h"
    1.10 +
    1.11 +#include "SharedSurface.h"
    1.12 +
    1.13 +namespace mozilla {
    1.14 +namespace gfx {
    1.15 +
    1.16 +SurfaceFactory::~SurfaceFactory()
    1.17 +{
    1.18 +    while (!mScraps.empty()) {
    1.19 +        SharedSurface* cur = mScraps.front();
    1.20 +        mScraps.pop();
    1.21 +
    1.22 +        delete cur;
    1.23 +    }
    1.24 +}
    1.25 +
    1.26 +SharedSurface*
    1.27 +SurfaceFactory::NewSharedSurface(const gfx::IntSize& size)
    1.28 +{
    1.29 +    // Attempt to reuse an old surface.
    1.30 +    while (!mScraps.empty()) {
    1.31 +        SharedSurface* cur = mScraps.front();
    1.32 +        mScraps.pop();
    1.33 +        if (cur->Size() == size)
    1.34 +            return cur;
    1.35 +
    1.36 +        // Destroy old surfaces of the wrong size.
    1.37 +        delete cur;
    1.38 +    }
    1.39 +
    1.40 +    SharedSurface* ret = CreateShared(size);
    1.41 +
    1.42 +    return ret;
    1.43 +}
    1.44 +
    1.45 +// Auto-deletes surfs of the wrong type.
    1.46 +void
    1.47 +SurfaceFactory::Recycle(SharedSurface*& surf)
    1.48 +{
    1.49 +    if (!surf)
    1.50 +        return;
    1.51 +
    1.52 +    if (surf->Type() == mType) {
    1.53 +        mScraps.push(surf);
    1.54 +    } else {
    1.55 +        delete surf;
    1.56 +    }
    1.57 +
    1.58 +    surf = nullptr;
    1.59 +}
    1.60 +
    1.61 +} /* namespace gfx */
    1.62 +} /* namespace mozilla */

mercurial