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 "webkit/glue/plugins/pepper_image_data.h" | 5 #include "webkit/glue/plugins/pepper_image_data.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/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
12 #include "skia/ext/platform_canvas.h" | 12 #include "skia/ext/platform_canvas.h" |
13 #include "third_party/ppapi/c/pp_instance.h" | 13 #include "third_party/ppapi/c/pp_instance.h" |
14 #include "third_party/ppapi/c/pp_module.h" | 14 #include "third_party/ppapi/c/pp_module.h" |
15 #include "third_party/ppapi/c/pp_resource.h" | 15 #include "third_party/ppapi/c/pp_resource.h" |
16 #include "third_party/ppapi/c/ppb_image_data.h" | 16 #include "third_party/ppapi/c/ppb_image_data.h" |
17 #include "webkit/glue/plugins/pepper_plugin_instance.h" | 17 #include "webkit/glue/plugins/pepper_plugin_instance.h" |
18 #include "webkit/glue/plugins/pepper_plugin_module.h" | 18 #include "webkit/glue/plugins/pepper_plugin_module.h" |
19 | 19 |
20 namespace pepper { | 20 namespace pepper { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 PP_ImageDataFormat GetNativeImageDataFormat() { | 24 PP_ImageDataFormat GetNativeImageDataFormat() { |
25 return PP_IMAGEDATAFORMAT_BGRA_PREMUL; | 25 return PP_IMAGEDATAFORMAT_BGRA_PREMUL; |
26 } | 26 } |
27 | 27 |
28 PP_Resource Create(PP_Module module_id, | 28 PP_Resource Create(PP_Module module_id, |
29 PP_ImageDataFormat format, | 29 PP_ImageDataFormat format, |
30 int32_t width, int32_t height, | 30 const PP_Size* size, |
31 bool init_to_zero) { | 31 bool init_to_zero) { |
32 PluginModule* module = PluginModule::FromPPModule(module_id); | 32 PluginModule* module = PluginModule::FromPPModule(module_id); |
33 if (!module) | 33 if (!module) |
34 return NULL; | 34 return NULL; |
35 | 35 |
| 36 if (!size) |
| 37 return NULL; |
| 38 |
36 scoped_refptr<ImageData> data(new ImageData(module)); | 39 scoped_refptr<ImageData> data(new ImageData(module)); |
37 if (!data->Init(format, width, height, init_to_zero)) | 40 if (!data->Init(format, size->width, size->height, init_to_zero)) |
38 return NULL; | 41 return NULL; |
39 data->AddRef(); // AddRef for the caller. | 42 data->AddRef(); // AddRef for the caller. |
40 | 43 |
41 return data->GetResource(); | 44 return data->GetResource(); |
42 } | 45 } |
43 | 46 |
44 bool IsImageData(PP_Resource resource) { | 47 bool IsImageData(PP_Resource resource) { |
45 return !!Resource::GetAs<ImageData>(resource).get(); | 48 return !!Resource::GetAs<ImageData>(resource).get(); |
46 } | 49 } |
47 | 50 |
48 bool Describe(PP_Resource resource, | 51 bool Describe(PP_Resource resource, PP_ImageDataDesc* desc) { |
49 PP_ImageDataDesc* desc) { | |
50 // Give predictable values on failure. | 52 // Give predictable values on failure. |
51 memset(desc, 0, sizeof(PP_ImageDataDesc)); | 53 memset(desc, 0, sizeof(PP_ImageDataDesc)); |
52 | 54 |
53 scoped_refptr<ImageData> image_data(Resource::GetAs<ImageData>(resource)); | 55 scoped_refptr<ImageData> image_data(Resource::GetAs<ImageData>(resource)); |
54 if (!image_data.get()) | 56 if (!image_data.get()) |
55 return false; | 57 return false; |
56 image_data->Describe(desc); | 58 image_data->Describe(desc); |
57 return true; | 59 return true; |
58 } | 60 } |
59 | 61 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 113 |
112 platform_image_.reset( | 114 platform_image_.reset( |
113 module()->GetSomeInstance()->delegate()->CreateImage2D(width, height)); | 115 module()->GetSomeInstance()->delegate()->CreateImage2D(width, height)); |
114 width_ = width; | 116 width_ = width; |
115 height_ = height; | 117 height_ = height; |
116 return !!platform_image_.get(); | 118 return !!platform_image_.get(); |
117 } | 119 } |
118 | 120 |
119 void ImageData::Describe(PP_ImageDataDesc* desc) const { | 121 void ImageData::Describe(PP_ImageDataDesc* desc) const { |
120 desc->format = PP_IMAGEDATAFORMAT_BGRA_PREMUL; | 122 desc->format = PP_IMAGEDATAFORMAT_BGRA_PREMUL; |
121 desc->width = width_; | 123 desc->size.width = width_; |
122 desc->height = height_; | 124 desc->size.height = height_; |
123 desc->stride = width_ * 4; | 125 desc->stride = width_ * 4; |
124 } | 126 } |
125 | 127 |
126 void* ImageData::Map() { | 128 void* ImageData::Map() { |
127 if (!mapped_canvas_.get()) { | 129 if (!mapped_canvas_.get()) { |
128 mapped_canvas_.reset(platform_image_->Map()); | 130 mapped_canvas_.reset(platform_image_->Map()); |
129 if (!mapped_canvas_.get()) | 131 if (!mapped_canvas_.get()) |
130 return NULL; | 132 return NULL; |
131 } | 133 } |
132 const SkBitmap& bitmap = | 134 const SkBitmap& bitmap = |
(...skipping 20 matching lines...) Expand all Loading... |
153 } | 155 } |
154 | 156 |
155 void ImageData::Swap(ImageData* other) { | 157 void ImageData::Swap(ImageData* other) { |
156 swap(other->platform_image_, platform_image_); | 158 swap(other->platform_image_, platform_image_); |
157 swap(other->mapped_canvas_, mapped_canvas_); | 159 swap(other->mapped_canvas_, mapped_canvas_); |
158 std::swap(other->width_, width_); | 160 std::swap(other->width_, width_); |
159 std::swap(other->height_, height_); | 161 std::swap(other->height_, height_); |
160 } | 162 } |
161 | 163 |
162 } // namespace pepper | 164 } // namespace pepper |
OLD | NEW |