OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "webkit/plugins/ppapi/ppb_image_data_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "skia/ext/platform_canvas.h" | 12 #include "skia/ext/platform_canvas.h" |
13 #include "ppapi/c/pp_instance.h" | 13 #include "ppapi/c/pp_instance.h" |
14 #include "ppapi/c/pp_resource.h" | 14 #include "ppapi/c/pp_resource.h" |
15 #include "ppapi/c/ppb_image_data.h" | 15 #include "ppapi/c/ppb_image_data.h" |
16 #include "ppapi/c/trusted/ppb_image_data_trusted.h" | 16 #include "ppapi/c/trusted/ppb_image_data_trusted.h" |
17 #include "ppapi/thunk/thunk.h" | 17 #include "ppapi/thunk/thunk.h" |
18 #include "third_party/skia/include/core/SkColorPriv.h" | 18 #include "third_party/skia/include/core/SkColorPriv.h" |
19 #include "webkit/plugins/ppapi/common.h" | 19 #include "webkit/plugins/ppapi/common.h" |
20 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 20 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 21 #include "webkit/plugins/ppapi/resource_helper.h" |
21 | 22 |
22 using ::ppapi::thunk::PPB_ImageData_API; | 23 using ::ppapi::thunk::PPB_ImageData_API; |
23 | 24 |
24 namespace webkit { | 25 namespace webkit { |
25 namespace ppapi { | 26 namespace ppapi { |
26 | 27 |
27 PPB_ImageData_Impl::PPB_ImageData_Impl(PluginInstance* instance) | 28 PPB_ImageData_Impl::PPB_ImageData_Impl(PP_Instance instance) |
28 : Resource(instance), | 29 : Resource(instance), |
29 format_(PP_IMAGEDATAFORMAT_BGRA_PREMUL), | 30 format_(PP_IMAGEDATAFORMAT_BGRA_PREMUL), |
30 width_(0), | 31 width_(0), |
31 height_(0) { | 32 height_(0) { |
32 } | 33 } |
33 | 34 |
34 PPB_ImageData_Impl::~PPB_ImageData_Impl() { | 35 PPB_ImageData_Impl::~PPB_ImageData_Impl() { |
35 } | 36 } |
36 | 37 |
37 // static | 38 // static |
38 PP_Resource PPB_ImageData_Impl::Create(PluginInstance* instance, | 39 PP_Resource PPB_ImageData_Impl::Create(PP_Instance instance, |
39 PP_ImageDataFormat format, | 40 PP_ImageDataFormat format, |
40 const PP_Size& size, | 41 const PP_Size& size, |
41 PP_Bool init_to_zero) { | 42 PP_Bool init_to_zero) { |
42 scoped_refptr<PPB_ImageData_Impl> data(new PPB_ImageData_Impl(instance)); | 43 scoped_refptr<PPB_ImageData_Impl> data(new PPB_ImageData_Impl(instance)); |
43 if (!data->Init(format, size.width, size.height, !!init_to_zero)) | 44 if (!data->Init(format, size.width, size.height, !!init_to_zero)) |
44 return 0; | 45 return 0; |
45 return data->GetReference(); | 46 return data->GetReference(); |
46 } | 47 } |
47 | 48 |
48 PPB_ImageData_API* PPB_ImageData_Impl::AsPPB_ImageData_API() { | 49 PPB_ImageData_API* PPB_ImageData_Impl::AsPPB_ImageData_API() { |
49 return this; | 50 return this; |
50 } | 51 } |
51 | 52 |
52 bool PPB_ImageData_Impl::Init(PP_ImageDataFormat format, | 53 bool PPB_ImageData_Impl::Init(PP_ImageDataFormat format, |
53 int width, int height, | 54 int width, int height, |
54 bool init_to_zero) { | 55 bool init_to_zero) { |
55 // TODO(brettw) this should be called only on the main thread! | 56 // TODO(brettw) this should be called only on the main thread! |
56 // TODO(brettw) use init_to_zero when we implement caching. | 57 // TODO(brettw) use init_to_zero when we implement caching. |
57 if (!IsImageDataFormatSupported(format)) | 58 if (!IsImageDataFormatSupported(format)) |
58 return false; // Only support this one format for now. | 59 return false; // Only support this one format for now. |
59 if (width <= 0 || height <= 0) | 60 if (width <= 0 || height <= 0) |
60 return false; | 61 return false; |
61 if (static_cast<int64>(width) * static_cast<int64>(height) * 4 >= | 62 if (static_cast<int64>(width) * static_cast<int64>(height) * 4 >= |
62 std::numeric_limits<int32>::max()) | 63 std::numeric_limits<int32>::max()) |
63 return false; // Prevent overflow of signed 32-bit ints. | 64 return false; // Prevent overflow of signed 32-bit ints. |
64 | 65 |
65 platform_image_.reset( | 66 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); |
66 instance()->delegate()->CreateImage2D(width, height)); | 67 if (!plugin_delegate) |
| 68 return false; |
| 69 |
| 70 platform_image_.reset(plugin_delegate->CreateImage2D(width, height)); |
67 format_ = format; | 71 format_ = format; |
68 width_ = width; | 72 width_ = width; |
69 height_ = height; | 73 height_ = height; |
70 return !!platform_image_.get(); | 74 return !!platform_image_.get(); |
71 } | 75 } |
72 | 76 |
73 PP_Bool PPB_ImageData_Impl::Describe(PP_ImageDataDesc* desc) { | 77 PP_Bool PPB_ImageData_Impl::Describe(PP_ImageDataDesc* desc) { |
74 desc->format = format_; | 78 desc->format = format_; |
75 desc->size.width = width_; | 79 desc->size.width = width_; |
76 desc->size.height = height_; | 80 desc->size.height = height_; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 swap(other->platform_image_, platform_image_); | 121 swap(other->platform_image_, platform_image_); |
118 swap(other->mapped_canvas_, mapped_canvas_); | 122 swap(other->mapped_canvas_, mapped_canvas_); |
119 std::swap(other->format_, format_); | 123 std::swap(other->format_, format_); |
120 std::swap(other->width_, width_); | 124 std::swap(other->width_, width_); |
121 std::swap(other->height_, height_); | 125 std::swap(other->height_, height_); |
122 } | 126 } |
123 | 127 |
124 } // namespace ppapi | 128 } // namespace ppapi |
125 } // namespace webkit | 129 } // namespace webkit |
126 | 130 |
OLD | NEW |