blob: f5ed426eb0d9c6e260941a391232583bf90d34d9 [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.comc899ad92012-08-23 15:24:42 +000018 static int step = 0; // useNew triggers error at 23275
19 // error is not easy to debug in its current state
caryclark@google.com03f97062012-08-21 13:13:52 +000020 static double seconds;
caryclark@google.comc899ad92012-08-23 15:24:42 +000021 static bool useOld = false;
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.comd88e0892012-03-27 13:23:51 +000043private:
44 typedef SkView INHERITED;
45};
46
caryclark@google.comc899ad92012-08-23 15:24:42 +000047void application_init();
48void application_term();
49
caryclark@google.comd88e0892012-03-27 13:23:51 +000050void application_init() {
51 SkGraphics::Init();
52 SkEvent::Init();
53}
54
55void application_term() {
56 SkGraphics::Term();
57 SkEvent::Term();
58}
59
60class FillLayout : public SkView::Layout {
61protected:
62 virtual void onLayoutChildren(SkView* parent) {
63 SkView* view = SkView::F2BIter(parent).next();
64 view->setSize(parent->width(), parent->height());
65 }
66};
67
68#import "SimpleApp.h"
caryclark@google.coma5764232012-03-28 16:20:21 +000069
caryclark@google.comd88e0892012-03-27 13:23:51 +000070@implementation SimpleNSView
71
72- (id)initWithDefaults {
caryclark@google.comc899ad92012-08-23 15:24:42 +000073 if ((self = [super initWithDefaults])) {
caryclark@google.comd88e0892012-03-27 13:23:51 +000074 fWind = new SkOSWindow(self);
75 fWind->setLayout(new FillLayout, false);
76 fWind->attachChildToFront(new SkSampleView)->unref();
77 }
78 return self;
79}
80
81- (void)drawRect:(NSRect)dirtyRect {
82 CGContextRef ctx = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
83 SkCGDrawBitmap(ctx, fWind->getBitmap(), 0, 0);
84}
85
86@end