| 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" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 ImageData* ResourceAsImageData(PP_Resource resource) { | 25 ImageData* ResourceAsImageData(PP_Resource resource) { |
| 26 scoped_refptr<Resource> image_resource = | 26 scoped_refptr<Resource> image_resource = |
| 27 ResourceTracker::Get()->GetResource(resource); | 27 ResourceTracker::Get()->GetResource(resource); |
| 28 if (!image_resource.get()) | 28 if (!image_resource.get()) |
| 29 return NULL; | 29 return NULL; |
| 30 return image_resource->AsImageData(); | 30 return image_resource->AsImageData(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 PP_ImageDataFormat GetNativeImageDataFormat() { |
| 34 return PP_IMAGEDATAFORMAT_BGRA_PREMUL; |
| 35 } |
| 36 |
| 33 PP_Resource Create(PP_Module module_id, | 37 PP_Resource Create(PP_Module module_id, |
| 34 PP_ImageDataFormat format, | 38 PP_ImageDataFormat format, |
| 35 int32_t width, int32_t height, | 39 int32_t width, int32_t height, |
| 36 bool init_to_zero) { | 40 bool init_to_zero) { |
| 37 PluginModule* module = PluginModule::FromPPModule(module_id); | 41 PluginModule* module = PluginModule::FromPPModule(module_id); |
| 38 if (!module) | 42 if (!module) |
| 39 return NullPPResource(); | 43 return NULL; |
| 40 | 44 |
| 41 scoped_refptr<ImageData> data(new ImageData(module)); | 45 scoped_refptr<ImageData> data(new ImageData(module)); |
| 42 if (!data->Init(format, width, height, init_to_zero)) | 46 if (!data->Init(format, width, height, init_to_zero)) |
| 43 return NullPPResource(); | 47 return NULL; |
| 44 data->AddRef(); // AddRef for the caller. | 48 data->AddRef(); // AddRef for the caller. |
| 45 | 49 |
| 46 return data->GetResource(); | 50 return data->GetResource(); |
| 47 } | 51 } |
| 48 | 52 |
| 49 bool IsImageData(PP_Resource resource) { | 53 bool IsImageData(PP_Resource resource) { |
| 50 return !!ResourceTracker::Get()->GetAsImageData(resource).get(); | 54 return !!ResourceTracker::Get()->GetAsImageData(resource).get(); |
| 51 } | 55 } |
| 52 | 56 |
| 53 bool Describe(PP_Resource resource, | 57 bool Describe(PP_Resource resource, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 73 | 77 |
| 74 void Unmap(PP_Resource resource) { | 78 void Unmap(PP_Resource resource) { |
| 75 scoped_refptr<ImageData> image_data( | 79 scoped_refptr<ImageData> image_data( |
| 76 ResourceTracker::Get()->GetAsImageData(resource)); | 80 ResourceTracker::Get()->GetAsImageData(resource)); |
| 77 if (!image_data) | 81 if (!image_data) |
| 78 return; | 82 return; |
| 79 return image_data->Unmap(); | 83 return image_data->Unmap(); |
| 80 } | 84 } |
| 81 | 85 |
| 82 const PPB_ImageData ppb_imagedata = { | 86 const PPB_ImageData ppb_imagedata = { |
| 87 &GetNativeImageDataFormat, |
| 83 &Create, | 88 &Create, |
| 84 &IsImageData, | 89 &IsImageData, |
| 85 &Describe, | 90 &Describe, |
| 86 &Map, | 91 &Map, |
| 87 &Unmap, | 92 &Unmap, |
| 88 }; | 93 }; |
| 89 | 94 |
| 90 } // namespace | 95 } // namespace |
| 91 | 96 |
| 92 ImageData::ImageData(PluginModule* module) | 97 ImageData::ImageData(PluginModule* module) |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 } | 167 } |
| 163 | 168 |
| 164 void ImageData::Swap(ImageData* other) { | 169 void ImageData::Swap(ImageData* other) { |
| 165 swap(other->platform_image_, platform_image_); | 170 swap(other->platform_image_, platform_image_); |
| 166 swap(other->mapped_canvas_, mapped_canvas_); | 171 swap(other->mapped_canvas_, mapped_canvas_); |
| 167 std::swap(other->width_, width_); | 172 std::swap(other->width_, width_); |
| 168 std::swap(other->height_, height_); | 173 std::swap(other->height_, height_); |
| 169 } | 174 } |
| 170 | 175 |
| 171 } // namespace pepper | 176 } // namespace pepper |
| OLD | NEW |