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