| 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 #include "webkit/glue/plugins/pepper_resource_tracker.h" | |
| 20 | 19 |
| 21 namespace pepper { | 20 namespace pepper { |
| 22 | 21 |
| 23 namespace { | 22 namespace { |
| 24 | 23 |
| 25 PP_ImageDataFormat GetNativeImageDataFormat() { | 24 PP_ImageDataFormat GetNativeImageDataFormat() { |
| 26 return PP_IMAGEDATAFORMAT_BGRA_PREMUL; | 25 return PP_IMAGEDATAFORMAT_BGRA_PREMUL; |
| 27 } | 26 } |
| 28 | 27 |
| 29 PP_Resource Create(PP_Module module_id, | 28 PP_Resource Create(PP_Module module_id, |
| 30 PP_ImageDataFormat format, | 29 PP_ImageDataFormat format, |
| 31 int32_t width, int32_t height, | 30 int32_t width, int32_t height, |
| 32 bool init_to_zero) { | 31 bool init_to_zero) { |
| 33 PluginModule* module = PluginModule::FromPPModule(module_id); | 32 PluginModule* module = PluginModule::FromPPModule(module_id); |
| 34 if (!module) | 33 if (!module) |
| 35 return NULL; | 34 return NULL; |
| 36 | 35 |
| 37 scoped_refptr<ImageData> data(new ImageData(module)); | 36 scoped_refptr<ImageData> data(new ImageData(module)); |
| 38 if (!data->Init(format, width, height, init_to_zero)) | 37 if (!data->Init(format, width, height, init_to_zero)) |
| 39 return NULL; | 38 return NULL; |
| 40 data->AddRef(); // AddRef for the caller. | 39 data->AddRef(); // AddRef for the caller. |
| 41 | 40 |
| 42 return data->GetResource(); | 41 return data->GetResource(); |
| 43 } | 42 } |
| 44 | 43 |
| 45 bool IsImageData(PP_Resource resource) { | 44 bool IsImageData(PP_Resource resource) { |
| 46 return !!ResourceTracker::Get()->GetAsImageData(resource).get(); | 45 return !!Resource::GetAs<ImageData>(resource).get(); |
| 47 } | 46 } |
| 48 | 47 |
| 49 bool Describe(PP_Resource resource, | 48 bool Describe(PP_Resource resource, |
| 50 PP_ImageDataDesc* desc) { | 49 PP_ImageDataDesc* desc) { |
| 51 // Give predictable values on failure. | 50 // Give predictable values on failure. |
| 52 memset(desc, 0, sizeof(PP_ImageDataDesc)); | 51 memset(desc, 0, sizeof(PP_ImageDataDesc)); |
| 53 | 52 |
| 54 scoped_refptr<ImageData> image_data( | 53 scoped_refptr<ImageData> image_data(Resource::GetAs<ImageData>(resource)); |
| 55 ResourceTracker::Get()->GetAsImageData(resource)); | |
| 56 if (!image_data.get()) | 54 if (!image_data.get()) |
| 57 return false; | 55 return false; |
| 58 image_data->Describe(desc); | 56 image_data->Describe(desc); |
| 59 return true; | 57 return true; |
| 60 } | 58 } |
| 61 | 59 |
| 62 void* Map(PP_Resource resource) { | 60 void* Map(PP_Resource resource) { |
| 63 scoped_refptr<ImageData> image_data( | 61 scoped_refptr<ImageData> image_data(Resource::GetAs<ImageData>(resource)); |
| 64 ResourceTracker::Get()->GetAsImageData(resource)); | |
| 65 if (!image_data.get()) | 62 if (!image_data.get()) |
| 66 return NULL; | 63 return NULL; |
| 67 return image_data->Map(); | 64 return image_data->Map(); |
| 68 } | 65 } |
| 69 | 66 |
| 70 void Unmap(PP_Resource resource) { | 67 void Unmap(PP_Resource resource) { |
| 71 scoped_refptr<ImageData> image_data( | 68 scoped_refptr<ImageData> image_data(Resource::GetAs<ImageData>(resource)); |
| 72 ResourceTracker::Get()->GetAsImageData(resource)); | |
| 73 if (!image_data) | 69 if (!image_data) |
| 74 return; | 70 return; |
| 75 return image_data->Unmap(); | 71 return image_data->Unmap(); |
| 76 } | 72 } |
| 77 | 73 |
| 78 const PPB_ImageData ppb_imagedata = { | 74 const PPB_ImageData ppb_imagedata = { |
| 79 &GetNativeImageDataFormat, | 75 &GetNativeImageDataFormat, |
| 80 &Create, | 76 &Create, |
| 81 &IsImageData, | 77 &IsImageData, |
| 82 &Describe, | 78 &Describe, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 } | 153 } |
| 158 | 154 |
| 159 void ImageData::Swap(ImageData* other) { | 155 void ImageData::Swap(ImageData* other) { |
| 160 swap(other->platform_image_, platform_image_); | 156 swap(other->platform_image_, platform_image_); |
| 161 swap(other->mapped_canvas_, mapped_canvas_); | 157 swap(other->mapped_canvas_, mapped_canvas_); |
| 162 std::swap(other->width_, width_); | 158 std::swap(other->width_, width_); |
| 163 std::swap(other->height_, height_); | 159 std::swap(other->height_, height_); |
| 164 } | 160 } |
| 165 | 161 |
| 166 } // namespace pepper | 162 } // namespace pepper |
| OLD | NEW |