blob: 23d8c5a01f844a2885649f90ab033b4ebcffa7ae [file] [log] [blame]
caryclark@google.coma5764232012-03-28 16:20:21 +00001#include "EdgeDemo.h"
caryclark@google.comd88e0892012-03-27 13:23:51 +00002#import "SkCanvas.h"
caryclark@google.comd88e0892012-03-27 13:23:51 +00003#import "SkWindow.h"
4#include "SkGraphics.h"
5#include "SkCGUtils.h"
6
caryclark@google.com03f97062012-08-21 13:13:52 +00007#include <time.h>
8#include <sys/time.h>
9
caryclark@google.comd88e0892012-03-27 13:23:51 +000010class SkSampleView : public SkView {
11public:
12 SkSampleView() {
13 this->setVisibleP(true);
14 this->setClipToBounds(false);
caryclark@google.com9e49fb62012-08-27 14:11:33 +000015 useOld = true;
caryclark@google.comd88e0892012-03-27 13:23:51 +000016 };
17protected:
18 virtual void onDraw(SkCanvas* canvas) {
caryclark@google.comc899ad92012-08-23 15:24:42 +000019 static int step = 0; // useNew triggers error at 23275
20 // error is not easy to debug in its current state
caryclark@google.com03f97062012-08-21 13:13:52 +000021 static double seconds;
caryclark@google.com03f97062012-08-21 13:13:52 +000022 if (step == -1) {
23 timeval t;
24 gettimeofday(&t, NULL);
25 seconds = t.tv_sec+t.tv_usec/1000000.0;
26 step = 0;
27 }
caryclark@google.coma5764232012-03-28 16:20:21 +000028 canvas->drawColor(SK_ColorWHITE);
caryclark@google.com03f97062012-08-21 13:13:52 +000029 if (DrawEdgeDemo(canvas, step, useOld)) {
caryclark@google.coma5764232012-03-28 16:20:21 +000030 ++step;
caryclark@google.comc899ad92012-08-23 15:24:42 +000031 if (step == 23270) {
caryclark@google.com03f97062012-08-21 13:13:52 +000032 timeval t;
33 gettimeofday(&t, NULL);
34 double last = seconds;
35 seconds = t.tv_sec+t.tv_usec/1000000.0;
36 SkDebugf("old=%d seconds=%g\n", useOld, seconds - last);
37 useOld ^= true;
38 step = 0;
39 }
caryclark@google.coma5764232012-03-28 16:20:21 +000040 inval(NULL);
caryclark@google.comd88e0892012-03-27 13:23:51 +000041 }
42 }
caryclark@google.com9e49fb62012-08-27 14:11:33 +000043
44 virtual Click* onFindClickHandler(SkScalar , SkScalar ) {
45 useOld ^= true;
46 return NULL;
47 }
48
caryclark@google.comd88e0892012-03-27 13:23:51 +000049private:
caryclark@google.com9e49fb62012-08-27 14:11:33 +000050 bool useOld;
caryclark@google.comd88e0892012-03-27 13:23:51 +000051 typedef SkView INHERITED;
52};
53
caryclark@google.comc899ad92012-08-23 15:24:42 +000054void application_init();
55void application_term();
56
caryclark@google.comd88e0892012-03-27 13:23:51 +000057void application_init() {
58 SkGraphics::Init();
59 SkEvent::Init();
60}
61
62void application_term() {
63 SkGraphics::Term();
64 SkEvent::Term();
65}
66
67class FillLayout : public SkView::Layout {
68protected:
69 virtual void onLayoutChildren(SkView* parent) {
70 SkView* view = SkView::F2BIter(parent).next();
71 view->setSize(parent->width(), parent->height());
72 }
73};
74
75#import "SimpleApp.h"
caryclark@google.coma5764232012-03-28 16:20:21 +000076
caryclark@google.comd88e0892012-03-27 13:23:51 +000077@implementation SimpleNSView
78
79- (id)initWithDefaults {
caryclark@google.comc899ad92012-08-23 15:24:42 +000080 if ((self = [super initWithDefaults])) {
caryclark@google.comd88e0892012-03-27 13:23:51 +000081 fWind = new SkOSWindow(self);
82 fWind->setLayout(new FillLayout, false);
83 fWind->attachChildToFront(new SkSampleView)->unref();
84 }
85 return self;
86}
87
88- (void)drawRect:(NSRect)dirtyRect {
89 CGContextRef ctx = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
90 SkCGDrawBitmap(ctx, fWind->getBitmap(), 0, 0);
91}
92
93@end