| OLD | NEW |
| 1 #include <cstdio> | 1 |
| 2 #include <string> | 2 /* |
| 3 * Copyright 2013 Google Inc. |
| 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. |
| 7 */ |
| 3 | 8 |
| 4 #include "ppapi/cpp/completion_callback.h" | 9 #include "ppapi/cpp/completion_callback.h" |
| 5 #include "ppapi/cpp/graphics_2d.h" | 10 #include "ppapi/cpp/graphics_2d.h" |
| 6 #include "ppapi/cpp/image_data.h" | 11 #include "ppapi/cpp/image_data.h" |
| 7 #include "ppapi/cpp/instance.h" | 12 #include "ppapi/cpp/instance.h" |
| 8 #include "ppapi/cpp/module.h" | 13 #include "ppapi/cpp/module.h" |
| 9 #include "ppapi/cpp/point.h" | 14 #include "ppapi/cpp/point.h" |
| 10 #include "ppapi/cpp/rect.h" | 15 #include "ppapi/cpp/rect.h" |
| 11 #include "ppapi/cpp/var.h" | 16 #include "ppapi/cpp/var.h" |
| 12 | 17 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 24 // Used by SkDebugf | 29 // Used by SkDebugf |
| 25 SkiaInstance* gPluginInstance; | 30 SkiaInstance* gPluginInstance; |
| 26 | 31 |
| 27 void FlushCallback(void* data, int32_t result); | 32 void FlushCallback(void* data, int32_t result); |
| 28 | 33 |
| 29 // Skia's subclass of pp::Instance, our interface with the browser. | 34 // Skia's subclass of pp::Instance, our interface with the browser. |
| 30 class SkiaInstance : public pp::Instance { | 35 class SkiaInstance : public pp::Instance { |
| 31 public: | 36 public: |
| 32 explicit SkiaInstance(PP_Instance instance) | 37 explicit SkiaInstance(PP_Instance instance) |
| 33 : pp::Instance(instance) | 38 : pp::Instance(instance) |
| 34 , fBitmap() | |
| 35 , fCanvas(NULL) | 39 , fCanvas(NULL) |
| 36 , fDebugger() | 40 , fPicture(NULL) |
| 37 , fImage() | |
| 38 , fFlushLoopRunning(false) | 41 , fFlushLoopRunning(false) |
| 39 , fFlushPending(false) | 42 , fFlushPending(false) |
| 40 , fPicture(NULL) | 43 |
| 41 { | 44 { |
| 42 gPluginInstance = this; | 45 gPluginInstance = this; |
| 43 SkGraphics::Init(); | 46 SkGraphics::Init(); |
| 44 } | 47 } |
| 45 | 48 |
| 46 virtual ~SkiaInstance() { | 49 virtual ~SkiaInstance() { |
| 47 SkGraphics::Term(); | 50 SkGraphics::Term(); |
| 48 gPluginInstance = NULL; | 51 gPluginInstance = NULL; |
| 49 } | 52 } |
| 50 | 53 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 64 SkDebugf("Failed to decode SKP\n"); | 67 SkDebugf("Failed to decode SKP\n"); |
| 65 return; | 68 return; |
| 66 } | 69 } |
| 67 SkMemoryStream pictureStream(decodedData.getData(), decodedSize)
; | 70 SkMemoryStream pictureStream(decodedData.getData(), decodedSize)
; |
| 68 fPicture = new SkPicture(&pictureStream); | 71 fPicture = new SkPicture(&pictureStream); |
| 69 if (fPicture->width() == 0 || fPicture->height() == 0) { | 72 if (fPicture->width() == 0 || fPicture->height() == 0) { |
| 70 SkDebugf("Failed to create SKP.\n"); | 73 SkDebugf("Failed to create SKP.\n"); |
| 71 return; | 74 return; |
| 72 } | 75 } |
| 73 fDebugger.loadPicture(fPicture); | 76 fDebugger.loadPicture(fPicture); |
| 77 |
| 78 // Set up the command list. |
| 74 SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsString
s(); | 79 SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsString
s(); |
| 75 PostMessage("ClearCommands"); | 80 PostMessage("ClearCommands"); |
| 76 for (int i = 0; i < commands->count(); ++i) { | 81 for (int i = 0; i < commands->count(); ++i) { |
| 77 SkString message("AddCommand:"); | 82 SkString addCommand("AddCommand:"); |
| 78 message.append((*commands)[i]); | 83 addCommand.append((*commands)[i]); |
| 79 PostMessage(message.c_str()); | 84 PostMessage(addCommand.c_str()); |
| 80 } | 85 } |
| 86 PostMessage("UpdateCommands"); |
| 87 |
| 88 // Set the overview text. |
| 89 SkString overviewText; |
| 90 fDebugger.getOverviewText(NULL, 0.0, &overviewText); |
| 91 overviewText.prepend("SetOverview:"); |
| 92 PostMessage(overviewText.c_str()); |
| 93 |
| 94 // Draw the SKP. |
| 81 if (!fFlushLoopRunning) { | 95 if (!fFlushLoopRunning) { |
| 82 Paint(); | 96 Paint(); |
| 83 } | 97 } |
| 84 } else if (msg.startsWith("CommandSelected:")) { | 98 } else if (msg.startsWith("CommandSelected:")) { |
| 85 size_t startIndex = strlen("CommandSelected:"); | 99 size_t startIndex = strlen("CommandSelected:"); |
| 86 int index = atoi(msg.c_str() + startIndex); | 100 int index = atoi(msg.c_str() + startIndex); |
| 87 fDebugger.setIndex(index); | 101 fDebugger.setIndex(index); |
| 88 if (!fFlushLoopRunning) { | 102 if (!fFlushLoopRunning) { |
| 89 Paint(); | 103 Paint(); |
| 90 } | 104 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 virtual pp::Instance* CreateInstance(PP_Instance instance) { | 212 virtual pp::Instance* CreateInstance(PP_Instance instance) { |
| 199 return new SkiaInstance(instance); | 213 return new SkiaInstance(instance); |
| 200 } | 214 } |
| 201 }; | 215 }; |
| 202 | 216 |
| 203 namespace pp { | 217 namespace pp { |
| 204 Module* CreateModule() { | 218 Module* CreateModule() { |
| 205 return new SkiaModule(); | 219 return new SkiaModule(); |
| 206 } | 220 } |
| 207 } // namespace pp | 221 } // namespace pp |
| OLD | NEW |