Pepper_47_C++_interfaces
buffer_dev.cc
Go to the documentation of this file.
1 // Copyright (c) 2011 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 
6 
7 #include "ppapi/c/dev/ppb_buffer_dev.h"
9 #include "ppapi/cpp/module.h"
10 #include "ppapi/cpp/module_impl.h"
11 
12 namespace pp {
13 
14 namespace {
15 
16 template <> const char* interface_name<PPB_Buffer_Dev>() {
17  return PPB_BUFFER_DEV_INTERFACE;
18 }
19 
20 } // namespace
21 
22 Buffer_Dev::Buffer_Dev() : data_(NULL), size_(0) {
23 }
24 
26  : Resource(other) {
27  Init();
28 }
29 
31  : Resource(resource) {
32  Init();
33 }
34 
35 Buffer_Dev::Buffer_Dev(const InstanceHandle& instance, uint32_t size)
36  : data_(NULL),
37  size_(0) {
38  if (!has_interface<PPB_Buffer_Dev>())
39  return;
40 
41  PassRefFromConstructor(get_interface<PPB_Buffer_Dev>()->Create(
42  instance.pp_instance(), size));
43  Init();
44 }
45 
47  : Resource(PassRef(), resource) {
48  Init();
49 }
50 
52  get_interface<PPB_Buffer_Dev>()->Unmap(pp_resource());
53 }
54 
57  Init();
58  return *this;
59 }
60 
61 void Buffer_Dev::Init() {
62  if (get_interface<PPB_Buffer_Dev>()->Describe(pp_resource(), &size_)) {
63  data_ = get_interface<PPB_Buffer_Dev>()->Map(pp_resource());
64  if (data_)
65  return;
66  }
67  data_ = NULL;
68  size_ = 0;
69 }
70 
71 } // namespace pp
void PassRefFromConstructor(PP_Resource resource)
Definition: resource.cc:50
Buffer_Dev & operator=(const Buffer_Dev &rhs)
Definition: buffer_dev.cc:55
uint32_t size() const
Definition: buffer_dev.h:34
virtual ~Buffer_Dev()
Definition: buffer_dev.cc:51
PassRef
Definition: pass_ref.h:17
PP_Resource pp_resource() const
Definition: resource.h:47
PP_Instance pp_instance() const
A reference counted module resource.
Definition: resource.h:20
Resource & operator=(const Resource &other)
Definition: resource.cc:27