Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: ppapi/cpp/image_data.cc

Issue 9700088: Check for specific PPB interface versions in C++ wrappers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix MouseInputEvent version check. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/cpp/graphics_2d.cc ('k') | ppapi/cpp/input_event.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/cpp/image_data.h" 5 #include "ppapi/cpp/image_data.h"
6 6
7 #include <string.h> // Needed for memset. 7 #include <string.h> // Needed for memset.
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "ppapi/cpp/instance_handle.h" 11 #include "ppapi/cpp/instance_handle.h"
12 #include "ppapi/cpp/module.h" 12 #include "ppapi/cpp/module.h"
13 #include "ppapi/cpp/module_impl.h" 13 #include "ppapi/cpp/module_impl.h"
14 14
15 namespace pp { 15 namespace pp {
16 16
17 namespace { 17 namespace {
18 18
19 template <> const char* interface_name<PPB_ImageData>() { 19 template <> const char* interface_name<PPB_ImageData_1_0>() {
20 return PPB_IMAGEDATA_INTERFACE; 20 return PPB_IMAGEDATA_INTERFACE_1_0;
21 } 21 }
22 22
23 } // namespace 23 } // namespace
24 24
25 ImageData::ImageData() : data_(NULL) { 25 ImageData::ImageData() : data_(NULL) {
26 memset(&desc_, 0, sizeof(PP_ImageDataDesc)); 26 memset(&desc_, 0, sizeof(PP_ImageDataDesc));
27 } 27 }
28 28
29 ImageData::ImageData(const ImageData& other) 29 ImageData::ImageData(const ImageData& other)
30 : Resource(other), 30 : Resource(other),
31 desc_(other.desc_), 31 desc_(other.desc_),
32 data_(other.data_) { 32 data_(other.data_) {
33 } 33 }
34 34
35 ImageData::ImageData(PassRef, PP_Resource resource) 35 ImageData::ImageData(PassRef, PP_Resource resource)
36 : Resource(PASS_REF, resource), 36 : Resource(PASS_REF, resource),
37 data_(NULL) { 37 data_(NULL) {
38 memset(&desc_, 0, sizeof(PP_ImageDataDesc)); 38 memset(&desc_, 0, sizeof(PP_ImageDataDesc));
39 InitData(); 39 InitData();
40 } 40 }
41 41
42 ImageData::ImageData(const InstanceHandle& instance, 42 ImageData::ImageData(const InstanceHandle& instance,
43 PP_ImageDataFormat format, 43 PP_ImageDataFormat format,
44 const Size& size, 44 const Size& size,
45 bool init_to_zero) 45 bool init_to_zero)
46 : data_(NULL) { 46 : data_(NULL) {
47 memset(&desc_, 0, sizeof(PP_ImageDataDesc)); 47 memset(&desc_, 0, sizeof(PP_ImageDataDesc));
48 48
49 if (!has_interface<PPB_ImageData>()) 49 if (!has_interface<PPB_ImageData_1_0>())
50 return; 50 return;
51 51
52 PassRefFromConstructor(get_interface<PPB_ImageData>()->Create( 52 PassRefFromConstructor(get_interface<PPB_ImageData_1_0>()->Create(
53 instance.pp_instance(), format, &size.pp_size(), 53 instance.pp_instance(), format, &size.pp_size(),
54 PP_FromBool(init_to_zero))); 54 PP_FromBool(init_to_zero)));
55 InitData(); 55 InitData();
56 } 56 }
57 57
58 ImageData& ImageData::operator=(const ImageData& other) { 58 ImageData& ImageData::operator=(const ImageData& other) {
59 Resource::operator=(other); 59 Resource::operator=(other);
60 desc_ = other.desc_; 60 desc_ = other.desc_;
61 data_ = other.data_; 61 data_ = other.data_;
62 return *this; 62 return *this;
63 } 63 }
64 64
65 const uint32_t* ImageData::GetAddr32(const Point& coord) const { 65 const uint32_t* ImageData::GetAddr32(const Point& coord) const {
66 // Prefer evil const casts rather than evil code duplication. 66 // Prefer evil const casts rather than evil code duplication.
67 return const_cast<ImageData*>(this)->GetAddr32(coord); 67 return const_cast<ImageData*>(this)->GetAddr32(coord);
68 } 68 }
69 69
70 uint32_t* ImageData::GetAddr32(const Point& coord) { 70 uint32_t* ImageData::GetAddr32(const Point& coord) {
71 // If we add more image format types that aren't 32-bit, we'd want to check 71 // If we add more image format types that aren't 32-bit, we'd want to check
72 // here and fail. 72 // here and fail.
73 return reinterpret_cast<uint32_t*>( 73 return reinterpret_cast<uint32_t*>(
74 &static_cast<char*>(data())[coord.y() * stride() + coord.x() * 4]); 74 &static_cast<char*>(data())[coord.y() * stride() + coord.x() * 4]);
75 } 75 }
76 76
77 // static 77 // static
78 PP_ImageDataFormat ImageData::GetNativeImageDataFormat() { 78 PP_ImageDataFormat ImageData::GetNativeImageDataFormat() {
79 if (!has_interface<PPB_ImageData>()) 79 if (!has_interface<PPB_ImageData_1_0>())
80 return PP_IMAGEDATAFORMAT_BGRA_PREMUL; // Default to something on failure. 80 return PP_IMAGEDATAFORMAT_BGRA_PREMUL; // Default to something on failure.
81 return get_interface<PPB_ImageData>()->GetNativeImageDataFormat(); 81 return get_interface<PPB_ImageData_1_0>()->GetNativeImageDataFormat();
82 } 82 }
83 83
84 void ImageData::InitData() { 84 void ImageData::InitData() {
85 if (!has_interface<PPB_ImageData>()) 85 if (!has_interface<PPB_ImageData_1_0>())
86 return; 86 return;
87 if (!get_interface<PPB_ImageData>()->Describe(pp_resource(), &desc_) || 87 if (!get_interface<PPB_ImageData_1_0>()->Describe(pp_resource(), &desc_) ||
88 !(data_ = get_interface<PPB_ImageData>()->Map(pp_resource()))) 88 !(data_ = get_interface<PPB_ImageData_1_0>()->Map(pp_resource())))
89 *this = ImageData(); 89 *this = ImageData();
90 } 90 }
91 91
92 } // namespace pp 92 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/cpp/graphics_2d.cc ('k') | ppapi/cpp/input_event.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698