1 #include "EdgeDemo.h" 2 #import "SkCanvas.h" 3 #import "SkWindow.h" 4 #include "SkGraphics.h" 5 #include "SkCGUtils.h" 6 7 #include <time.h> 8 #include <sys/time.h> 9 10 class SkSampleView : public SkView { 11 public: 12 SkSampleView() { 13 this->setVisibleP(true); 14 this->setClipToBounds(false); 15 useOld = false; 16 }; 17 protected: 18 virtual void onDraw(SkCanvas* canvas) { 19 static int step = 0; // 17907 drawLetters first error 20 // drawStars triggers error at 33348 21 // drawStars error not easy to debug last time I checked 22 static double seconds; 23 if (step == -1) { 24 timeval t; 25 gettimeofday(&t, NULL); 26 seconds = t.tv_sec+t.tv_usec/1000000.0; 27 step = 0; 28 } 29 canvas->drawColor(SK_ColorWHITE); 30 if (DrawEdgeDemo(canvas, step, useOld)) { 31 ++step; 32 if (step == -1) { 33 timeval t; 34 gettimeofday(&t, NULL); 35 double last = seconds; 36 seconds = t.tv_sec+t.tv_usec/1000000.0; 37 SkDebugf("old=%d seconds=%g\n", useOld, seconds - last); 38 useOld ^= true; 39 step = 0; 40 } 41 inval(NULL); 42 } 43 } 44 45 virtual Click* onFindClickHandler(SkScalar , SkScalar ) { 46 useOld ^= true; 47 return NULL; 48 } 49 50 private: 51 bool useOld; 52 typedef SkView INHERITED; 53 }; 54 55 void application_init(); 56 void application_term(); 57 58 void application_init() { 59 SkGraphics::Init(); 60 SkEvent::Init(); 61 } 62 63 void application_term() { 64 SkGraphics::Term(); 65 SkEvent::Term(); 66 } 67 68 class FillLayout : public SkView::Layout { 69 protected: 70 virtual void onLayoutChildren(SkView* parent) { 71 SkView* view = SkView::F2BIter(parent).next(); 72 view->setSize(parent->width(), parent->height()); 73 } 74 }; 75 76 #import "SimpleApp.h" 77 78 @implementation SimpleNSView 79 80 - (id)initWithDefaults { 81 if ((self = [super initWithDefaults])) { 82 fWind = new SkOSWindow(self); 83 fWind->setLayout(new FillLayout, false); 84 fWind->attachChildToFront(new SkSampleView)->unref(); 85 } 86 return self; 87 } 88 89 - (void)drawRect:(NSRect)dirtyRect { 90 CGContextRef ctx = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; 91 SkCGDrawBitmap(ctx, fWind->getBitmap(), 0, 0); 92 } 93 94 @end 95