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

Side by Side Diff: samplecode/SampleApp.cpp

Issue 684923002: MultiPictureDraw is taskgroup aware. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: actually call Reset() to free the data in each data Created 6 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « include/core/SkMultiPictureDraw.h ('k') | src/core/SkMultiPictureDraw.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 DEFINE_string(slide, "", "Start on this sample."); 735 DEFINE_string(slide, "", "Start on this sample.");
736 DEFINE_int32(msaa, 0, "Request multisampling with this count."); 736 DEFINE_int32(msaa, 0, "Request multisampling with this count.");
737 DEFINE_string(pictureDir, "", "Read pictures from here."); 737 DEFINE_string(pictureDir, "", "Read pictures from here.");
738 DEFINE_string(picture, "", "Path to single picture."); 738 DEFINE_string(picture, "", "Path to single picture.");
739 DEFINE_bool(sort, false, "Sort samples by title."); 739 DEFINE_bool(sort, false, "Sort samples by title.");
740 DEFINE_bool(list, false, "List samples?"); 740 DEFINE_bool(list, false, "List samples?");
741 #ifdef SAMPLE_PDF_FILE_VIEWER 741 #ifdef SAMPLE_PDF_FILE_VIEWER
742 DEFINE_string(pdfPath, "", "Path to direcotry of pdf files."); 742 DEFINE_string(pdfPath, "", "Path to direcotry of pdf files.");
743 #endif 743 #endif
744 744
745 #include "SkTaskGroup.h"
746
745 SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev Manager) 747 SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev Manager)
746 : INHERITED(hwnd) 748 : INHERITED(hwnd)
747 , fDevManager(NULL) { 749 , fDevManager(NULL) {
748 750
749 SkCommandLineFlags::Parse(argc, argv); 751 SkCommandLineFlags::Parse(argc, argv);
750 752
751 fCurrIndex = -1; 753 fCurrIndex = -1;
752 754
753 if (!FLAGS_pictureDir.isEmpty()) { 755 if (!FLAGS_pictureDir.isEmpty()) {
754 SkOSFile::Iter iter(FLAGS_pictureDir[0], "skp"); 756 SkOSFile::Iter iter(FLAGS_pictureDir[0], "skp");
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 SkString title; 808 SkString title;
807 if (readTitleFromPrefs(&title)) { 809 if (readTitleFromPrefs(&title)) {
808 fCurrIndex = findByTitle(title.c_str()); 810 fCurrIndex = findByTitle(title.c_str());
809 } 811 }
810 } 812 }
811 813
812 if (fCurrIndex < 0) { 814 if (fCurrIndex < 0) {
813 fCurrIndex = 0; 815 fCurrIndex = 0;
814 } 816 }
815 817
818 static SkTaskGroup::Enabler enabled(-1);
816 gSampleWindow = this; 819 gSampleWindow = this;
817 820
818 #ifdef PIPE_FILE 821 #ifdef PIPE_FILE
819 //Clear existing file or create file if it doesn't exist 822 //Clear existing file or create file if it doesn't exist
820 FILE* f = fopen(FILE_PATH, "wb"); 823 FILE* f = fopen(FILE_PATH, "wb");
821 fclose(f); 824 fclose(f);
822 #endif 825 #endif
823 826
824 fDeviceType = kRaster_DeviceType; 827 fDeviceType = kRaster_DeviceType;
825 828
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
1299 } 1302 }
1300 } 1303 }
1301 1304
1302 if (fUseClip) { 1305 if (fUseClip) {
1303 canvas->drawColor(0xFFFF88FF); 1306 canvas->drawColor(0xFFFF88FF);
1304 canvas->clipPath(fClipPath, SkRegion::kIntersect_Op, true); 1307 canvas->clipPath(fClipPath, SkRegion::kIntersect_Op, true);
1305 } 1308 }
1306 1309
1307 return canvas; 1310 return canvas;
1308 } 1311 }
1309 1312 #include "SkMultiPictureDraw.h"
1310 void SampleWindow::afterChildren(SkCanvas* orig) { 1313 void SampleWindow::afterChildren(SkCanvas* orig) {
1311 if (fSaveToPdf) { 1314 if (fSaveToPdf) {
1312 fSaveToPdf = false; 1315 fSaveToPdf = false;
1313 fPDFDocument->endPage(); 1316 fPDFDocument->endPage();
1314 fPDFDocument.reset(NULL); 1317 fPDFDocument.reset(NULL);
1315 // We took over the draw calls in order to create the PDF, so we need 1318 // We took over the draw calls in order to create the PDF, so we need
1316 // to redraw. 1319 // to redraw.
1317 this->inval(NULL); 1320 this->inval(NULL);
1318 return; 1321 return;
1319 } 1322 }
1320 1323
1321 if (fRequestGrabImage) { 1324 if (fRequestGrabImage) {
1322 fRequestGrabImage = false; 1325 fRequestGrabImage = false;
1323 1326
1324 SkBitmap bmp = capture_bitmap(orig); 1327 SkBitmap bmp = capture_bitmap(orig);
1325 if (!bmp.isNull()) { 1328 if (!bmp.isNull()) {
1326 static int gSampleGrabCounter; 1329 static int gSampleGrabCounter;
1327 SkString name; 1330 SkString name;
1328 name.printf("sample_grab_%d.png", gSampleGrabCounter++); 1331 name.printf("sample_grab_%d.png", gSampleGrabCounter++);
1329 SkImageEncoder::EncodeFile(name.c_str(), bmp, 1332 SkImageEncoder::EncodeFile(name.c_str(), bmp,
1330 SkImageEncoder::kPNG_Type, 100); 1333 SkImageEncoder::kPNG_Type, 100);
1331 } 1334 }
1332 } 1335 }
1333 1336
1334 if (kPicture_DeviceType == fDeviceType) { 1337 if (kPicture_DeviceType == fDeviceType) {
1335 SkAutoTUnref<const SkPicture> picture(fRecorder.endRecording()); 1338 SkAutoTUnref<const SkPicture> picture(fRecorder.endRecording());
1336 1339
1337 if (true) { 1340 if (true) {
1338 this->installDrawFilter(orig); 1341 this->installDrawFilter(orig);
1339 orig->drawPicture(picture); 1342
1343 if (true) {
1344 SkImageInfo info;
1345 size_t rowBytes;
1346 void* addr = orig->accessTopLayerPixels(&info, &rowBytes);
1347 if (addr) {
1348 SkSurface* surfs[4];
1349 SkMultiPictureDraw md;
1350
1351 SkImageInfo n = SkImageInfo::Make(info.width()/2, info.heigh t()/2,
1352 info.colorType(), info.alp haType());
1353 int index = 0;
1354 for (int y = 0; y < 2; ++y) {
1355 for (int x = 0; x < 2; ++x) {
1356 char* p = (char*)addr;
1357 p += y * n.height() * rowBytes;
1358 p += x * n.width() * sizeof(SkPMColor);
1359 surfs[index] = SkSurface::NewRasterDirect(n, p, rowB ytes);
1360 SkCanvas* c = surfs[index]->getCanvas();
1361 c->translate(SkIntToScalar(-x * n.width()),
1362 SkIntToScalar(-y * n.height()));
1363 md.add(c, picture, NULL, NULL);
1364 index++;
1365 }
1366 }
1367 md.draw();
1368 for (int i = 0; i < 4; ++i) {
1369 surfs[i]->unref();
1370 }
1371 }
1372 } else {
1373 orig->drawPicture(picture);
1374 }
1340 } else if (true) { 1375 } else if (true) {
1341 SkDynamicMemoryWStream ostream; 1376 SkDynamicMemoryWStream ostream;
1342 picture->serialize(&ostream); 1377 picture->serialize(&ostream);
1343 1378
1344 SkAutoDataUnref data(ostream.copyToData()); 1379 SkAutoDataUnref data(ostream.copyToData());
1345 SkMemoryStream istream(data->data(), data->size()); 1380 SkMemoryStream istream(data->data(), data->size());
1346 SkAutoTUnref<SkPicture> pict(SkPicture::CreateFromStream(&istream)); 1381 SkAutoTUnref<SkPicture> pict(SkPicture::CreateFromStream(&istream));
1347 if (pict.get() != NULL) { 1382 if (pict.get() != NULL) {
1348 orig->drawPicture(pict.get()); 1383 orig->drawPicture(pict.get());
1349 } 1384 }
(...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after
2394 setenv("ANDROID_ROOT", "/android/device/data", 0); 2429 setenv("ANDROID_ROOT", "/android/device/data", 0);
2395 #endif 2430 #endif
2396 SkGraphics::Init(); 2431 SkGraphics::Init();
2397 SkEvent::Init(); 2432 SkEvent::Init();
2398 } 2433 }
2399 2434
2400 void application_term() { 2435 void application_term() {
2401 SkEvent::Term(); 2436 SkEvent::Term();
2402 SkGraphics::Term(); 2437 SkGraphics::Term();
2403 } 2438 }
OLDNEW
« no previous file with comments | « include/core/SkMultiPictureDraw.h ('k') | src/core/SkMultiPictureDraw.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698