forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSurfaceFactory.cpp
59 lines (46 loc) · 1.23 KB
/
SurfaceFactory.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40; -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "SurfaceFactory.h"
#include "SharedSurface.h"
namespace mozilla {
namespace gfx {
SurfaceFactory::~SurfaceFactory()
{
while (!mScraps.empty()) {
SharedSurface* cur = mScraps.front();
mScraps.pop();
delete cur;
}
}
SharedSurface*
SurfaceFactory::NewSharedSurface(const gfxIntSize& size)
{
// Attempt to reuse an old surface.
while (!mScraps.empty()) {
SharedSurface* cur = mScraps.front();
mScraps.pop();
if (cur->Size() == size)
return cur;
// Destroy old surfaces of the wrong size.
delete cur;
}
SharedSurface* ret = CreateShared(size);
return ret;
}
// Auto-deletes surfs of the wrong type.
void
SurfaceFactory::Recycle(SharedSurface*& surf)
{
if (!surf)
return;
if (surf->Type() == mType) {
mScraps.push(surf);
} else {
delete surf;
}
surf = nullptr;
}
} /* namespace gfx */
} /* namespace mozilla */