blob: 7c50fea617145f244e98a6d8f5a3416750e460fa [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.com0b7da432012-10-31 19:00:20 +000015 useOld = false;
caryclark@google.comd88e0892012-03-27 13:23:51 +000016 };
17protected:
18 virtual void onDraw(SkCanvas* canvas) {
caryclark@google.com31143cf2012-11-09 22:14:19 +000019 static int step = 0; // 17907 drawLetters first error
caryclark@google.com0b7da432012-10-31 19:00:20 +000020 // drawStars triggers error at 33348
caryclark@google.comfb51afb2012-10-19 15:54:16 +000021 // drawStars error not easy to debug last time I checked
caryclark@google.com03f97062012-08-21 13:13:52 +000022 static double seconds;
caryclark@google.com03f97062012-08-21 13:13:52 +000023 if (step == -1) {
24 timeval t;
25 gettimeofday(&t, NULL);
26 seconds = t.tv_sec+t.tv_usec/1000000.0;
27 step = 0;
28 }
caryclark@google.coma5764232012-03-28 16:20:21 +000029 canvas->drawColor(SK_ColorWHITE);
caryclark@google.com03f97062012-08-21 13:13:52 +000030 if (DrawEdgeDemo(canvas, step, useOld)) {
caryclark@google.coma5764232012-03-28 16:20:21 +000031 ++step;
caryclark@google.com0b7da432012-10-31 19:00:20 +000032 if (step == -1) {
caryclark@google.com03f97062012-08-21 13:13:52 +000033 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 }
caryclark@google.coma5764232012-03-28 16:20:21 +000041 inval(NULL);
caryclark@google.comd88e0892012-03-27 13:23:51 +000042 }
43 }
caryclark@google.com9e49fb62012-08-27 14:11:33 +000044
45 virtual Click* onFindClickHandler(SkScalar , SkScalar ) {
46 useOld ^= true;
47 return NULL;
48 }
49
caryclark@google.comd88e0892012-03-27 13:23:51 +000050private:
caryclark@google.com9e49fb62012-08-27 14:11:33 +000051 bool useOld;
caryclark@google.comd88e0892012-03-27 13:23:51 +000052 typedef SkView INHERITED;
53};
54
caryclark@google.comc899ad92012-08-23 15:24:42 +000055void application_init();
56void application_term();
57
caryclark@google.comd88e0892012-03-27 13:23:51 +000058void application_init() {
59 SkGraphics::Init();
60 SkEvent::Init();
61}
62
63void application_term() {
64 SkGraphics::Term();
65 SkEvent::Term();
66}
67
68class FillLayout : public SkView::Layout {
69protected:
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"
caryclark@google.coma5764232012-03-28 16:20:21 +000077
caryclark@google.comd88e0892012-03-27 13:23:51 +000078@implementation SimpleNSView
79
80- (id)initWithDefaults {
caryclark@google.comc899ad92012-08-23 15:24:42 +000081 if ((self = [super initWithDefaults])) {
caryclark@google.comd88e0892012-03-27 13:23:51 +000082 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