| 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include "webkit/glue/plugins/pepper_private.h" | 7 #include "webkit/glue/plugins/pepper_private.h" |
| 8 | 8 |
| 9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 87 |
| 88 PP_Resource GetResourceImage(PP_Module module_id, PP_ResourceImage image_id) { | 88 PP_Resource GetResourceImage(PP_Module module_id, PP_ResourceImage image_id) { |
| 89 int res_id = 0; | 89 int res_id = 0; |
| 90 for (size_t i = 0; i < arraysize(kResourceImageMap); ++i) { | 90 for (size_t i = 0; i < arraysize(kResourceImageMap); ++i) { |
| 91 if (kResourceImageMap[i].pp_id == image_id) { | 91 if (kResourceImageMap[i].pp_id == image_id) { |
| 92 res_id = kResourceImageMap[i].res_id; | 92 res_id = kResourceImageMap[i].res_id; |
| 93 break; | 93 break; |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 if (res_id == 0) | 96 if (res_id == 0) |
| 97 return NULL; | 97 return 0; |
| 98 | 98 |
| 99 SkBitmap* res_bitmap = | 99 SkBitmap* res_bitmap = |
| 100 ResourceBundle::GetSharedInstance().GetBitmapNamed(res_id); | 100 ResourceBundle::GetSharedInstance().GetBitmapNamed(res_id); |
| 101 | 101 |
| 102 PluginModule* module = PluginModule::FromPPModule(module_id); | 102 PluginModule* module = PluginModule::FromPPModule(module_id); |
| 103 if (!module) | 103 if (!module) |
| 104 return NULL; | 104 return 0; |
| 105 scoped_refptr<pepper::ImageData> image_data(new pepper::ImageData(module)); | 105 scoped_refptr<pepper::ImageData> image_data(new pepper::ImageData(module)); |
| 106 if (!image_data->Init(PP_IMAGEDATAFORMAT_BGRA_PREMUL, | 106 if (!image_data->Init(PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 107 res_bitmap->width(), res_bitmap->height(), false)) { | 107 res_bitmap->width(), res_bitmap->height(), false)) { |
| 108 return NULL; | 108 return 0; |
| 109 } | 109 } |
| 110 | 110 |
| 111 ImageDataAutoMapper mapper(image_data); | 111 ImageDataAutoMapper mapper(image_data); |
| 112 if (!mapper.is_valid()) | 112 if (!mapper.is_valid()) |
| 113 return NULL; | 113 return 0; |
| 114 | 114 |
| 115 skia::PlatformCanvas* canvas = image_data->mapped_canvas(); | 115 skia::PlatformCanvas* canvas = image_data->mapped_canvas(); |
| 116 SkBitmap& ret_bitmap = | 116 SkBitmap& ret_bitmap = |
| 117 const_cast<SkBitmap&>(canvas->getTopPlatformDevice().accessBitmap(true)); | 117 const_cast<SkBitmap&>(canvas->getTopPlatformDevice().accessBitmap(true)); |
| 118 if (!res_bitmap->copyTo(&ret_bitmap, SkBitmap::kARGB_8888_Config, NULL)) { | 118 if (!res_bitmap->copyTo(&ret_bitmap, SkBitmap::kARGB_8888_Config, NULL)) { |
| 119 return NULL; | 119 return 0; |
| 120 } | 120 } |
| 121 | 121 |
| 122 return image_data->GetReference(); | 122 return image_data->GetReference(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 PP_Resource GetFontFileWithFallback( | 125 PP_Resource GetFontFileWithFallback( |
| 126 PP_Module module_id, | 126 PP_Module module_id, |
| 127 const PP_PrivateFontFileDescription* description) { | 127 const PP_PrivateFontFileDescription* description) { |
| 128 #if defined(OS_LINUX) | 128 #if defined(OS_LINUX) |
| 129 PluginModule* module = PluginModule::FromPPModule(module_id); | 129 PluginModule* module = PluginModule::FromPPModule(module_id); |
| 130 if (!module) | 130 if (!module) |
| 131 return NULL; | 131 return 0; |
| 132 | 132 |
| 133 int fd = webkit_glue::MatchFontWithFallback(description->face, | 133 int fd = webkit_glue::MatchFontWithFallback(description->face, |
| 134 description->weight >= 700, | 134 description->weight >= 700, |
| 135 description->italic, | 135 description->italic, |
| 136 description->charset); | 136 description->charset); |
| 137 if (fd == -1) | 137 if (fd == -1) |
| 138 return NULL; | 138 return 0; |
| 139 | 139 |
| 140 scoped_refptr<PrivateFontFile> font(new PrivateFontFile(module, fd)); | 140 scoped_refptr<PrivateFontFile> font(new PrivateFontFile(module, fd)); |
| 141 | 141 |
| 142 return font->GetReference(); | 142 return font->GetReference(); |
| 143 #else | 143 #else |
| 144 // For trusted pepper plugins, this is only needed in Linux since font loading | 144 // For trusted pepper plugins, this is only needed in Linux since font loading |
| 145 // on Windows and Mac works through the renderer sandbox. | 145 // on Windows and Mac works through the renderer sandbox. |
| 146 return false; | 146 return 0; |
| 147 #endif | 147 #endif |
| 148 } | 148 } |
| 149 | 149 |
| 150 bool GetFontTableForPrivateFontFile(PP_Resource font_file, | 150 bool GetFontTableForPrivateFontFile(PP_Resource font_file, |
| 151 uint32_t table, | 151 uint32_t table, |
| 152 void* output, | 152 void* output, |
| 153 uint32_t* output_length) { | 153 uint32_t* output_length) { |
| 154 #if defined(OS_LINUX) | 154 #if defined(OS_LINUX) |
| 155 scoped_refptr<PrivateFontFile> font( | 155 scoped_refptr<PrivateFontFile> font( |
| 156 Resource::GetAs<PrivateFontFile>(font_file)); | 156 Resource::GetAs<PrivateFontFile>(font_file)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 182 uint32_t* output_length) { | 182 uint32_t* output_length) { |
| 183 size_t temp_size = static_cast<size_t>(*output_length); | 183 size_t temp_size = static_cast<size_t>(*output_length); |
| 184 bool rv = webkit_glue::GetFontTable( | 184 bool rv = webkit_glue::GetFontTable( |
| 185 fd_, table, static_cast<uint8_t*>(output), &temp_size); | 185 fd_, table, static_cast<uint8_t*>(output), &temp_size); |
| 186 *output_length = static_cast<uint32_t>(temp_size); | 186 *output_length = static_cast<uint32_t>(temp_size); |
| 187 return rv; | 187 return rv; |
| 188 } | 188 } |
| 189 #endif | 189 #endif |
| 190 | 190 |
| 191 } // namespace pepper | 191 } // namespace pepper |
| OLD | NEW |