summaryrefslogtreecommitdiffstats
path: root/cc/CCScopedTexture.cpp
blob: b032680714f59d04a62ae13dc1e5fb063f8d330d (plain)
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
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "config.h"

#include "CCScopedTexture.h"

namespace WebCore {

CCScopedTexture::CCScopedTexture(CCResourceProvider* resourceProvider)
    : m_resourceProvider(resourceProvider)
{
    ASSERT(m_resourceProvider);
}

CCScopedTexture::~CCScopedTexture()
{
    free();
}

bool CCScopedTexture::allocate(int pool, const IntSize& size, GC3Denum format, CCResourceProvider::TextureUsageHint hint)
{
    ASSERT(!id());
    ASSERT(!size.isEmpty());

    setDimensions(size, format);
    setId(m_resourceProvider->createResource(pool, size, format, hint));

#if !ASSERT_DISABLED
    m_allocateThreadIdentifier = WTF::currentThread();
#endif

    return id();
}

void CCScopedTexture::free()
{
    if (id()) {
        ASSERT(m_allocateThreadIdentifier == WTF::currentThread());
        m_resourceProvider->deleteResource(id());
    }
    setId(0);
}

void CCScopedTexture::leak()
{
    setId(0);
}

}