| Index: platform_tools/nacl/src/nacl_hello.cpp
|
| ===================================================================
|
| --- platform_tools/nacl/src/nacl_hello.cpp (revision 9611)
|
| +++ platform_tools/nacl/src/nacl_hello.cpp (working copy)
|
| @@ -15,11 +15,9 @@
|
| #include "ppapi/cpp/rect.h"
|
| #include "ppapi/cpp/var.h"
|
|
|
| -#include "SkBase64.h"
|
| #include "SkBitmap.h"
|
| #include "SkCanvas.h"
|
| #include "SkColor.h"
|
| -#include "SkDebugger.h"
|
| #include "SkGraphics.h"
|
| #include "SkStream.h"
|
| #include "SkString.h"
|
| @@ -31,16 +29,26 @@
|
|
|
| void FlushCallback(void* data, int32_t result);
|
|
|
| +static void doDraw(SkCanvas* canvas, const SkPaint& paint, const char text[]) {
|
| + canvas->drawColor(SK_ColorWHITE);
|
| + SkPaint red;
|
| + red.setColor(SK_ColorRED);
|
| + canvas->drawCircle(150.0, 150.0, 100.0, red);
|
| + SkRect bounds;
|
| + canvas->getClipBounds(&bounds);
|
| + canvas->drawText(text, strlen(text),
|
| + bounds.centerX(), bounds.centerY(),
|
| + paint);
|
| +}
|
| +
|
| // Skia's subclass of pp::Instance, our interface with the browser.
|
| class SkiaInstance : public pp::Instance {
|
| public:
|
| explicit SkiaInstance(PP_Instance instance)
|
| : pp::Instance(instance)
|
| , fCanvas(NULL)
|
| - , fPicture(NULL)
|
| , fFlushLoopRunning(false)
|
| , fFlushPending(false)
|
| -
|
| {
|
| gPluginInstance = this;
|
| SkGraphics::Init();
|
| @@ -53,92 +61,16 @@
|
|
|
| virtual void HandleMessage(const pp::Var& var_message) {
|
| // Receive a message from javascript.
|
| - if (var_message.is_string()) {
|
| - SkString msg(var_message.AsString().c_str());
|
| - if (msg.startsWith("init")) {
|
| - } else if (msg.startsWith("LoadSKP")) {
|
| - size_t startIndex = strlen("LoadSKP");
|
| - size_t dataSize = msg.size()/sizeof(char) - startIndex;
|
| - SkBase64 decodedData;
|
| - decodedData.decode(msg.c_str() + startIndex, dataSize);
|
| - size_t decodedSize = 3 * (dataSize / 4);
|
| - SkDebugf("Got size: %d\n", decodedSize);
|
| - if (!decodedData.getData()) {
|
| - SkDebugf("Failed to decode SKP\n");
|
| - return;
|
| - }
|
| - SkMemoryStream pictureStream(decodedData.getData(), decodedSize);
|
| - fPicture = new SkPicture(&pictureStream);
|
| - if (fPicture->width() == 0 || fPicture->height() == 0) {
|
| - SkDebugf("Failed to create SKP.\n");
|
| - return;
|
| - }
|
| - fDebugger.loadPicture(fPicture);
|
| -
|
| - // Set up the command list.
|
| - SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsStrings();
|
| - PostMessage("ClearCommands");
|
| - for (int i = 0; i < commands->count(); ++i) {
|
| - SkString addCommand("AddCommand:");
|
| - addCommand.append((*commands)[i]);
|
| - PostMessage(addCommand.c_str());
|
| - }
|
| - PostMessage("UpdateCommands");
|
| -
|
| - // Set the overview text.
|
| - SkString overviewText;
|
| - fDebugger.getOverviewText(NULL, 0.0, &overviewText, 1);
|
| - overviewText.prepend("SetOverview:");
|
| - PostMessage(overviewText.c_str());
|
| -
|
| - // Draw the SKP.
|
| - if (!fFlushLoopRunning) {
|
| - Paint();
|
| - }
|
| - } else if (msg.startsWith("CommandSelected:")) {
|
| - size_t startIndex = strlen("CommandSelected:");
|
| - int index = atoi(msg.c_str() + startIndex);
|
| - fDebugger.setIndex(index);
|
| - if (!fFlushLoopRunning) {
|
| - Paint();
|
| - }
|
| - } else if (msg.startsWith("Rewind")) {
|
| - fCanvas->clear(SK_ColorWHITE);
|
| - fDebugger.setIndex(0);
|
| - if (!fFlushLoopRunning) {
|
| - Paint();
|
| - }
|
| - } else if (msg.startsWith("StepBack")) {
|
| - fCanvas->clear(SK_ColorWHITE);
|
| - int currentIndex = fDebugger.index();
|
| - if (currentIndex > 1) {
|
| - fDebugger.setIndex(currentIndex - 1);
|
| - if (!fFlushLoopRunning) {
|
| - Paint();
|
| - }
|
| - }
|
| - } else if (msg.startsWith("Pause")) {
|
| - // TODO(borenet)
|
| - } else if (msg.startsWith("StepForward")) {
|
| - int currentIndex = fDebugger.index();
|
| - if (currentIndex < fDebugger.getSize() -1) {
|
| - fDebugger.setIndex(currentIndex + 1);
|
| - if (!fFlushLoopRunning) {
|
| - Paint();
|
| - }
|
| - }
|
| - } else if (msg.startsWith("Play")) {
|
| - fDebugger.setIndex(fDebugger.getSize() - 1);
|
| - if (!fFlushLoopRunning) {
|
| - Paint();
|
| - }
|
| - }
|
| - }
|
| }
|
|
|
| void Paint() {
|
| if (!fImage.is_null()) {
|
| - fDebugger.draw(fCanvas);
|
| + SkPaint paint;
|
| + paint.setAntiAlias(true);
|
| + paint.setTextSize(SkIntToScalar(30));
|
| + paint.setTextAlign(SkPaint::kCenter_Align);
|
| + doDraw(fCanvas, paint, "Hello");
|
| +
|
| fDeviceContext.PaintImageData(fImage, pp::Point(0, 0));
|
| if (!fFlushPending) {
|
| fFlushPending = true;
|
| @@ -158,7 +90,6 @@
|
| }
|
| fWidth = position.size().width();
|
| fHeight = position.size().height();
|
| -
|
| fDeviceContext = pp::Graphics2D(this, pp::Size(fWidth, fHeight), false);
|
| if (!BindGraphics(fDeviceContext)) {
|
| SkDebugf("Couldn't bind the device context\n");
|
| @@ -193,8 +124,6 @@
|
|
|
| SkBitmap fBitmap;
|
| SkCanvas* fCanvas;
|
| - SkDebugger fDebugger;
|
| - SkPicture* fPicture;
|
|
|
| bool fFlushLoopRunning;
|
| bool fFlushPending;
|
|
|