blob: 6f8c1cd8c5478699ee9bc5409ccfa17e928e827e [file] [log] [blame]
James Robinson646469d2014-10-03 15:33:28 -07001// Copyright 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CC_RESOURCES_SCOPED_RESOURCE_H_
6#define CC_RESOURCES_SCOPED_RESOURCE_H_
7
8#include "base/basictypes.h"
9#include "base/logging.h"
10#include "base/memory/scoped_ptr.h"
11#include "cc/base/cc_export.h"
12#include "cc/resources/resource.h"
13
James Robinsond753aca2015-01-12 13:07:20 -080014#if DCHECK_IS_ON()
James Robinson646469d2014-10-03 15:33:28 -070015#include "base/threading/platform_thread.h"
16#endif
17
18namespace cc {
19
20class CC_EXPORT ScopedResource : public Resource {
21 public:
22 static scoped_ptr<ScopedResource> Create(
23 ResourceProvider* resource_provider) {
24 return make_scoped_ptr(new ScopedResource(resource_provider));
25 }
26 virtual ~ScopedResource();
27
28 void Allocate(const gfx::Size& size,
29 ResourceProvider::TextureHint hint,
30 ResourceFormat format);
31 void AllocateManaged(const gfx::Size& size,
32 GLenum target,
33 ResourceFormat format);
34 void Free();
James Robinson646469d2014-10-03 15:33:28 -070035
36 protected:
37 explicit ScopedResource(ResourceProvider* provider);
38
39 private:
40 ResourceProvider* resource_provider_;
41
James Robinsond753aca2015-01-12 13:07:20 -080042#if DCHECK_IS_ON()
James Robinson646469d2014-10-03 15:33:28 -070043 base::PlatformThreadId allocate_thread_id_;
44#endif
45
46 DISALLOW_COPY_AND_ASSIGN(ScopedResource);
47};
48
49} // namespace cc
50
51#endif // CC_RESOURCES_SCOPED_RESOURCE_H_