Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(295)

Unified Diff: samplecode/SampleApp.cpp

Issue 303403003: using real tiles when simulating tiling (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: put no_tiling case first Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gm/bitmaprect.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samplecode/SampleApp.cpp
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index 473220e7943f8e49ffda1d32a5887d7c411f659e..ad03feacc8d5803cbd96bf19434565df1a9f77ee 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -16,6 +16,7 @@
#include "SkPicture.h"
#include "SkPictureRecorder.h"
#include "SkStream.h"
+#include "SkSurface.h"
#include "SkTSort.h"
#include "SkTime.h"
#include "SkWindow.h"
@@ -1192,27 +1193,33 @@ void SampleWindow::draw(SkCanvas* canvas) {
} else {
SkSize tile = this->tileSize();
- for (SkScalar y = 0; y < height(); y += tile.height()) {
- for (SkScalar x = 0; x < width(); x += tile.width()) {
- SkAutoCanvasRestore acr(canvas, true);
- canvas->clipRect(SkRect::MakeXYWH(x, y,
- tile.width(),
- tile.height()));
- this->INHERITED::draw(canvas);
+ 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);
+ }
}
- }
- if (fTilingMode != kNo_Tiling) {
+ // 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);
+ canvas->drawRect(SkRect::MakeXYWH(x, y, tile.width(), tile.height()), paint);
}
}
}
« no previous file with comments | « gm/bitmaprect.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698