blob: e3be2ca9f3884cb0a38d4263109ffc6329f05569 [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);
15 };
16protected:
17 virtual void onDraw(SkCanvas* canvas) {
caryclark@google.com03f97062012-08-21 13:13:52 +000018 static int step = -1;
19 static double seconds;
20 static bool useOld = true;
21 if (step == -1) {
22 timeval t;
23 gettimeofday(&t, NULL);
24 seconds = t.tv_sec+t.tv_usec/1000000.0;
25 step = 0;
26 }
caryclark@google.coma5764232012-03-28 16:20:21 +000027 canvas->drawColor(SK_ColorWHITE);
caryclark@google.com03f97062012-08-21 13:13:52 +000028 if (DrawEdgeDemo(canvas, step, useOld)) {
caryclark@google.coma5764232012-03-28 16:20:21 +000029 ++step;
caryclark@google.com03f97062012-08-21 13:13:52 +000030 if (step == 3200) {
31 timeval t;
32 gettimeofday(&t, NULL);
33 double last = seconds;
34 seconds = t.tv_sec+t.tv_usec/1000000.0;
35 SkDebugf("old=%d seconds=%g\n", useOld, seconds - last);
36 useOld ^= true;
37 step = 0;
38 }
caryclark@google.coma5764232012-03-28 16:20:21 +000039 inval(NULL);
caryclark@google.comd88e0892012-03-27 13:23:51 +000040 }
41 }
caryclark@google.comd88e0892012-03-27 13:23:51 +000042private:
43 typedef SkView INHERITED;
44};
45
46void application_init() {
47 SkGraphics::Init();
48 SkEvent::Init();
49}
50
51void application_term() {
52 SkGraphics::Term();
53 SkEvent::Term();
54}
55
56class FillLayout : public SkView::Layout {
57protected:
58 virtual void onLayoutChildren(SkView* parent) {
59 SkView* view = SkView::F2BIter(parent).next();
60 view->setSize(parent->width(), parent->height());
61 }
62};
63
64#import "SimpleApp.h"
caryclark@google.coma5764232012-03-28 16:20:21 +000065
caryclark@google.comd88e0892012-03-27 13:23:51 +000066@implementation SimpleNSView
67
68- (id)initWithDefaults {
69 if (self = [super initWithDefaults]) {
70 fWind = new SkOSWindow(self);
71 fWind->setLayout(new FillLayout, false);
72 fWind->attachChildToFront(new SkSampleView)->unref();
73 }
74 return self;
75}
76
77- (void)drawRect:(NSRect)dirtyRect {
78 CGContextRef ctx = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
79 SkCGDrawBitmap(ctx, fWind->getBitmap(), 0, 0);
80}
81
82@end