Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ppapi/cpp/dev/printing_dev.h" | |
| 6 #include "ppapi/cpp/image_data.h" | |
| 7 #include "ppapi/cpp/instance.h" | |
| 8 #include "ppapi/cpp/module.h" | |
| 9 #include "ppapi/cpp/rect.h" | |
| 10 #include "ppapi/utility/completion_callback_factory.h" | |
| 11 | |
| 12 namespace { | |
| 13 | |
| 14 void FillRect(pp::ImageData* image, int left, int top, int width, int height, | |
| 15 uint32_t color) { | |
| 16 for (int y = std::max(0, top); | |
| 17 y < std::min(image->size().height(), top + height); | |
| 18 y++) { | |
| 19 for (int x = std::max(0, left); | |
| 20 x < std::min(image->size().width(), left + width); | |
| 21 x++) | |
| 22 *image->GetAddr32(pp::Point(x, y)) = color; | |
| 23 } | |
| 24 } | |
| 25 | |
| 26 } // namespace | |
| 27 | |
| 28 class MyInstance : public pp::Instance, public pp::Printing_Dev { | |
| 29 public: | |
| 30 explicit MyInstance(PP_Instance instance) | |
| 31 : pp::Instance(instance), | |
| 32 pp::Printing_Dev(this) { | |
| 33 } | |
| 34 virtual ~MyInstance() {} | |
| 35 | |
| 36 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { | |
| 37 return true; | |
| 38 } | |
| 39 | |
| 40 virtual uint32_t QuerySupportedPrintOutputFormats() { | |
| 41 return PP_PRINTOUTPUTFORMAT_RASTER; | |
| 42 } | |
| 43 | |
| 44 virtual int32_t PrintBegin(const PP_PrintSettings_Dev& print_settings) { | |
| 45 return 1; | |
| 46 } | |
| 47 | |
| 48 virtual pp::Resource PrintPages( | |
| 49 const PP_PrintPageNumberRange_Dev* page_ranges, | |
| 50 uint32_t page_range_count) { | |
| 51 pp::Size size(100, 100); | |
| 52 pp::ImageData image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, size, true); | |
| 53 FillRect(&image, 0, 0, size.width(), size.height(), 0xFFFFFFFF); | |
|
viettrungluu
2012/02/28 00:11:43
This will blow up in spectacular fashion if the im
| |
| 54 | |
| 55 FillRect(&image, 0, 0, 10, 10, 0xFF000000); | |
| 56 FillRect(&image, size.width() - 11, size.height() - 11, 10, 10, 0xFF000000); | |
| 57 return image; | |
| 58 } | |
| 59 | |
| 60 virtual void PrintEnd() { | |
| 61 } | |
| 62 | |
| 63 virtual bool IsPrintScalingDisabled() { | |
| 64 return true; | |
| 65 } | |
| 66 }; | |
| 67 | |
| 68 class MyModule : public pp::Module { | |
| 69 public: | |
| 70 MyModule() : pp::Module() {} | |
| 71 virtual ~MyModule() {} | |
| 72 | |
| 73 // Override CreateInstance to create your customized Instance object. | |
| 74 virtual pp::Instance* CreateInstance(PP_Instance instance) { | |
| 75 return new MyInstance(instance); | |
| 76 } | |
| 77 }; | |
| 78 | |
| 79 namespace pp { | |
| 80 | |
| 81 // Factory function for your specialization of the Module object. | |
| 82 Module* CreateModule() { | |
| 83 return new MyModule(); | |
| 84 } | |
| 85 | |
| 86 } // namespace pp | |
| 87 | |
| OLD | NEW |