summaryrefslogtreecommitdiffstats
path: root/cc/scoped_texture.cc
blob: 38fb7976e90e681d4e24f3ebab523dc5a2d67552 (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
52
53
// 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 "cc/scoped_texture.h"

namespace cc {

ScopedTexture::ScopedTexture(ResourceProvider* resourceProvider)
    : m_resourceProvider(resourceProvider)
{
    DCHECK(m_resourceProvider);
}

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

bool ScopedTexture::allocate(int pool, const gfx::Size& size, GLenum format, ResourceProvider::TextureUsageHint hint)
{
    DCHECK(!id());
    DCHECK(!size.IsEmpty());

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

#ifndef NDEBUG
    m_allocateThreadIdentifier = base::PlatformThread::CurrentId();
#endif

    return id();
}

void ScopedTexture::free()
{
    if (id()) {
#ifndef NDEBUG
        DCHECK(m_allocateThreadIdentifier == base::PlatformThread::CurrentId());
#endif
        m_resourceProvider->deleteResource(id());
    }
    setId(0);
}

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

}  // namespace cc