blob: e4a0d96dcb4e57f20ab691183b7de4ce37665a83 (
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 (c) 2010 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 "ppapi/cpp/resource.h"
#include <algorithm>
#include "ppapi/cpp/logging.h"
#include "ppapi/cpp/module.h"
namespace pp {
Resource::Resource() : pp_resource_(0) {
}
Resource::Resource(const Resource& other) : pp_resource_(other.pp_resource_) {
if (!is_null())
Module::Get()->core()->AddRefResource(pp_resource_);
}
Resource::~Resource() {
if (!is_null())
Module::Get()->core()->ReleaseResource(pp_resource_);
}
Resource& Resource::operator=(const Resource& other) {
Resource copy(other);
swap(copy);
return *this;
}
void Resource::swap(Resource& other) {
std::swap(pp_resource_, other.pp_resource_);
}
PP_Resource Resource::detach() {
PP_Resource ret = pp_resource_;
pp_resource_ = 0;
return ret;
}
Resource::Resource(PP_Resource resource) : pp_resource_(resource) {
if (!is_null())
Module::Get()->core()->AddRefResource(pp_resource_);
}
void Resource::PassRefFromConstructor(PP_Resource resource) {
PP_DCHECK(!pp_resource_);
pp_resource_ = resource;
}
} // namespace pp
|