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

Side by Side Diff: ppapi/cpp/graphics_2d.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 | « no previous file | ppapi/cpp/image_data.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) 2011 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/graphics_2d.h" 5 #include "ppapi/cpp/graphics_2d.h"
6 6
7 #include "ppapi/c/pp_errors.h" 7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/c/ppb_graphics_2d.h" 8 #include "ppapi/c/ppb_graphics_2d.h"
9 #include "ppapi/cpp/completion_callback.h" 9 #include "ppapi/cpp/completion_callback.h"
10 #include "ppapi/cpp/image_data.h" 10 #include "ppapi/cpp/image_data.h"
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 #include "ppapi/cpp/point.h" 14 #include "ppapi/cpp/point.h"
15 #include "ppapi/cpp/rect.h" 15 #include "ppapi/cpp/rect.h"
16 16
17 namespace pp { 17 namespace pp {
18 18
19 namespace { 19 namespace {
20 20
21 template <> const char* interface_name<PPB_Graphics2D>() { 21 template <> const char* interface_name<PPB_Graphics2D_1_0>() {
22 return PPB_GRAPHICS_2D_INTERFACE; 22 return PPB_GRAPHICS_2D_INTERFACE_1_0;
23 } 23 }
24 24
25 } // namespace 25 } // namespace
26 26
27 Graphics2D::Graphics2D() : Resource() { 27 Graphics2D::Graphics2D() : Resource() {
28 } 28 }
29 29
30 Graphics2D::Graphics2D(const Graphics2D& other) 30 Graphics2D::Graphics2D(const Graphics2D& other)
31 : Resource(other), 31 : Resource(other),
32 size_(other.size_) { 32 size_(other.size_) {
33 } 33 }
34 34
35 Graphics2D::Graphics2D(const InstanceHandle& instance, 35 Graphics2D::Graphics2D(const InstanceHandle& instance,
36 const Size& size, 36 const Size& size,
37 bool is_always_opaque) 37 bool is_always_opaque)
38 : Resource() { 38 : Resource() {
39 if (!has_interface<PPB_Graphics2D>()) 39 if (!has_interface<PPB_Graphics2D_1_0>())
40 return; 40 return;
41 PassRefFromConstructor(get_interface<PPB_Graphics2D>()->Create( 41 PassRefFromConstructor(get_interface<PPB_Graphics2D_1_0>()->Create(
42 instance.pp_instance(), 42 instance.pp_instance(),
43 &size.pp_size(), 43 &size.pp_size(),
44 PP_FromBool(is_always_opaque))); 44 PP_FromBool(is_always_opaque)));
45 if (!is_null()) { 45 if (!is_null()) {
46 // Only save the size if allocation succeeded. 46 // Only save the size if allocation succeeded.
47 size_ = size; 47 size_ = size;
48 } 48 }
49 } 49 }
50 50
51 Graphics2D::~Graphics2D() { 51 Graphics2D::~Graphics2D() {
52 } 52 }
53 53
54 Graphics2D& Graphics2D::operator=(const Graphics2D& other) { 54 Graphics2D& Graphics2D::operator=(const Graphics2D& other) {
55 Resource::operator=(other); 55 Resource::operator=(other);
56 size_ = other.size_; 56 size_ = other.size_;
57 return *this; 57 return *this;
58 } 58 }
59 59
60 void Graphics2D::PaintImageData(const ImageData& image, 60 void Graphics2D::PaintImageData(const ImageData& image,
61 const Point& top_left) { 61 const Point& top_left) {
62 if (!has_interface<PPB_Graphics2D>()) 62 if (!has_interface<PPB_Graphics2D_1_0>())
63 return; 63 return;
64 get_interface<PPB_Graphics2D>()->PaintImageData(pp_resource(), 64 get_interface<PPB_Graphics2D_1_0>()->PaintImageData(pp_resource(),
65 image.pp_resource(), 65 image.pp_resource(),
66 &top_left.pp_point(), 66 &top_left.pp_point(),
67 NULL); 67 NULL);
68 } 68 }
69 69
70 void Graphics2D::PaintImageData(const ImageData& image, 70 void Graphics2D::PaintImageData(const ImageData& image,
71 const Point& top_left, 71 const Point& top_left,
72 const Rect& src_rect) { 72 const Rect& src_rect) {
73 if (!has_interface<PPB_Graphics2D>()) 73 if (!has_interface<PPB_Graphics2D_1_0>())
74 return; 74 return;
75 get_interface<PPB_Graphics2D>()->PaintImageData(pp_resource(), 75 get_interface<PPB_Graphics2D_1_0>()->PaintImageData(pp_resource(),
76 image.pp_resource(), 76 image.pp_resource(),
77 &top_left.pp_point(), 77 &top_left.pp_point(),
78 &src_rect.pp_rect()); 78 &src_rect.pp_rect());
79 } 79 }
80 80
81 void Graphics2D::Scroll(const Rect& clip, const Point& amount) { 81 void Graphics2D::Scroll(const Rect& clip, const Point& amount) {
82 if (!has_interface<PPB_Graphics2D>()) 82 if (!has_interface<PPB_Graphics2D_1_0>())
83 return; 83 return;
84 get_interface<PPB_Graphics2D>()->Scroll(pp_resource(), 84 get_interface<PPB_Graphics2D_1_0>()->Scroll(pp_resource(),
85 &clip.pp_rect(), 85 &clip.pp_rect(),
86 &amount.pp_point()); 86 &amount.pp_point());
87 } 87 }
88 88
89 void Graphics2D::ReplaceContents(ImageData* image) { 89 void Graphics2D::ReplaceContents(ImageData* image) {
90 if (!has_interface<PPB_Graphics2D>()) 90 if (!has_interface<PPB_Graphics2D_1_0>())
91 return; 91 return;
92 get_interface<PPB_Graphics2D>()->ReplaceContents(pp_resource(), 92 get_interface<PPB_Graphics2D_1_0>()->ReplaceContents(pp_resource(),
93 image->pp_resource()); 93 image->pp_resource());
94 94
95 // On success, reset the image data. This is to help prevent people 95 // On success, reset the image data. This is to help prevent people
96 // from continuing to use the resource which will result in artifacts. 96 // from continuing to use the resource which will result in artifacts.
97 *image = ImageData(); 97 *image = ImageData();
98 } 98 }
99 99
100 int32_t Graphics2D::Flush(const CompletionCallback& cc) { 100 int32_t Graphics2D::Flush(const CompletionCallback& cc) {
101 if (!has_interface<PPB_Graphics2D>()) 101 if (!has_interface<PPB_Graphics2D_1_0>())
102 return cc.MayForce(PP_ERROR_NOINTERFACE); 102 return cc.MayForce(PP_ERROR_NOINTERFACE);
103 return get_interface<PPB_Graphics2D>()->Flush(pp_resource(), 103 return get_interface<PPB_Graphics2D_1_0>()->Flush(pp_resource(),
104 cc.pp_completion_callback()); 104 cc.pp_completion_callback());
105 } 105 }
106 106
107 } // namespace pp 107 } // namespace pp
OLDNEW
« no previous file with comments | « no previous file | ppapi/cpp/image_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698