aboutsummaryrefslogtreecommitdiffhomepage
path: root/samplecode
diff options
context:
space:
mode:
Diffstat (limited to 'samplecode')
-rw-r--r--samplecode/SampleApp.cpp146
-rw-r--r--samplecode/SampleApp.h1
2 files changed, 30 insertions, 117 deletions
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index 2cad753817..17e8623d4f 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -77,8 +77,6 @@ public:
SkTCPServer gServer;
#endif
-#define USE_ARROWS_FOR_ZOOM true
-
#if SK_ANGLE
//#define DEFAULT_TO_ANGLE 1
#else
@@ -795,7 +793,6 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
#endif
fUseClip = false;
- fNClip = false;
fAnimating = false;
fRotate = false;
fPerspAnim = false;
@@ -904,7 +901,6 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
fSlideMenu = new SkOSMenu;
this->addMenu(fSlideMenu);
- this->setColorType(kN32_SkColorType);
this->setVisibleP(true);
this->setClipToBounds(false);
@@ -965,30 +961,11 @@ static SkBitmap capture_bitmap(SkCanvas* canvas) {
return bm;
}
-static bool bitmap_diff(SkCanvas* canvas, const SkBitmap& orig,
- SkBitmap* diff) {
- SkBitmap src = capture_bitmap(canvas);
-
- SkAutoLockPixels alp0(src);
- SkAutoLockPixels alp1(orig);
- for (int y = 0; y < src.height(); y++) {
- const void* srcP = src.getAddr(0, y);
- const void* origP = orig.getAddr(0, y);
- size_t bytes = src.width() * src.bytesPerPixel();
- if (memcmp(srcP, origP, bytes)) {
- SkDebugf("---------- difference on line %d\n", y);
- return true;
- }
- }
- return false;
-}
-
-static void drawText(SkCanvas* canvas, SkString string, SkScalar left, SkScalar top, SkPaint& paint)
-{
+static void drawText(SkCanvas* canvas, SkString str, SkScalar left, SkScalar top, SkPaint& paint) {
SkColor desiredColor = paint.getColor();
paint.setColor(SK_ColorWHITE);
- const char* c_str = string.c_str();
- size_t size = string.size();
+ const char* c_str = str.c_str();
+ size_t size = str.size();
SkRect bounds;
paint.measureText(c_str, size, &bounds);
bounds.offset(left, top);
@@ -1017,70 +994,39 @@ void SampleWindow::draw(SkCanvas* canvas) {
fMeasureFPS_Time = 0;
}
- if (fNClip) {
- this->INHERITED::draw(canvas);
- SkBitmap orig = capture_bitmap(canvas);
+ SkSize tile = this->tileSize();
- const SkScalar w = this->width();
- const SkScalar h = this->height();
- const SkScalar cw = w / XCLIP_N;
- const SkScalar ch = h / YCLIP_N;
- for (int y = 0; y < YCLIP_N; y++) {
- SkRect r;
- r.fTop = y * ch;
- r.fBottom = (y + 1) * ch;
- if (y == YCLIP_N - 1) {
- r.fBottom = h;
- }
- for (int x = 0; x < XCLIP_N; x++) {
- SkAutoCanvasRestore acr(canvas, true);
- r.fLeft = x * cw;
- r.fRight = (x + 1) * cw;
- if (x == XCLIP_N - 1) {
- r.fRight = w;
- }
- canvas->clipRect(r);
- this->INHERITED::draw(canvas);
- }
- }
-
- SkBitmap diff;
- if (bitmap_diff(canvas, orig, &diff)) {
- }
+ if (kNo_Tiling == fTilingMode) {
+ this->INHERITED::draw(canvas); // no looping or surfaces needed
} else {
- SkSize tile = this->tileSize();
-
- if (kNo_Tiling == fTilingMode) {
- this->INHERITED::draw(canvas); // no looping or surfaces needed
- } else {
- const int w = SkScalarRoundToInt(tile.width());
- const int h = SkScalarRoundToInt(tile.height());
- SkImageInfo info = SkImageInfo::MakeN32Premul(w, h);
- SkAutoTUnref<SkSurface> surface(canvas->newSurface(info));
- SkCanvas* tileCanvas = surface->getCanvas();
-
- for (SkScalar y = 0; y < height(); y += tile.height()) {
- for (SkScalar x = 0; x < width(); x += tile.width()) {
- SkAutoCanvasRestore acr(tileCanvas, true);
- tileCanvas->translate(-x, -y);
- tileCanvas->clear(0);
- this->INHERITED::draw(tileCanvas);
- surface->draw(canvas, x, y, NULL);
- }
+ const int w = SkScalarRoundToInt(tile.width());
+ const int h = SkScalarRoundToInt(tile.height());
+ SkImageInfo info = SkImageInfo::MakeN32Premul(w, h);
+ SkAutoTUnref<SkSurface> surface(canvas->newSurface(info));
+ SkCanvas* tileCanvas = surface->getCanvas();
+
+ for (SkScalar y = 0; y < height(); y += tile.height()) {
+ for (SkScalar x = 0; x < width(); x += tile.width()) {
+ SkAutoCanvasRestore acr(tileCanvas, true);
+ tileCanvas->translate(-x, -y);
+ tileCanvas->clear(0);
+ this->INHERITED::draw(tileCanvas);
+ surface->draw(canvas, x, y, NULL);
}
+ }
- // for drawing the borders between tiles
- SkPaint paint;
- paint.setColor(0x60FF00FF);
- paint.setStyle(SkPaint::kStroke_Style);
+ // for drawing the borders between tiles
+ SkPaint paint;
+ paint.setColor(0x60FF00FF);
+ paint.setStyle(SkPaint::kStroke_Style);
- for (SkScalar y = 0; y < height(); y += tile.height()) {
- for (SkScalar x = 0; x < width(); x += tile.width()) {
- canvas->drawRect(SkRect::MakeXYWH(x, y, tile.width(), tile.height()), paint);
- }
+ for (SkScalar y = 0; y < height(); y += tile.height()) {
+ for (SkScalar x = 0; x < width(); x += tile.width()) {
+ canvas->drawRect(SkRect::MakeXYWH(x, y, tile.width(), tile.height()), paint);
}
}
}
+
if (fShowZoomer && !fSaveToPdf) {
showZoomer(canvas);
}
@@ -1396,20 +1342,6 @@ void SampleWindow::afterChild(SkView* child, SkCanvas* canvas) {
canvas->setDrawFilter(NULL);
}
-static SkColorType gColorTypeCycle[] = {
- kUnknown_SkColorType, // none -> none
- kUnknown_SkColorType, // a8 -> none
- kN32_SkColorType, // 565 -> 8888
- kN32_SkColorType, // 4444 -> 8888
- kRGB_565_SkColorType, // 8888 -> 565
- kRGB_565_SkColorType, // 8888 -> 565
- kUnknown_SkColorType, // index8 -> none
-};
-
-static SkColorType cycle_colortypes(SkColorType c) {
- return gColorTypeCycle[c];
-}
-
void SampleWindow::changeZoomLevel(float delta) {
fZoomLevel += delta;
if (fZoomLevel > 0) {
@@ -1512,10 +1444,6 @@ bool SampleWindow::onEvent(const SkEvent& evt) {
}
return true;
}
- if (evt.isType("replace-transition-view")) {
- this->loadView((SkView*)SkEventSink::FindSink(evt.getFast32()));
- return true;
- }
if (evt.isType("set-curr-index")) {
this->goToSample(evt.getFast32());
return true;
@@ -1798,21 +1726,10 @@ bool SampleWindow::onHandleKey(SkKey key) {
}
return true;
case kUp_SkKey:
- if (USE_ARROWS_FOR_ZOOM) {
- this->changeZoomLevel(1.f / 32.f);
- } else {
- fNClip = !fNClip;
- this->inval(NULL);
- this->updateTitle();
- }
+ this->changeZoomLevel(1.f / 32.f);
return true;
case kDown_SkKey:
- if (USE_ARROWS_FOR_ZOOM) {
- this->changeZoomLevel(-1.f / 32.f);
- } else {
- this->setColorType(cycle_colortypes(this->getBitmap().colorType()));
- this->updateTitle();
- }
+ this->changeZoomLevel(-1.f / 32.f);
return true;
case kOK_SkKey: {
SkString title;
@@ -1979,9 +1896,6 @@ void SampleWindow::updateTitle() {
if (fRotate) {
title.prepend("<R> ");
}
- if (fNClip) {
- title.prepend("<C> ");
- }
if (fPerspAnim) {
title.prepend("<K> ");
}
diff --git a/samplecode/SampleApp.h b/samplecode/SampleApp.h
index 4e2cb6fe48..2385fc010b 100644
--- a/samplecode/SampleApp.h
+++ b/samplecode/SampleApp.h
@@ -174,7 +174,6 @@ private:
SkAutoTUnref<SkDocument> fPDFDocument;
bool fUseClip;
- bool fNClip;
bool fAnimating;
bool fRotate;
bool fPerspAnim;