Added Debugger to Sample App, off by default
Removed CocoaDebugger from experimental
Slight changes to SkOSMenu
Bug fixes for NetPipeReader and DrawingBoard
git-svn-id: http://skia.googlecode.com/svn/trunk@2102 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/experimental/DrawingBoard/SampleDrawingClient.cpp b/experimental/DrawingBoard/SampleDrawingClient.cpp
index 9885d51..02b7a3b 100644
--- a/experimental/DrawingBoard/SampleDrawingClient.cpp
+++ b/experimental/DrawingBoard/SampleDrawingClient.cpp
@@ -8,7 +8,32 @@
#include "SkColorPalette.h"
#include "SkOSMenu.h"
+
+/**
+ * Drawing Client
+ *
+ * A drawing client that allows a user to perform simple brush stokes with
+ * a selected color and brush size. The drawing client communicates with a
+ * drawing server to send/receive data to/from other clients connected to the
+ * same server. The drawing client stores data in fData and fBuffer depending on
+ * the data type. Append type means that the drawing data is a completed stroke
+ * and Replace type means that the drawing data is in progress and will be
+ * replaced by subsequent data. fData and fBuffer are read by a pipe reader and
+ * reproduce the drawing. When the client is in a normal state, the data stored
+ * on the client and the server should be identical.
+ * The drawing client is also able to switch between vector and bitmap drawing.
+ * The drawing client also renders the latest drawing stroke locally in order to
+ * produce better reponses. This can be disabled by calling
+ * controller.disablePlayBack(), which will introduce a lag between the input
+ * and the drawing.
+ * Note: in order to keep up with the drawing data, the client will try to read
+ * a few times each frame in case more than one frame worth of data has been
+ * received and render them together. This behavior can be adjusted by tweaking
+ * MAX_READ_PER_FRAME or disabled by turning fSync to false
+ */
+
#define MAX_READ_PER_FRAME 5
+
class DrawingClientView : public SampleView {
public:
DrawingClientView() {
@@ -22,8 +47,8 @@
fBrushSize = SkFloatToScalar(2.5);
fAA = false;
fPaletteVisible = true;
- fSync = false;
- fVector = false;
+ fSync = true;
+ fVector = true;
}
~DrawingClientView() {
if (fSocket) {
@@ -35,11 +60,14 @@
virtual void requestMenu(SkOSMenu* menu) {
menu->setTitle("Drawing Client");
- menu->appendTextField("Server IP", "Server IP", this->getSinkID(), "IP address or hostname");
+ menu->appendTextField("Server IP", "Server IP", this->getSinkID(),
+ "IP address or hostname");
menu->appendSwitch("Vector", "Vector", this->getSinkID(), fVector);
- menu->appendSlider("Brush Size", "Brush Size", this->getSinkID(), 1.0, 100.0, fBrushSize);
+ menu->appendSlider("Brush Size", "Brush Size", this->getSinkID(), 1.0,
+ 100.0, fBrushSize);
menu->appendSwitch("Anti-Aliasing", "AA", this->getSinkID(), fAA);
- menu->appendSwitch("Show Color Palette", "Palette", this->getSinkID(), fPaletteVisible);
+ menu->appendSwitch("Show Color Palette", "Palette", this->getSinkID(),
+ fPaletteVisible);
menu->appendSwitch("Sync", "Sync", this->getSinkID(), fSync);
menu->appendAction("Clear", this->getSinkID());
}
@@ -75,11 +103,11 @@
}
bool onEvent(const SkEvent& evt) {;
- if (SkOSMenu::FindSliderValue(&evt, "Brush Size", &fBrushSize))
+ if (SkOSMenu::FindSliderValue(evt, "Brush Size", &fBrushSize))
return true;
SkString s;
- if (SkOSMenu::FindText(&evt, "Server IP", &s)) {
+ if (SkOSMenu::FindText(evt, "Server IP", &s)) {
if (NULL != fSocket) {
delete fSocket;
}
@@ -92,18 +120,18 @@
this->inval(NULL);
return true;
}
- if (SkOSMenu::FindSwitchState(&evt, "AA", &fAA) ||
- SkOSMenu::FindSwitchState(&evt, "Sync", &fSync))
+ if (SkOSMenu::FindSwitchState(evt, "AA", &fAA) ||
+ SkOSMenu::FindSwitchState(evt, "Sync", &fSync))
return true;
- if (SkOSMenu::FindSwitchState(&evt, "Vector", &fVector)) {
+ if (SkOSMenu::FindSwitchState(evt, "Vector", &fVector)) {
this->clearBitmap();
return true;
}
- if (SkOSMenu::FindAction(&evt, "Clear")) {
+ if (SkOSMenu::FindAction(evt, "Clear")) {
this->clear();
return true;
}
- if (SkOSMenu::FindSwitchState(&evt, "Palette", &fPaletteVisible)) {
+ if (SkOSMenu::FindSwitchState(evt, "Palette", &fPaletteVisible)) {
fPalette->setVisibleP(fPaletteVisible);
return true;
}
@@ -150,6 +178,7 @@
fSocket->connectToServer();
}
size_t bytesRead = 0;
+ SkGPipeReader::Status status;
SkCanvas bufferCanvas(fBase);
SkCanvas* tempCanvas;
while (fTotalBytesRead < fData.count()) {
@@ -157,10 +186,10 @@
tempCanvas = canvas;
else
tempCanvas = &bufferCanvas;
- SkGPipeReader reader(tempCanvas);
- SkGPipeReader::Status status = reader.playback(fData.begin() + fTotalBytesRead,
- fData.count() - fTotalBytesRead,
- &bytesRead);
+ SkGPipeReader reader(tempCanvas);
+ status = reader.playback(fData.begin() + fTotalBytesRead,
+ fData.count() - fTotalBytesRead,
+ &bytesRead);
SkASSERT(SkGPipeReader::kError_Status != status);
fTotalBytesRead += bytesRead;
}
@@ -172,10 +201,10 @@
size_t totalBytesRead = 0;
while (totalBytesRead < fBuffer.count()) {
SkGPipeReader reader(canvas);
- reader.playback(fBuffer.begin() + totalBytesRead,
- fBuffer.count() - totalBytesRead,
- &bytesRead);
-
+ status = reader.playback(fBuffer.begin() + totalBytesRead,
+ fBuffer.count() - totalBytesRead,
+ &bytesRead);
+ SkASSERT(SkGPipeReader::kError_Status != status);
totalBytesRead += bytesRead;
}