OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 #include "SampleApp.h" | 7 #include "SampleApp.h" |
8 | 8 |
9 #include "SkData.h" | 9 #include "SkData.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkDevice.h" | 11 #include "SkDevice.h" |
12 #include "SkGraphics.h" | 12 #include "SkGraphics.h" |
13 #include "SkImageDecoder.h" | 13 #include "SkImageDecoder.h" |
14 #include "SkImageEncoder.h" | 14 #include "SkImageEncoder.h" |
15 #include "SkPaint.h" | 15 #include "SkPaint.h" |
16 #include "SkPicture.h" | 16 #include "SkPicture.h" |
17 #include "SkPictureRecorder.h" | 17 #include "SkPictureRecorder.h" |
18 #include "SkStream.h" | 18 #include "SkStream.h" |
| 19 #include "SkSurface.h" |
19 #include "SkTSort.h" | 20 #include "SkTSort.h" |
20 #include "SkTime.h" | 21 #include "SkTime.h" |
21 #include "SkWindow.h" | 22 #include "SkWindow.h" |
22 | 23 |
23 #include "SampleCode.h" | 24 #include "SampleCode.h" |
24 #include "SkTypeface.h" | 25 #include "SkTypeface.h" |
25 | 26 |
26 #if SK_SUPPORT_GPU | 27 #if SK_SUPPORT_GPU |
27 #include "gl/GrGLInterface.h" | 28 #include "gl/GrGLInterface.h" |
28 #include "gl/GrGLUtil.h" | 29 #include "gl/GrGLUtil.h" |
(...skipping 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1185 this->INHERITED::draw(canvas); | 1186 this->INHERITED::draw(canvas); |
1186 } | 1187 } |
1187 } | 1188 } |
1188 | 1189 |
1189 SkBitmap diff; | 1190 SkBitmap diff; |
1190 if (bitmap_diff(canvas, orig, &diff)) { | 1191 if (bitmap_diff(canvas, orig, &diff)) { |
1191 } | 1192 } |
1192 } else { | 1193 } else { |
1193 SkSize tile = this->tileSize(); | 1194 SkSize tile = this->tileSize(); |
1194 | 1195 |
1195 for (SkScalar y = 0; y < height(); y += tile.height()) { | 1196 if (kNo_Tiling == fTilingMode) { |
1196 for (SkScalar x = 0; x < width(); x += tile.width()) { | 1197 this->INHERITED::draw(canvas); // no looping or surfaces needed |
1197 SkAutoCanvasRestore acr(canvas, true); | 1198 } else { |
1198 canvas->clipRect(SkRect::MakeXYWH(x, y, | 1199 const int w = SkScalarRoundToInt(tile.width()); |
1199 tile.width(), | 1200 const int h = SkScalarRoundToInt(tile.height()); |
1200 tile.height())); | 1201 SkImageInfo info = SkImageInfo::MakeN32Premul(w, h); |
1201 this->INHERITED::draw(canvas); | 1202 SkAutoTUnref<SkSurface> surface(canvas->newSurface(info)); |
| 1203 SkCanvas* tileCanvas = surface->getCanvas(); |
| 1204 |
| 1205 for (SkScalar y = 0; y < height(); y += tile.height()) { |
| 1206 for (SkScalar x = 0; x < width(); x += tile.width()) { |
| 1207 SkAutoCanvasRestore acr(tileCanvas, true); |
| 1208 tileCanvas->translate(-x, -y); |
| 1209 tileCanvas->clear(0); |
| 1210 this->INHERITED::draw(tileCanvas); |
| 1211 surface->draw(canvas, x, y, NULL); |
| 1212 } |
1202 } | 1213 } |
1203 } | |
1204 | 1214 |
1205 if (fTilingMode != kNo_Tiling) { | 1215 // for drawing the borders between tiles |
1206 SkPaint paint; | 1216 SkPaint paint; |
1207 paint.setColor(0x60FF00FF); | 1217 paint.setColor(0x60FF00FF); |
1208 paint.setStyle(SkPaint::kStroke_Style); | 1218 paint.setStyle(SkPaint::kStroke_Style); |
1209 | 1219 |
1210 for (SkScalar y = 0; y < height(); y += tile.height()) { | 1220 for (SkScalar y = 0; y < height(); y += tile.height()) { |
1211 for (SkScalar x = 0; x < width(); x += tile.width()) { | 1221 for (SkScalar x = 0; x < width(); x += tile.width()) { |
1212 canvas->drawRect(SkRect::MakeXYWH(x, y, | 1222 canvas->drawRect(SkRect::MakeXYWH(x, y, tile.width(), tile.h
eight()), paint); |
1213 tile.width(), | |
1214 tile.height()), | |
1215 paint); | |
1216 } | 1223 } |
1217 } | 1224 } |
1218 } | 1225 } |
1219 } | 1226 } |
1220 if (fShowZoomer && !fSaveToPdf) { | 1227 if (fShowZoomer && !fSaveToPdf) { |
1221 showZoomer(canvas); | 1228 showZoomer(canvas); |
1222 } | 1229 } |
1223 if (fMagnify && !fSaveToPdf) { | 1230 if (fMagnify && !fSaveToPdf) { |
1224 magnify(canvas); | 1231 magnify(canvas); |
1225 } | 1232 } |
(...skipping 1332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2558 SkGraphics::Init(); | 2565 SkGraphics::Init(); |
2559 SkEvent::Init(); | 2566 SkEvent::Init(); |
2560 } | 2567 } |
2561 | 2568 |
2562 // FIXME: this should be in a header | 2569 // FIXME: this should be in a header |
2563 void application_term(); | 2570 void application_term(); |
2564 void application_term() { | 2571 void application_term() { |
2565 SkEvent::Term(); | 2572 SkEvent::Term(); |
2566 SkGraphics::Term(); | 2573 SkGraphics::Term(); |
2567 } | 2574 } |
OLD | NEW |