Index: chrome/renderer/pepper/ppb_pdf_impl.cc |
diff --git a/chrome/renderer/pepper/ppb_pdf_impl.cc b/chrome/renderer/pepper/ppb_pdf_impl.cc |
index a44610580369f232d01441d3dec9be28ad6558d4..33078f8615deebf1f4d260113be22f75978dab68 100644 |
--- a/chrome/renderer/pepper/ppb_pdf_impl.cc |
+++ b/chrome/renderer/pepper/ppb_pdf_impl.cc |
@@ -29,7 +29,10 @@ |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
#include "ui/base/l10n/l10n_util.h" |
+#include "ui/base/layout.h" |
#include "ui/base/resource/resource_bundle.h" |
+#include "ui/gfx/image/image_skia.h" |
+#include "ui/gfx/image/image_skia_rep.h" |
#include "unicode/usearch.h" |
#include "webkit/plugins/ppapi/host_globals.h" |
#include "webkit/plugins/ppapi/plugin_delegate.h" |
@@ -363,6 +366,61 @@ PP_Bool IsFeatureEnabled(PP_PDFFeature feature) { |
return result; |
} |
+PP_Resource GetResourceImageForScale(PP_Instance instance_id, |
brettw
2012/08/01 21:20:51
This is mostly copied fromGetResourceImage. I wond
Josh Horwich
2012/08/01 21:53:52
Done.
|
+ PP_ResourceImage image_id, |
+ float scale) { |
+ int res_id = 0; |
+ for (size_t i = 0; i < arraysize(kResourceImageMap); ++i) { |
+ if (kResourceImageMap[i].pp_id == image_id) { |
+ res_id = kResourceImageMap[i].res_id; |
+ break; |
+ } |
+ } |
+ if (res_id == 0) |
+ return 0; |
+ |
+ ui::ScaleFactor scale_factor = ui::GetScaleFactorFromScale(scale); |
+ |
+ gfx::ImageSkia* res_image_skia = |
+ ResourceBundle::GetSharedInstance().GetImageSkiaNamed(res_id); |
+ |
+ if (!res_image_skia) |
+ return 0; |
+ |
+ // Validate the instance. |
+ if (!content::GetHostGlobals()->GetInstance(instance_id)) |
+ return 0; |
+ |
+ if (!res_image_skia->HasRepresentation(scale_factor)) |
+ return 0; |
+ |
+ gfx::ImageSkiaRep image_skia_rep = res_image_skia->GetRepresentation( |
+ scale_factor); |
+ |
+ scoped_refptr<webkit::ppapi::PPB_ImageData_Impl> image_data( |
+ new webkit::ppapi::PPB_ImageData_Impl( |
+ instance_id, |
+ webkit::ppapi::PPB_ImageData_Impl::PLATFORM)); |
+ if (!image_data->Init( |
+ webkit::ppapi::PPB_ImageData_Impl::GetNativeImageDataFormat(), |
+ image_skia_rep.pixel_width(), |
+ image_skia_rep.pixel_height(), |
+ false)) { |
+ return 0; |
+ } |
+ |
+ webkit::ppapi::ImageDataAutoMapper mapper(image_data); |
+ if (!mapper.is_valid()) |
+ return 0; |
+ |
+ skia::PlatformCanvas* canvas = image_data->GetPlatformCanvas(); |
+ // Note: Do not skBitmap::copyTo the canvas bitmap directly because it will |
+ // ignore the allocated pixels in shared memory and re-allocate a new buffer. |
+ canvas->writePixels(image_skia_rep.sk_bitmap(), 0, 0); |
+ |
+ return image_data->GetReference(); |
+} |
+ |
const PPB_PDF ppb_pdf = { |
&GetLocalizedString, |
&GetResourceImage, |
@@ -377,7 +435,8 @@ const PPB_PDF ppb_pdf = { |
&HasUnsupportedFeature, |
&SaveAs, |
&PPB_PDF_Impl::InvokePrintingForInstance, |
- &IsFeatureEnabled |
+ &IsFeatureEnabled, |
+ &GetResourceImageForScale |
}; |
} // namespace |