| 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 "ppapi/c/pp_instance.h" | 13 #include "ppapi/c/pp_instance.h" |
| 14 #include "ppapi/c/pp_module.h" | 14 #include "ppapi/c/pp_module.h" |
| 15 #include "ppapi/c/pp_resource.h" | 15 #include "ppapi/c/pp_resource.h" |
| 16 #include "ppapi/c/ppb_image_data.h" | 16 #include "ppapi/c/ppb_image_data.h" |
| 17 #include "ppapi/c/trusted/ppb_image_data_trusted.h" | 17 #include "ppapi/c/trusted/ppb_image_data_trusted.h" |
| 18 #include "third_party/skia/include/core/SkColorPriv.h" | 18 #include "third_party/skia/include/core/SkColorPriv.h" |
| 19 #include "webkit/glue/plugins/pepper_common.h" |
| 19 #include "webkit/glue/plugins/pepper_plugin_instance.h" | 20 #include "webkit/glue/plugins/pepper_plugin_instance.h" |
| 20 #include "webkit/glue/plugins/pepper_plugin_module.h" | 21 #include "webkit/glue/plugins/pepper_plugin_module.h" |
| 21 | 22 |
| 22 namespace pepper { | 23 namespace pepper { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 PP_ImageDataFormat GetNativeImageDataFormat() { | 27 PP_ImageDataFormat GetNativeImageDataFormat() { |
| 27 return ImageData::GetNativeImageDataFormat(); | 28 return ImageData::GetNativeImageDataFormat(); |
| 28 } | 29 } |
| 29 | 30 |
| 30 bool IsImageDataFormatSupported(PP_ImageDataFormat format) { | 31 PP_Bool IsImageDataFormatSupported(PP_ImageDataFormat format) { |
| 31 return ImageData::IsImageDataFormatSupported(format); | 32 return BoolToPPBool(ImageData::IsImageDataFormatSupported(format)); |
| 32 } | 33 } |
| 33 | 34 |
| 34 PP_Resource Create(PP_Module module_id, | 35 PP_Resource Create(PP_Module module_id, |
| 35 PP_ImageDataFormat format, | 36 PP_ImageDataFormat format, |
| 36 const PP_Size* size, | 37 const PP_Size* size, |
| 37 bool init_to_zero) { | 38 PP_Bool init_to_zero) { |
| 38 PluginModule* module = ResourceTracker::Get()->GetModule(module_id); | 39 PluginModule* module = ResourceTracker::Get()->GetModule(module_id); |
| 39 if (!module) | 40 if (!module) |
| 40 return 0; | 41 return 0; |
| 41 | 42 |
| 42 scoped_refptr<ImageData> data(new ImageData(module)); | 43 scoped_refptr<ImageData> data(new ImageData(module)); |
| 43 if (!data->Init(format, size->width, size->height, init_to_zero)) | 44 if (!data->Init(format, |
| 45 size->width, |
| 46 size->height, |
| 47 PPBoolToBool(init_to_zero))) { |
| 44 return 0; | 48 return 0; |
| 49 } |
| 45 | 50 |
| 46 return data->GetReference(); | 51 return data->GetReference(); |
| 47 } | 52 } |
| 48 | 53 |
| 49 bool IsImageData(PP_Resource resource) { | 54 PP_Bool IsImageData(PP_Resource resource) { |
| 50 return !!Resource::GetAs<ImageData>(resource); | 55 return BoolToPPBool(!!Resource::GetAs<ImageData>(resource)); |
| 51 } | 56 } |
| 52 | 57 |
| 53 bool Describe(PP_Resource resource, PP_ImageDataDesc* desc) { | 58 PP_Bool Describe(PP_Resource resource, PP_ImageDataDesc* desc) { |
| 54 // Give predictable values on failure. | 59 // Give predictable values on failure. |
| 55 memset(desc, 0, sizeof(PP_ImageDataDesc)); | 60 memset(desc, 0, sizeof(PP_ImageDataDesc)); |
| 56 | 61 |
| 57 scoped_refptr<ImageData> image_data(Resource::GetAs<ImageData>(resource)); | 62 scoped_refptr<ImageData> image_data(Resource::GetAs<ImageData>(resource)); |
| 58 if (!image_data) | 63 if (!image_data) |
| 59 return false; | 64 return PP_FALSE; |
| 60 image_data->Describe(desc); | 65 image_data->Describe(desc); |
| 61 return true; | 66 return PP_TRUE; |
| 62 } | 67 } |
| 63 | 68 |
| 64 void* Map(PP_Resource resource) { | 69 void* Map(PP_Resource resource) { |
| 65 scoped_refptr<ImageData> image_data(Resource::GetAs<ImageData>(resource)); | 70 scoped_refptr<ImageData> image_data(Resource::GetAs<ImageData>(resource)); |
| 66 if (!image_data) | 71 if (!image_data) |
| 67 return NULL; | 72 return NULL; |
| 68 return image_data->Map(); | 73 return image_data->Map(); |
| 69 } | 74 } |
| 70 | 75 |
| 71 void Unmap(PP_Resource resource) { | 76 void Unmap(PP_Resource resource) { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 201 |
| 197 void ImageData::Swap(ImageData* other) { | 202 void ImageData::Swap(ImageData* other) { |
| 198 swap(other->platform_image_, platform_image_); | 203 swap(other->platform_image_, platform_image_); |
| 199 swap(other->mapped_canvas_, mapped_canvas_); | 204 swap(other->mapped_canvas_, mapped_canvas_); |
| 200 std::swap(other->format_, format_); | 205 std::swap(other->format_, format_); |
| 201 std::swap(other->width_, width_); | 206 std::swap(other->width_, width_); |
| 202 std::swap(other->height_, height_); | 207 std::swap(other->height_, height_); |
| 203 } | 208 } |
| 204 | 209 |
| 205 } // namespace pepper | 210 } // namespace pepper |
| OLD | NEW |