| 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 | 7 |
| 8 #include "SampleApp.h" | 8 #include "SampleApp.h" |
| 9 | 9 |
| 10 #include "OverView.h" | 10 #include "OverView.h" |
| (...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1000 static SkBitmap capture_bitmap(SkCanvas* canvas) { | 1000 static SkBitmap capture_bitmap(SkCanvas* canvas) { |
| 1001 SkBitmap bm; | 1001 SkBitmap bm; |
| 1002 if (bm.allocPixels(canvas->imageInfo())) { | 1002 if (bm.allocPixels(canvas->imageInfo())) { |
| 1003 canvas->readPixels(&bm, 0, 0); | 1003 canvas->readPixels(&bm, 0, 0); |
| 1004 } | 1004 } |
| 1005 return bm; | 1005 return bm; |
| 1006 } | 1006 } |
| 1007 | 1007 |
| 1008 static bool bitmap_diff(SkCanvas* canvas, const SkBitmap& orig, | 1008 static bool bitmap_diff(SkCanvas* canvas, const SkBitmap& orig, |
| 1009 SkBitmap* diff) { | 1009 SkBitmap* diff) { |
| 1010 const SkBitmap& src = canvas->getDevice()->accessBitmap(false); | 1010 SkBitmap src = capture_bitmap(canvas); |
| 1011 | 1011 |
| 1012 SkAutoLockPixels alp0(src); | 1012 SkAutoLockPixels alp0(src); |
| 1013 SkAutoLockPixels alp1(orig); | 1013 SkAutoLockPixels alp1(orig); |
| 1014 for (int y = 0; y < src.height(); y++) { | 1014 for (int y = 0; y < src.height(); y++) { |
| 1015 const void* srcP = src.getAddr(0, y); | 1015 const void* srcP = src.getAddr(0, y); |
| 1016 const void* origP = orig.getAddr(0, y); | 1016 const void* origP = orig.getAddr(0, y); |
| 1017 size_t bytes = src.width() * src.bytesPerPixel(); | 1017 size_t bytes = src.width() * src.bytesPerPixel(); |
| 1018 if (memcmp(srcP, origP, bytes)) { | 1018 if (memcmp(srcP, origP, bytes)) { |
| 1019 SkDebugf("---------- difference on line %d\n", y); | 1019 SkDebugf("---------- difference on line %d\n", y); |
| 1020 return true; | 1020 return true; |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1275 #include "SkColorPriv.h" | 1275 #include "SkColorPriv.h" |
| 1276 | 1276 |
| 1277 void SampleWindow::saveToPdf() | 1277 void SampleWindow::saveToPdf() |
| 1278 { | 1278 { |
| 1279 fSaveToPdf = true; | 1279 fSaveToPdf = true; |
| 1280 this->inval(NULL); | 1280 this->inval(NULL); |
| 1281 } | 1281 } |
| 1282 | 1282 |
| 1283 SkCanvas* SampleWindow::beforeChildren(SkCanvas* canvas) { | 1283 SkCanvas* SampleWindow::beforeChildren(SkCanvas* canvas) { |
| 1284 if (fSaveToPdf) { | 1284 if (fSaveToPdf) { |
| 1285 const SkBitmap& bmp = canvas->getDevice()->accessBitmap(false); | 1285 const SkBitmap bmp = capture_bitmap(canvas); |
| 1286 SkISize size = SkISize::Make(bmp.width(), bmp.height()); | 1286 SkISize size = SkISize::Make(bmp.width(), bmp.height()); |
| 1287 SkPDFDevice* pdfDevice = new SkPDFDevice(size, size, | 1287 SkPDFDevice* pdfDevice = new SkPDFDevice(size, size, |
| 1288 canvas->getTotalMatrix()); | 1288 canvas->getTotalMatrix()); |
| 1289 fPdfCanvas = new SkCanvas(pdfDevice); | 1289 fPdfCanvas = new SkCanvas(pdfDevice); |
| 1290 pdfDevice->unref(); | 1290 pdfDevice->unref(); |
| 1291 canvas = fPdfCanvas; | 1291 canvas = fPdfCanvas; |
| 1292 } else if (kPicture_DeviceType == fDeviceType) { | 1292 } else if (kPicture_DeviceType == fDeviceType) { |
| 1293 canvas = fRecorder.beginRecording(9999, 9999, NULL, 0); | 1293 canvas = fRecorder.beginRecording(9999, 9999, NULL, 0); |
| 1294 } else { | 1294 } else { |
| 1295 #if SK_SUPPORT_GPU | 1295 #if SK_SUPPORT_GPU |
| 1296 if (kNullGPU_DeviceType != fDeviceType) | 1296 if (kNullGPU_DeviceType != fDeviceType) |
| 1297 #endif | 1297 #endif |
| 1298 { | 1298 { |
| 1299 canvas = this->INHERITED::beforeChildren(canvas); | 1299 canvas = this->INHERITED::beforeChildren(canvas); |
| 1300 } | 1300 } |
| 1301 } | 1301 } |
| 1302 | 1302 |
| 1303 if (fUseClip) { | 1303 if (fUseClip) { |
| 1304 canvas->drawColor(0xFFFF88FF); | 1304 canvas->drawColor(0xFFFF88FF); |
| 1305 canvas->clipPath(fClipPath, SkRegion::kIntersect_Op, true); | 1305 canvas->clipPath(fClipPath, SkRegion::kIntersect_Op, true); |
| 1306 } | 1306 } |
| 1307 | 1307 |
| 1308 return canvas; | 1308 return canvas; |
| 1309 } | 1309 } |
| 1310 | 1310 |
| 1311 static void paint_rgn(const SkBitmap& bm, const SkIRect& r, | |
| 1312 const SkRegion& rgn) { | |
| 1313 SkCanvas canvas(bm); | |
| 1314 SkRegion inval(rgn); | |
| 1315 | |
| 1316 inval.translate(r.fLeft, r.fTop); | |
| 1317 canvas.clipRegion(inval); | |
| 1318 canvas.drawColor(0xFFFF8080); | |
| 1319 } | |
| 1320 #include "SkData.h" | 1311 #include "SkData.h" |
| 1321 void SampleWindow::afterChildren(SkCanvas* orig) { | 1312 void SampleWindow::afterChildren(SkCanvas* orig) { |
| 1322 if (fSaveToPdf) { | 1313 if (fSaveToPdf) { |
| 1323 fSaveToPdf = false; | 1314 fSaveToPdf = false; |
| 1324 if (fShowZoomer) { | 1315 if (fShowZoomer) { |
| 1325 showZoomer(fPdfCanvas); | 1316 showZoomer(fPdfCanvas); |
| 1326 } | 1317 } |
| 1327 SkString name; | 1318 SkString name; |
| 1328 name.printf("%s.pdf", this->getTitle()); | 1319 name.printf("%s.pdf", this->getTitle()); |
| 1329 SkPDFDocument doc; | 1320 SkPDFDocument doc; |
| 1330 SkPDFDevice* device = static_cast<SkPDFDevice*>(fPdfCanvas->getDevice())
; | 1321 SkPDFDevice* device = NULL;//static_cast<SkPDFDevice*>(fPdfCanvas->getDe
vice()); |
| 1322 SkASSERT(false); |
| 1331 doc.appendPage(device); | 1323 doc.appendPage(device); |
| 1332 #ifdef SK_BUILD_FOR_ANDROID | 1324 #ifdef SK_BUILD_FOR_ANDROID |
| 1333 name.prepend("/sdcard/"); | 1325 name.prepend("/sdcard/"); |
| 1334 #endif | 1326 #endif |
| 1335 | 1327 |
| 1336 #ifdef SK_BUILD_FOR_IOS | 1328 #ifdef SK_BUILD_FOR_IOS |
| 1337 SkDynamicMemoryWStream mstream; | 1329 SkDynamicMemoryWStream mstream; |
| 1338 doc.emitPDF(&mstream); | 1330 doc.emitPDF(&mstream); |
| 1339 fPDFData = mstream.copyToData(); | 1331 fPDFData = mstream.copyToData(); |
| 1340 #endif | 1332 #endif |
| 1341 SkFILEWStream stream(name.c_str()); | 1333 SkFILEWStream stream(name.c_str()); |
| 1342 if (stream.isValid()) { | 1334 if (stream.isValid()) { |
| 1343 doc.emitPDF(&stream); | 1335 doc.emitPDF(&stream); |
| 1344 const char* desc = "File saved from Skia SampleApp"; | 1336 const char* desc = "File saved from Skia SampleApp"; |
| 1345 this->onPDFSaved(this->getTitle(), desc, name.c_str()); | 1337 this->onPDFSaved(this->getTitle(), desc, name.c_str()); |
| 1346 } | 1338 } |
| 1347 | 1339 |
| 1348 delete fPdfCanvas; | 1340 delete fPdfCanvas; |
| 1349 fPdfCanvas = NULL; | 1341 fPdfCanvas = NULL; |
| 1350 | 1342 |
| 1351 // We took over the draw calls in order to create the PDF, so we need | 1343 // We took over the draw calls in order to create the PDF, so we need |
| 1352 // to redraw. | 1344 // to redraw. |
| 1353 this->inval(NULL); | 1345 this->inval(NULL); |
| 1354 return; | 1346 return; |
| 1355 } | 1347 } |
| 1356 | 1348 |
| 1357 if (fRequestGrabImage) { | 1349 if (fRequestGrabImage) { |
| 1358 fRequestGrabImage = false; | 1350 fRequestGrabImage = false; |
| 1359 | 1351 |
| 1360 SkBaseDevice* device = orig->getDevice(); | 1352 SkBitmap bmp = capture_bitmap(orig); |
| 1361 SkBitmap bmp; | 1353 if (!bmp.isNull()) { |
| 1362 if (device->accessBitmap(false).copyTo(&bmp, kN32_SkColorType)) { | |
| 1363 static int gSampleGrabCounter; | 1354 static int gSampleGrabCounter; |
| 1364 SkString name; | 1355 SkString name; |
| 1365 name.printf("sample_grab_%d.png", gSampleGrabCounter++); | 1356 name.printf("sample_grab_%d.png", gSampleGrabCounter++); |
| 1366 SkImageEncoder::EncodeFile(name.c_str(), bmp, | 1357 SkImageEncoder::EncodeFile(name.c_str(), bmp, |
| 1367 SkImageEncoder::kPNG_Type, 100); | 1358 SkImageEncoder::kPNG_Type, 100); |
| 1368 } | 1359 } |
| 1369 } | 1360 } |
| 1370 | 1361 |
| 1371 if (kPicture_DeviceType == fDeviceType) { | 1362 if (kPicture_DeviceType == fDeviceType) { |
| 1372 SkAutoTUnref<SkPicture> picture(fRecorder.endRecording()); | 1363 SkAutoTUnref<SkPicture> picture(fRecorder.endRecording()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1388 } | 1379 } |
| 1389 } else { | 1380 } else { |
| 1390 picture->draw(orig); | 1381 picture->draw(orig); |
| 1391 } | 1382 } |
| 1392 } | 1383 } |
| 1393 | 1384 |
| 1394 // Do this after presentGL and other finishing, rather than in afterChild | 1385 // Do this after presentGL and other finishing, rather than in afterChild |
| 1395 if (fMeasureFPS && fMeasureFPS_StartTime) { | 1386 if (fMeasureFPS && fMeasureFPS_StartTime) { |
| 1396 fMeasureFPS_Time += SkTime::GetMSecs() - fMeasureFPS_StartTime; | 1387 fMeasureFPS_Time += SkTime::GetMSecs() - fMeasureFPS_StartTime; |
| 1397 } | 1388 } |
| 1398 | |
| 1399 // if ((fScrollTestX | fScrollTestY) != 0) | |
| 1400 if (false) { | |
| 1401 const SkBitmap& bm = orig->getDevice()->accessBitmap(true); | |
| 1402 int dx = fScrollTestX * 7; | |
| 1403 int dy = fScrollTestY * 7; | |
| 1404 SkIRect r; | |
| 1405 SkRegion inval; | |
| 1406 | |
| 1407 r.set(50, 50, 50+100, 50+100); | |
| 1408 bm.scrollRect(&r, dx, dy, &inval); | |
| 1409 paint_rgn(bm, r, inval); | |
| 1410 } | |
| 1411 } | 1389 } |
| 1412 | 1390 |
| 1413 void SampleWindow::beforeChild(SkView* child, SkCanvas* canvas) { | 1391 void SampleWindow::beforeChild(SkView* child, SkCanvas* canvas) { |
| 1414 if (fRotate) { | 1392 if (fRotate) { |
| 1415 fRotateAnimTime += SampleCode::GetAnimSecondsDelta(); | 1393 fRotateAnimTime += SampleCode::GetAnimSecondsDelta(); |
| 1416 | 1394 |
| 1417 SkScalar cx = this->width() / 2; | 1395 SkScalar cx = this->width() / 2; |
| 1418 SkScalar cy = this->height() / 2; | 1396 SkScalar cy = this->height() / 2; |
| 1419 canvas->translate(cx, cy); | 1397 canvas->translate(cx, cy); |
| 1420 canvas->rotate(fRotateAnimTime * 10); | 1398 canvas->rotate(fRotateAnimTime * 10); |
| (...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2250 | 2228 |
| 2251 fAtomsWritten += 1; | 2229 fAtomsWritten += 1; |
| 2252 } | 2230 } |
| 2253 | 2231 |
| 2254 void SampleView::draw(SkCanvas* canvas) { | 2232 void SampleView::draw(SkCanvas* canvas) { |
| 2255 if (SkOSMenu::kOffState == fPipeState) { | 2233 if (SkOSMenu::kOffState == fPipeState) { |
| 2256 this->INHERITED::draw(canvas); | 2234 this->INHERITED::draw(canvas); |
| 2257 } else { | 2235 } else { |
| 2258 SkGPipeWriter writer; | 2236 SkGPipeWriter writer; |
| 2259 SimplePC controller(canvas); | 2237 SimplePC controller(canvas); |
| 2260 TiledPipeController tc(canvas->getDevice()->accessBitmap(false), | 2238 SkBitmap bitmap = capture_bitmap(canvas); |
| 2261 &SkImageDecoder::DecodeMemory, | 2239 TiledPipeController tc(bitmap, &SkImageDecoder::DecodeMemory, &canvas->g
etTotalMatrix()); |
| 2262 &canvas->getTotalMatrix()); | |
| 2263 SkGPipeController* pc; | 2240 SkGPipeController* pc; |
| 2264 if (SkOSMenu::kMixedState == fPipeState) { | 2241 if (SkOSMenu::kMixedState == fPipeState) { |
| 2265 pc = &tc; | 2242 pc = &tc; |
| 2266 } else { | 2243 } else { |
| 2267 pc = &controller; | 2244 pc = &controller; |
| 2268 } | 2245 } |
| 2269 uint32_t flags = SkGPipeWriter::kCrossProcess_Flag; | 2246 uint32_t flags = SkGPipeWriter::kCrossProcess_Flag; |
| 2270 | 2247 |
| 2271 canvas = writer.startRecording(pc, flags); | 2248 canvas = writer.startRecording(pc, flags); |
| 2272 //Must draw before controller goes out of scope and sends data | 2249 //Must draw before controller goes out of scope and sends data |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2425 SkGraphics::Init(); | 2402 SkGraphics::Init(); |
| 2426 SkEvent::Init(); | 2403 SkEvent::Init(); |
| 2427 } | 2404 } |
| 2428 | 2405 |
| 2429 // FIXME: this should be in a header | 2406 // FIXME: this should be in a header |
| 2430 void application_term(); | 2407 void application_term(); |
| 2431 void application_term() { | 2408 void application_term() { |
| 2432 SkEvent::Term(); | 2409 SkEvent::Term(); |
| 2433 SkGraphics::Term(); | 2410 SkGraphics::Term(); |
| 2434 } | 2411 } |
| OLD | NEW |