Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/plugins/ppapi/ppapi_plugin_instance.h" | 5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 #include "webkit/plugins/ppapi/string.h" | 62 #include "webkit/plugins/ppapi/string.h" |
| 63 #include "webkit/plugins/ppapi/var.h" | 63 #include "webkit/plugins/ppapi/var.h" |
| 64 #include "webkit/plugins/sad_plugin.h" | 64 #include "webkit/plugins/sad_plugin.h" |
| 65 | 65 |
| 66 #if defined(OS_MACOSX) | 66 #if defined(OS_MACOSX) |
| 67 #include "base/mac/mac_util.h" | 67 #include "base/mac/mac_util.h" |
| 68 #include "base/mac/scoped_cftyperef.h" | 68 #include "base/mac/scoped_cftyperef.h" |
| 69 #include "printing/metafile_impl.h" | 69 #include "printing/metafile_impl.h" |
| 70 #endif | 70 #endif |
| 71 | 71 |
| 72 #if defined(OS_LINUX) || defined(OS_WIN) || \ | 72 #if defined(USE_SKIA) |
| 73 (defined(OS_MACOSX) && defined(USE_SKIA)) | |
| 74 #include "printing/metafile.h" | 73 #include "printing/metafile.h" |
| 75 #include "printing/metafile_skia_wrapper.h" | 74 #include "printing/metafile_skia_wrapper.h" |
| 76 #endif | 75 #endif |
| 77 | 76 |
| 78 #if defined(OS_WIN) | 77 #if defined(OS_WIN) |
| 79 #include "skia/ext/vector_platform_device_emf_win.h" | 78 #include "skia/ext/vector_platform_device_emf_win.h" |
| 80 #include "ui/gfx/codec/jpeg_codec.h" | 79 #include "ui/gfx/codec/jpeg_codec.h" |
| 81 #include "ui/gfx/gdi_util.h" | 80 #include "ui/gfx/gdi_util.h" |
| 82 #endif | 81 #endif |
|
kmadhusu
2011/06/30 17:58:09
nit: #endif // USE_SKIA
| |
| 83 | 82 |
| 84 #if defined(OS_MACOSX) && defined(USE_SKIA) | 83 #if defined(OS_MACOSX) && defined(USE_SKIA) |
| 85 #include "skia/ext/skia_utils_mac.h" | 84 #include "skia/ext/skia_utils_mac.h" |
| 86 #endif | 85 #endif |
| 87 | 86 |
| 88 using ppapi::thunk::EnterResourceNoLock; | 87 using ppapi::thunk::EnterResourceNoLock; |
| 89 using ppapi::thunk::PPB_Buffer_API; | 88 using ppapi::thunk::PPB_Buffer_API; |
| 90 using ppapi::thunk::PPB_Graphics2D_API; | 89 using ppapi::thunk::PPB_Graphics2D_API; |
| 91 using ppapi::thunk::PPB_ImageData_API; | 90 using ppapi::thunk::PPB_ImageData_API; |
| 92 using ppapi::thunk::PPB_Instance_FunctionAPI; | 91 using ppapi::thunk::PPB_Instance_FunctionAPI; |
| (...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 888 break; | 887 break; |
| 889 default: | 888 default: |
| 890 return 0; | 889 return 0; |
| 891 } | 890 } |
| 892 num_pages = plugin_print_interface_->Begin_0_3(pp_instance(), | 891 num_pages = plugin_print_interface_->Begin_0_3(pp_instance(), |
| 893 &print_settings_0_3); | 892 &print_settings_0_3); |
| 894 } | 893 } |
| 895 if (!num_pages) | 894 if (!num_pages) |
| 896 return 0; | 895 return 0; |
| 897 current_print_settings_ = print_settings; | 896 current_print_settings_ = print_settings; |
| 898 #if WEBKIT_USING_SKIA | 897 #if defined(OS_LINUX) || defined(OS_WIN) |
| 899 canvas_ = NULL; | 898 canvas_ = NULL; |
| 900 ranges_.clear(); | 899 ranges_.clear(); |
| 901 #endif // WEBKIT_USING_SKIA | 900 #endif // OS_LINUX || OS_WIN |
| 902 return num_pages; | 901 return num_pages; |
| 903 } | 902 } |
| 904 | 903 |
| 905 bool PluginInstance::PrintPage(int page_number, WebKit::WebCanvas* canvas) { | 904 bool PluginInstance::PrintPage(int page_number, WebKit::WebCanvas* canvas) { |
| 906 DCHECK(plugin_print_interface_.get()); | 905 DCHECK(plugin_print_interface_.get()); |
| 907 PP_PrintPageNumberRange_Dev page_range; | 906 PP_PrintPageNumberRange_Dev page_range; |
| 908 page_range.first_page_number = page_range.last_page_number = page_number; | 907 page_range.first_page_number = page_range.last_page_number = page_number; |
| 909 #if WEBKIT_USING_SKIA | 908 #if defined(OS_LINUX) || defined(OS_WIN) |
| 910 // The canvas only has a metafile on it for print preview. | 909 // The canvas only has a metafile on it for print preview. |
| 911 if (printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas)) { | 910 if (printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas)) { |
| 912 ranges_.push_back(page_range); | 911 ranges_.push_back(page_range); |
| 913 canvas_ = canvas; | 912 canvas_ = canvas; |
| 914 return true; | 913 return true; |
| 915 } else | 914 } else |
| 916 #endif // WEBKIT_USING_SKIA | 915 #endif // OS_LINUX || OS_WIN |
| 917 { | 916 { |
| 918 return PrintPageHelper(&page_range, 1, canvas); | 917 return PrintPageHelper(&page_range, 1, canvas); |
| 919 } | 918 } |
| 920 } | 919 } |
| 921 | 920 |
| 922 bool PluginInstance::PrintPageHelper(PP_PrintPageNumberRange_Dev* page_ranges, | 921 bool PluginInstance::PrintPageHelper(PP_PrintPageNumberRange_Dev* page_ranges, |
| 923 int num_ranges, | 922 int num_ranges, |
| 924 WebKit::WebCanvas* canvas) { | 923 WebKit::WebCanvas* canvas) { |
| 925 // Keep a reference on the stack. See NOTE above. | 924 // Keep a reference on the stack. See NOTE above. |
| 926 scoped_refptr<PluginInstance> ref(this); | 925 scoped_refptr<PluginInstance> ref(this); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 938 | 937 |
| 939 // Now we need to release the print output resource. | 938 // Now we need to release the print output resource. |
| 940 PluginModule::GetCore()->ReleaseResource(print_output); | 939 PluginModule::GetCore()->ReleaseResource(print_output); |
| 941 | 940 |
| 942 return ret; | 941 return ret; |
| 943 } | 942 } |
| 944 | 943 |
| 945 void PluginInstance::PrintEnd() { | 944 void PluginInstance::PrintEnd() { |
| 946 // Keep a reference on the stack. See NOTE above. | 945 // Keep a reference on the stack. See NOTE above. |
| 947 scoped_refptr<PluginInstance> ref(this); | 946 scoped_refptr<PluginInstance> ref(this); |
| 948 #if WEBKIT_USING_SKIA | 947 #if defined(OS_LINUX) || defined(OS_WIN) |
| 949 if (!ranges_.empty()) | 948 if (!ranges_.empty()) |
| 950 PrintPageHelper(&(ranges_.front()), ranges_.size(), canvas_.get()); | 949 PrintPageHelper(&(ranges_.front()), ranges_.size(), canvas_.get()); |
| 951 canvas_ = NULL; | 950 canvas_ = NULL; |
| 952 ranges_.clear(); | 951 ranges_.clear(); |
| 953 #endif // WEBKIT_USING_SKIA | 952 #endif // OS_LINUX || OS_WIN |
| 954 | 953 |
| 955 DCHECK(plugin_print_interface_.get()); | 954 DCHECK(plugin_print_interface_.get()); |
| 956 if (plugin_print_interface_.get()) | 955 if (plugin_print_interface_.get()) |
| 957 plugin_print_interface_->End(pp_instance()); | 956 plugin_print_interface_->End(pp_instance()); |
| 958 | 957 |
| 959 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | 958 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); |
| 960 #if defined(OS_MACOSX) | 959 #if defined(OS_MACOSX) |
| 961 last_printed_page_ = NULL; | 960 last_printed_page_ = NULL; |
| 962 #endif // defined(OS_MACOSX) | 961 #endif // defined(OS_MACOSX) |
| 963 } | 962 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1058 if (!pdf_module) | 1057 if (!pdf_module) |
| 1059 return false; | 1058 return false; |
| 1060 RenderPDFPageToDCProc render_proc = | 1059 RenderPDFPageToDCProc render_proc = |
| 1061 reinterpret_cast<RenderPDFPageToDCProc>( | 1060 reinterpret_cast<RenderPDFPageToDCProc>( |
| 1062 GetProcAddress(pdf_module, "RenderPDFPageToDC")); | 1061 GetProcAddress(pdf_module, "RenderPDFPageToDC")); |
| 1063 if (!render_proc) | 1062 if (!render_proc) |
| 1064 return false; | 1063 return false; |
| 1065 #endif // defined(OS_WIN) | 1064 #endif // defined(OS_WIN) |
| 1066 | 1065 |
| 1067 bool ret = false; | 1066 bool ret = false; |
| 1068 #if defined(OS_LINUX) | 1067 #if defined(OS_LINUX) || (defined(OS_MACOSX) && defined(USE_SKIA)) |
| 1069 // On Linux we just set the final bits in the native metafile | 1068 // On Linux we just set the final bits in the native metafile |
| 1070 // (NativeMetafile and PreviewMetafile must have compatible formats, | 1069 // (NativeMetafile and PreviewMetafile must have compatible formats, |
| 1071 // i.e. both PDF for this to work). | 1070 // i.e. both PDF for this to work). |
| 1072 printing::Metafile* metafile = | 1071 printing::Metafile* metafile = |
| 1073 printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas); | 1072 printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas); |
| 1074 DCHECK(metafile != NULL); | 1073 DCHECK(metafile != NULL); |
| 1075 if (metafile) | 1074 if (metafile) |
| 1076 ret = metafile->InitFromData(mapper.data(), mapper.size()); | 1075 ret = metafile->InitFromData(mapper.data(), mapper.size()); |
| 1077 #elif defined(OS_MACOSX) | 1076 #elif defined(OS_MACOSX) |
| 1078 printing::NativeMetafile metafile; | 1077 printing::NativeMetafile metafile; |
| 1079 // Create a PDF metafile and render from there into the passed in context. | 1078 // Create a PDF metafile and render from there into the passed in context. |
| 1080 if (metafile.InitFromData(mapper.data(), mapper.size())) { | 1079 if (metafile.InitFromData(mapper.data(), mapper.size())) { |
| 1081 // Flip the transform. | 1080 // Flip the transform. |
| 1082 #if defined(USE_SKIA) | |
| 1083 gfx::SkiaBitLocker bit_locker(canvas); | |
| 1084 CGContextRef cgContext = bit_locker.cgContext(); | |
| 1085 #else | |
| 1086 CGContextRef cgContext = canvas; | 1081 CGContextRef cgContext = canvas; |
| 1087 #endif | |
| 1088 CGContextSaveGState(cgContext); | 1082 CGContextSaveGState(cgContext); |
| 1089 CGContextTranslateCTM(cgContext, 0, | 1083 CGContextTranslateCTM(cgContext, 0, |
| 1090 current_print_settings_.printable_area.size.height); | 1084 current_print_settings_.printable_area.size.height); |
| 1091 CGContextScaleCTM(cgContext, 1.0, -1.0); | 1085 CGContextScaleCTM(cgContext, 1.0, -1.0); |
| 1092 CGRect page_rect; | 1086 CGRect page_rect; |
| 1093 page_rect.origin.x = current_print_settings_.printable_area.point.x; | 1087 page_rect.origin.x = current_print_settings_.printable_area.point.x; |
| 1094 page_rect.origin.y = current_print_settings_.printable_area.point.y; | 1088 page_rect.origin.y = current_print_settings_.printable_area.point.y; |
| 1095 page_rect.size.width = current_print_settings_.printable_area.size.width; | 1089 page_rect.size.width = current_print_settings_.printable_area.size.width; |
| 1096 page_rect.size.height = current_print_settings_.printable_area.size.height; | 1090 page_rect.size.height = current_print_settings_.printable_area.size.height; |
| 1097 | 1091 |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1496 } | 1490 } |
| 1497 | 1491 |
| 1498 PP_Bool PluginInstance::GetScreenSize(PP_Instance instance, PP_Size* size) { | 1492 PP_Bool PluginInstance::GetScreenSize(PP_Instance instance, PP_Size* size) { |
| 1499 gfx::Size screen_size = delegate()->GetScreenSize(); | 1493 gfx::Size screen_size = delegate()->GetScreenSize(); |
| 1500 *size = PP_MakeSize(screen_size.width(), screen_size.height()); | 1494 *size = PP_MakeSize(screen_size.width(), screen_size.height()); |
| 1501 return PP_TRUE; | 1495 return PP_TRUE; |
| 1502 } | 1496 } |
| 1503 | 1497 |
| 1504 } // namespace ppapi | 1498 } // namespace ppapi |
| 1505 } // namespace webkit | 1499 } // namespace webkit |
| OLD | NEW |