OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/device_context_2d.h" | 5 #include "ppapi/cpp/device_context_2d.h" |
6 | 6 |
| 7 #include "ppapi/c/pp_errors.h" |
| 8 #include "ppapi/c/ppb_device_context_2d.h" |
| 9 #include "ppapi/cpp/completion_callback.h" |
7 #include "ppapi/cpp/image_data.h" | 10 #include "ppapi/cpp/image_data.h" |
8 #include "ppapi/cpp/module.h" | 11 #include "ppapi/cpp/module.h" |
9 | 12 |
10 namespace pp { | 13 namespace pp { |
11 | 14 |
12 static PPB_DeviceContext2D const* device_context_2d_funcs = NULL; | 15 static PPB_DeviceContext2D const* device_context_2d_funcs = NULL; |
13 | 16 |
14 static bool EnsureFuncs() { | 17 static bool EnsureFuncs() { |
15 if (!device_context_2d_funcs) { | 18 if (!device_context_2d_funcs) { |
16 device_context_2d_funcs = reinterpret_cast<PPB_DeviceContext2D const*>( | 19 device_context_2d_funcs = reinterpret_cast<PPB_DeviceContext2D const*>( |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 if (device_context_2d_funcs->ReplaceContents(pp_resource(), | 85 if (device_context_2d_funcs->ReplaceContents(pp_resource(), |
83 image->pp_resource())) { | 86 image->pp_resource())) { |
84 // On success, reset the image data. This is to help prevent people | 87 // On success, reset the image data. This is to help prevent people |
85 // from continuing to use the resource which will result in artifacts. | 88 // from continuing to use the resource which will result in artifacts. |
86 *image = ImageData(); | 89 *image = ImageData(); |
87 return true; | 90 return true; |
88 } | 91 } |
89 return false; | 92 return false; |
90 } | 93 } |
91 | 94 |
92 bool DeviceContext2D::Flush(PPB_DeviceContext2D_FlushCallback callback, | 95 int32_t DeviceContext2D::Flush(const CompletionCallback& cc) { |
93 void* callback_data) { | 96 if (!EnsureFuncs()) |
94 if (!EnsureFuncs() || is_null()) | 97 return PP_Error_NoInterface; |
95 return false; | 98 if (is_null()) |
96 return device_context_2d_funcs->Flush(pp_resource(), callback, callback_data); | 99 return PP_Error_BadResource; |
| 100 return device_context_2d_funcs->Flush(pp_resource(), |
| 101 cc.pp_completion_callback()); |
97 } | 102 } |
98 | 103 |
99 } // namespace pp | 104 } // namespace pp |
OLD | NEW |