| OLD | NEW |
| 1 /* |
| 2 * Copyright 2011 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 1 #include "SkCanvas.h" | 7 #include "SkCanvas.h" |
| 2 #include "SkCGUtils.h" | 8 #include "SkCGUtils.h" |
| 3 #include "SkGraphics.h" | 9 #include "SkGraphics.h" |
| 4 #include "SkImageDecoder.h" | 10 #include "SkImageDecoder.h" |
| 5 #include "SkOSFile.h" | 11 #include "SkOSFile.h" |
| 6 #include "SkPaint.h" | 12 #include "SkPaint.h" |
| 7 #include "SkPicture.h" | 13 #include "SkPicture.h" |
| 8 #include "SkStream.h" | 14 #include "SkStream.h" |
| 9 #include "SkWindow.h" | 15 #include "SkWindow.h" |
| 10 | 16 |
| 11 static void make_filepath(SkString* path, const char* dir, const SkString& name)
{ | 17 static void make_filepath(SkString* path, const char* dir, const SkString& name)
{ |
| 12 size_t len = strlen(dir); | 18 size_t len = strlen(dir); |
| 13 path->set(dir); | 19 path->set(dir); |
| 14 if (len > 0 && dir[len - 1] != '/') { | 20 if (len > 0 && dir[len - 1] != '/') { |
| 15 path->append("/"); | 21 path->append("/"); |
| 16 } | 22 } |
| 17 path->append(name); | 23 path->append(name); |
| 18 } | 24 } |
| 19 | 25 |
| 20 static SkPicture* LoadPicture(const char path[]) { | 26 static SkPicture* LoadPicture(const char path[]) { |
| 21 SkPicture* pic = NULL; | 27 SkPicture* pic = NULL; |
| 22 | 28 |
| 23 SkBitmap bm; | 29 SkBitmap bm; |
| 24 if (SkImageDecoder::DecodeFile(path, &bm)) { | 30 if (SkImageDecoder::DecodeFile(path, &bm)) { |
| 25 bm.setImmutable(); | 31 bm.setImmutable(); |
| 26 pic = SkNEW(SkPicture); | 32 pic = new SkPicture; |
| 27 SkCanvas* can = pic->beginRecording(bm.width(), bm.height()); | 33 SkCanvas* can = pic->beginRecording(bm.width(), bm.height()); |
| 28 can->drawBitmap(bm, 0, 0, NULL); | 34 can->drawBitmap(bm, 0, 0, NULL); |
| 29 pic->endRecording(); | 35 pic->endRecording(); |
| 30 } else { | 36 } else { |
| 31 SkFILEStream stream(path); | 37 SkFILEStream stream(path); |
| 32 if (stream.isValid()) { | 38 if (stream.isValid()) { |
| 33 pic = SkNEW_ARGS(SkPicture, | 39 pic = new SkPicture(&stream, NULL, &SkImageDecoder::DecodeStream); |
| 34 (&stream, NULL, &SkImageDecoder::DecodeStream)); | |
| 35 } | 40 } |
| 36 | 41 |
| 37 if (false) { // re-record | 42 if (false) { // re-record |
| 38 SkPicture p2; | 43 SkPicture p2; |
| 39 pic->draw(p2.beginRecording(pic->width(), pic->height())); | 44 pic->draw(p2.beginRecording(pic->width(), pic->height())); |
| 40 p2.endRecording(); | 45 p2.endRecording(); |
| 41 | 46 |
| 42 SkString path2(path); | 47 SkString path2(path); |
| 43 path2.append(".new.skp"); | 48 path2.append(".new.skp"); |
| 44 SkFILEWStream writer(path2.c_str()); | 49 SkFILEWStream writer(path2.c_str()); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 SkString filename; | 245 SkString filename; |
| 241 PathCanvas canvas; | 246 PathCanvas canvas; |
| 242 canvas.init(); | 247 canvas.init(); |
| 243 while (iter.next(&filename)) { | 248 while (iter.next(&filename)) { |
| 244 SkString path; | 249 SkString path; |
| 245 // if (true) filename.set("tabl_www_sahadan_com.skp"); | 250 // if (true) filename.set("tabl_www_sahadan_com.skp"); |
| 246 make_filepath(&path, pictDir, filename); | 251 make_filepath(&path, pictDir, filename); |
| 247 canvas.divName(filename, false); | 252 canvas.divName(filename, false); |
| 248 SkPicture* pic = LoadPicture(path.c_str()); | 253 SkPicture* pic = LoadPicture(path.c_str()); |
| 249 pic->draw(&canvas); | 254 pic->draw(&canvas); |
| 250 SkDELETE(pic); | 255 delete pic; |
| 251 } | 256 } |
| 252 SkDebugf("\n</div>\n\n"); | 257 SkDebugf("\n</div>\n\n"); |
| 253 | 258 |
| 254 SkDebugf("<script type=\"text/javascript\">\n\n"); | 259 SkDebugf("<script type=\"text/javascript\">\n\n"); |
| 255 SkDebugf("var testDivs = [\n"); | 260 SkDebugf("var testDivs = [\n"); |
| 256 | 261 |
| 257 iter.reset(pictDir, "skp"); | 262 iter.reset(pictDir, "skp"); |
| 258 while (iter.next(&filename)) { | 263 while (iter.next(&filename)) { |
| 259 SkString path; | 264 SkString path; |
| 260 make_filepath(&path, pictDir, filename); | 265 make_filepath(&path, pictDir, filename); |
| 261 canvas.divName(filename, true); | 266 canvas.divName(filename, true); |
| 262 SkPicture* pic = LoadPicture(path.c_str()); | 267 SkPicture* pic = LoadPicture(path.c_str()); |
| 263 pic->draw(&canvas); | 268 pic->draw(&canvas); |
| 264 SkDELETE(pic); | 269 delete pic; |
| 265 } | 270 } |
| 266 SkDebugf("];\n\n"); | 271 SkDebugf("];\n\n"); |
| 267 | 272 |
| 268 SkDebugf("points min=%d max=%d verbs min=%d max=%d\n", canvas.pointsMin, can
vas.pointsMax, | 273 SkDebugf("points min=%d max=%d verbs min=%d max=%d\n", canvas.pointsMin, can
vas.pointsMax, |
| 269 canvas.verbsMin, canvas.verbsMax); | 274 canvas.verbsMin, canvas.verbsMax); |
| 270 SkDebugf("rect points min=%d max=%d verbs min=%d max=%d\n", canvas.rectPoint
sMin, canvas.rectPointsMax, | 275 SkDebugf("rect points min=%d max=%d verbs min=%d max=%d\n", canvas.rectPoint
sMin, canvas.rectPointsMax, |
| 271 canvas.rectVerbsMin, canvas.rectVerbsMax); | 276 canvas.rectVerbsMin, canvas.rectVerbsMax); |
| 272 | 277 |
| 273 SkDebugf("\n"); | 278 SkDebugf("\n"); |
| 274 } | 279 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 297 } | 302 } |
| 298 return self; | 303 return self; |
| 299 } | 304 } |
| 300 | 305 |
| 301 - (void)drawRect:(NSRect)dirtyRect { | 306 - (void)drawRect:(NSRect)dirtyRect { |
| 302 CGContextRef ctx = (CGContextRef)[[NSGraphicsContext currentContext] graphic
sPort]; | 307 CGContextRef ctx = (CGContextRef)[[NSGraphicsContext currentContext] graphic
sPort]; |
| 303 SkCGDrawBitmap(ctx, fWind->getBitmap(), 0, 0); | 308 SkCGDrawBitmap(ctx, fWind->getBitmap(), 0, 0); |
| 304 } | 309 } |
| 305 | 310 |
| 306 @end | 311 @end |
| OLD | NEW |