Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(428)

Side by Side Diff: samplecode/SampleApp.cpp

Issue 96099: Whitespace fix: remove whitespace from the end of lines.
Patch Set: Created 16 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « samplecode/SampleAll.cpp ('k') | samplecode/SampleArc.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "SkCanvas.h" 1 #include "SkCanvas.h"
2 #include "SkDevice.h" 2 #include "SkDevice.h"
3 #include "SkGLCanvas.h" 3 #include "SkGLCanvas.h"
4 #include "SkGraphics.h" 4 #include "SkGraphics.h"
5 #include "SkImageEncoder.h" 5 #include "SkImageEncoder.h"
6 #include "SkPaint.h" 6 #include "SkPaint.h"
7 #include "SkPicture.h" 7 #include "SkPicture.h"
8 #include "SkStream.h" 8 #include "SkStream.h"
9 #include "SkWindow.h" 9 #include "SkWindow.h"
10 10
(...skipping 11 matching lines...) Expand all
22 22
23 #define USE_OFFSCREEN 23 #define USE_OFFSCREEN
24 24
25 SkViewRegister* SkViewRegister::gHead; 25 SkViewRegister* SkViewRegister::gHead;
26 SkViewRegister::SkViewRegister(SkViewFactory fact) : fFact(fact) { 26 SkViewRegister::SkViewRegister(SkViewFactory fact) : fFact(fact) {
27 static bool gOnce; 27 static bool gOnce;
28 if (!gOnce) { 28 if (!gOnce) {
29 gHead = NULL; 29 gHead = NULL;
30 gOnce = true; 30 gOnce = true;
31 } 31 }
32 32
33 fChain = gHead; 33 fChain = gHead;
34 gHead = this; 34 gHead = this;
35 } 35 }
36 36
37 #ifdef SK_SUPPORT_GL 37 #ifdef SK_SUPPORT_GL
38 static AGLContext gAGLContext; 38 static AGLContext gAGLContext;
39 39
40 static void init_gl(WindowRef wref) { 40 static void init_gl(WindowRef wref) {
41 GLint major, minor; 41 GLint major, minor;
42 42
43 aglGetVersion(&major, &minor); 43 aglGetVersion(&major, &minor);
44 SkDebugf("---- agl version %d %d\n", major, minor); 44 SkDebugf("---- agl version %d %d\n", major, minor);
45 45
46 const GLint pixelAttrs[] = { 46 const GLint pixelAttrs[] = {
47 AGL_RGBA, 47 AGL_RGBA,
48 AGL_DEPTH_SIZE, 32, 48 AGL_DEPTH_SIZE, 32,
49 AGL_OFFSCREEN, 49 AGL_OFFSCREEN,
50 AGL_NONE 50 AGL_NONE
51 }; 51 };
52 52
53 AGLPixelFormat format = aglCreatePixelFormat(pixelAttrs); 53 AGLPixelFormat format = aglCreatePixelFormat(pixelAttrs);
54 SkDebugf("----- agl format %p\n", format); 54 SkDebugf("----- agl format %p\n", format);
55 gAGLContext = aglCreateContext(format, NULL); 55 gAGLContext = aglCreateContext(format, NULL);
56 SkDebugf("----- agl context %p\n", gAGLContext); 56 SkDebugf("----- agl context %p\n", gAGLContext);
57 aglDestroyPixelFormat(format); 57 aglDestroyPixelFormat(format);
58 58
59 aglEnable(gAGLContext, GL_BLEND); 59 aglEnable(gAGLContext, GL_BLEND);
60 aglEnable(gAGLContext, GL_LINE_SMOOTH); 60 aglEnable(gAGLContext, GL_LINE_SMOOTH);
61 aglEnable(gAGLContext, GL_POINT_SMOOTH); 61 aglEnable(gAGLContext, GL_POINT_SMOOTH);
62 aglEnable(gAGLContext, GL_POLYGON_SMOOTH); 62 aglEnable(gAGLContext, GL_POLYGON_SMOOTH);
63 63
64 aglSetCurrentContext(gAGLContext); 64 aglSetCurrentContext(gAGLContext);
65 } 65 }
66 66
67 static void setup_offscreen_gl(const SkBitmap& offscreen, WindowRef wref) { 67 static void setup_offscreen_gl(const SkBitmap& offscreen, WindowRef wref) {
68 GLboolean success = true; 68 GLboolean success = true;
69 69
70 #ifdef USE_OFFSCREEN 70 #ifdef USE_OFFSCREEN
71 success = aglSetOffScreen(gAGLContext, 71 success = aglSetOffScreen(gAGLContext,
72 offscreen.width(), 72 offscreen.width(),
73 offscreen.height(), 73 offscreen.height(),
74 offscreen.rowBytes(), 74 offscreen.rowBytes(),
75 offscreen.getPixels()); 75 offscreen.getPixels());
76 #else 76 #else
77 success = aglSetWindowRef(gAGLContext, wref); 77 success = aglSetWindowRef(gAGLContext, wref);
78 #endif 78 #endif
79 79
80 GLenum err = aglGetError(); 80 GLenum err = aglGetError();
81 if (err) { 81 if (err) {
82 SkDebugf("---- setoffscreen %d %d %s [%d %d]\n", success, err, 82 SkDebugf("---- setoffscreen %d %d %s [%d %d]\n", success, err,
83 aglErrorString(err), offscreen.width(), offscreen.height()); 83 aglErrorString(err), offscreen.width(), offscreen.height());
84 } 84 }
85 85
86 glEnable(GL_BLEND); 86 glEnable(GL_BLEND);
87 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 87 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
88 glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE); 88 glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
89 glEnable(GL_TEXTURE_2D); 89 glEnable(GL_TEXTURE_2D);
90 90
91 glClearColor(0, 0, 0, 0); 91 glClearColor(0, 0, 0, 0);
92 glClear(GL_COLOR_BUFFER_BIT); 92 glClear(GL_COLOR_BUFFER_BIT);
93 } 93 }
94 #endif 94 #endif
95 95
(...skipping 28 matching lines...) Expand all
124 class SampleWindow : public SkOSWindow { 124 class SampleWindow : public SkOSWindow {
125 public: 125 public:
126 SampleWindow(void* hwnd); 126 SampleWindow(void* hwnd);
127 virtual ~SampleWindow(); 127 virtual ~SampleWindow();
128 128
129 protected: 129 protected:
130 virtual void onDraw(SkCanvas* canvas); 130 virtual void onDraw(SkCanvas* canvas);
131 virtual bool onHandleKey(SkKey key); 131 virtual bool onHandleKey(SkKey key);
132 virtual bool onHandleChar(SkUnichar); 132 virtual bool onHandleChar(SkUnichar);
133 virtual void onSizeChange(); 133 virtual void onSizeChange();
134 134
135 virtual SkCanvas* beforeChildren(SkCanvas*); 135 virtual SkCanvas* beforeChildren(SkCanvas*);
136 virtual void afterChildren(SkCanvas*); 136 virtual void afterChildren(SkCanvas*);
137 137
138 virtual bool onEvent(const SkEvent& evt); 138 virtual bool onEvent(const SkEvent& evt);
139 139
140 #if 0 140 #if 0
141 virtual bool handleChar(SkUnichar uni); 141 virtual bool handleChar(SkUnichar uni);
142 virtual bool handleEvent(const SkEvent& evt); 142 virtual bool handleEvent(const SkEvent& evt);
143 virtual bool handleKey(SkKey key); 143 virtual bool handleKey(SkKey key);
144 virtual bool handleKeyUp(SkKey key); 144 virtual bool handleKeyUp(SkKey key);
145 145
146 virtual bool onClick(Click* click); 146 virtual bool onClick(Click* click);
147 virtual Click* onFindClickHandler(SkScalar x, SkScalar y); 147 virtual Click* onFindClickHandler(SkScalar x, SkScalar y);
148 virtual bool onHandleKeyUp(SkKey key); 148 virtual bool onHandleKeyUp(SkKey key);
149 #endif 149 #endif
150 private: 150 private:
151 const SkViewRegister* fCurr; 151 const SkViewRegister* fCurr;
152 152
153 SkPicture* fPicture; 153 SkPicture* fPicture;
154 SkGLCanvas* fGLCanvas; 154 SkGLCanvas* fGLCanvas;
155 SkPath fClipPath; 155 SkPath fClipPath;
156 156
157 enum CanvasType { 157 enum CanvasType {
158 kRaster_CanvasType, 158 kRaster_CanvasType,
159 kPicture_CanvasType, 159 kPicture_CanvasType,
160 kOpenGL_CanvasType 160 kOpenGL_CanvasType
161 }; 161 };
162 CanvasType fCanvasType; 162 CanvasType fCanvasType;
163 163
164 bool fUseClip; 164 bool fUseClip;
165 bool fRepeatDrawing; 165 bool fRepeatDrawing;
166 bool fAnimating; 166 bool fAnimating;
167 167
168 int fScrollTestX, fScrollTestY; 168 int fScrollTestX, fScrollTestY;
169 169
170 void loadView(SkView*); 170 void loadView(SkView*);
171 void updateTitle(); 171 void updateTitle();
172 bool nextSample(); 172 bool nextSample();
173 173
174 void postAnimatingEvent() { 174 void postAnimatingEvent() {
175 if (fAnimating) { 175 if (fAnimating) {
176 SkEvent* evt = new SkEvent(ANIMATING_EVENTTYPE); 176 SkEvent* evt = new SkEvent(ANIMATING_EVENTTYPE);
177 evt->post(this->getSinkID(), ANIMATING_DELAY); 177 evt->post(this->getSinkID(), ANIMATING_DELAY);
178 } 178 }
179 } 179 }
180 180
181 181
182 static CanvasType cycle_canvastype(CanvasType); 182 static CanvasType cycle_canvastype(CanvasType);
183 183
184 typedef SkOSWindow INHERITED; 184 typedef SkOSWindow INHERITED;
185 }; 185 };
186 186
187 SampleWindow::CanvasType SampleWindow::cycle_canvastype(CanvasType ct) { 187 SampleWindow::CanvasType SampleWindow::cycle_canvastype(CanvasType ct) {
188 static const CanvasType gCT[] = { 188 static const CanvasType gCT[] = {
189 kPicture_CanvasType, 189 kPicture_CanvasType,
190 kOpenGL_CanvasType, 190 kOpenGL_CanvasType,
191 kRaster_CanvasType 191 kRaster_CanvasType
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 case kPicture_CanvasType: 301 case kPicture_CanvasType:
302 if (true) { 302 if (true) {
303 SkPicture* pict = new SkPicture(*fPicture); 303 SkPicture* pict = new SkPicture(*fPicture);
304 fPicture->unref(); 304 fPicture->unref();
305 orig->drawPicture(*pict); 305 orig->drawPicture(*pict);
306 pict->unref(); 306 pict->unref();
307 } else if (true) { 307 } else if (true) {
308 SkDynamicMemoryWStream ostream; 308 SkDynamicMemoryWStream ostream;
309 fPicture->serialize(&ostream); 309 fPicture->serialize(&ostream);
310 fPicture->unref(); 310 fPicture->unref();
311 311
312 SkMemoryStream istream(ostream.getStream(), ostream.getOffset()) ; 312 SkMemoryStream istream(ostream.getStream(), ostream.getOffset()) ;
313 SkPicture pict(&istream); 313 SkPicture pict(&istream);
314 orig->drawPicture(pict); 314 orig->drawPicture(pict);
315 } else { 315 } else {
316 fPicture->draw(orig); 316 fPicture->draw(orig);
317 fPicture->unref(); 317 fPicture->unref();
318 } 318 }
319 fPicture = NULL; 319 fPicture = NULL;
320 break; 320 break;
321 #ifdef SK_SUPPORT_GL 321 #ifdef SK_SUPPORT_GL
322 case kOpenGL_CanvasType: 322 case kOpenGL_CanvasType:
323 glFlush(); 323 glFlush();
324 delete fGLCanvas; 324 delete fGLCanvas;
325 fGLCanvas = NULL; 325 fGLCanvas = NULL;
326 #ifdef USE_OFFSCREEN 326 #ifdef USE_OFFSCREEN
327 reverseRedAndBlue(orig->getDevice()->accessBitmap(true)); 327 reverseRedAndBlue(orig->getDevice()->accessBitmap(true));
328 #endif 328 #endif
329 break; 329 break;
330 #endif 330 #endif
331 } 331 }
332 332
333 // if ((fScrollTestX | fScrollTestY) != 0) 333 // if ((fScrollTestX | fScrollTestY) != 0)
334 { 334 {
335 const SkBitmap& bm = orig->getDevice()->accessBitmap(true); 335 const SkBitmap& bm = orig->getDevice()->accessBitmap(true);
336 int dx = fScrollTestX * 7; 336 int dx = fScrollTestX * 7;
337 int dy = fScrollTestY * 7; 337 int dy = fScrollTestY * 7;
338 SkIRect r; 338 SkIRect r;
339 SkRegion inval; 339 SkRegion inval;
340 340
341 r.set(50, 50, 50+100, 50+100); 341 r.set(50, 50, 50+100, 50+100);
342 bm.scrollRect(&r, dx, dy, &inval); 342 bm.scrollRect(&r, dx, dy, &inval);
343 paint_rgn(bm, r, inval); 343 paint_rgn(bm, r, inval);
344 } 344 }
345 } 345 }
346 346
347 static SkBitmap::Config gConfigCycle[] = { 347 static SkBitmap::Config gConfigCycle[] = {
348 SkBitmap::kNo_Config, // none -> none 348 SkBitmap::kNo_Config, // none -> none
349 SkBitmap::kNo_Config, // a1 -> none 349 SkBitmap::kNo_Config, // a1 -> none
350 SkBitmap::kNo_Config, // a8 -> none 350 SkBitmap::kNo_Config, // a8 -> none
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 switch (uni) { 400 switch (uni) {
401 case '5': dx = 0; dy = 0; break; 401 case '5': dx = 0; dy = 0; break;
402 case '8': dx = 0; dy = -1; break; 402 case '8': dx = 0; dy = -1; break;
403 case '6': dx = 1; dy = 0; break; 403 case '6': dx = 1; dy = 0; break;
404 case '2': dx = 0; dy = 1; break; 404 case '2': dx = 0; dy = 1; break;
405 case '4': dx = -1; dy = 0; break; 405 case '4': dx = -1; dy = 0; break;
406 case '7': dx = -1; dy = -1; break; 406 case '7': dx = -1; dy = -1; break;
407 case '9': dx = 1; dy = -1; break; 407 case '9': dx = 1; dy = -1; break;
408 case '3': dx = 1; dy = 1; break; 408 case '3': dx = 1; dy = 1; break;
409 case '1': dx = -1; dy = 1; break; 409 case '1': dx = -1; dy = 1; break;
410 410
411 default: 411 default:
412 break; 412 break;
413 } 413 }
414 414
415 if (0xFF != dx && 0xFF != dy) { 415 if (0xFF != dx && 0xFF != dy) {
416 if ((dx | dy) == 0) { 416 if ((dx | dy) == 0) {
417 fScrollTestX = fScrollTestY = 0; 417 fScrollTestX = fScrollTestY = 0;
418 } else { 418 } else {
419 fScrollTestX += dx; 419 fScrollTestX += dx;
420 fScrollTestY += dy; 420 fScrollTestY += dy;
421 } 421 }
422 this->inval(NULL); 422 this->inval(NULL);
423 return true; 423 return true;
424 } 424 }
425 425
426 switch (uni) { 426 switch (uni) {
427 case 'a': 427 case 'a':
428 fAnimating = !fAnimating; 428 fAnimating = !fAnimating;
429 this->postAnimatingEvent(); 429 this->postAnimatingEvent();
430 this->updateTitle(); 430 this->updateTitle();
431 return true; 431 return true;
432 case 'f': { 432 case 'f': {
433 const char* title = this->getTitle(); 433 const char* title = this->getTitle();
434 if (title[0] == 0) { 434 if (title[0] == 0) {
435 title = "sampleapp"; 435 title = "sampleapp";
436 } 436 }
437 SkString name(title); 437 SkString name(title);
438 cleanup_for_filename(&name); 438 cleanup_for_filename(&name);
439 name.append(".png"); 439 name.append(".png");
440 if (SkImageEncoder::EncodeFile(name.c_str(), this->getBitmap(), 440 if (SkImageEncoder::EncodeFile(name.c_str(), this->getBitmap(),
441 SkImageEncoder::kPNG_Type, 100)) { 441 SkImageEncoder::kPNG_Type, 100)) {
442 SkDebugf("Created %s\n", name.c_str()); 442 SkDebugf("Created %s\n", name.c_str());
443 } 443 }
444 return true; 444 return true;
445 } 445 }
446 default: 446 default:
447 break; 447 break;
448 } 448 }
449 449
450 return this->INHERITED::onHandleChar(uni); 450 return this->INHERITED::onHandleChar(uni);
451 } 451 }
452 452
453 #include "SkDumpCanvas.h" 453 #include "SkDumpCanvas.h"
454 454
455 bool SampleWindow::onHandleKey(SkKey key) { 455 bool SampleWindow::onHandleKey(SkKey key) {
456 switch (key) { 456 switch (key) {
457 case kRight_SkKey: 457 case kRight_SkKey:
458 if (this->nextSample()) { 458 if (this->nextSample()) {
459 return true; 459 return true;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 529
530 SkView::F2BIter iter(this); 530 SkView::F2BIter iter(this);
531 SkView* view = iter.next(); 531 SkView* view = iter.next();
532 SkEvent evt(gTitleEvtName); 532 SkEvent evt(gTitleEvtName);
533 if (view->doQuery(&evt)) { 533 if (view->doQuery(&evt)) {
534 title.set(evt.findString(gTitleEvtName)); 534 title.set(evt.findString(gTitleEvtName));
535 } 535 }
536 if (title.size() == 0) { 536 if (title.size() == 0) {
537 title.set("<unknown>"); 537 title.set("<unknown>");
538 } 538 }
539 539
540 title.prepend(gCanvasTypePrefix[fCanvasType]); 540 title.prepend(gCanvasTypePrefix[fCanvasType]);
541 541
542 title.prepend(" "); 542 title.prepend(" ");
543 title.prepend(configToString(this->getBitmap().config())); 543 title.prepend(configToString(this->getBitmap().config()));
544 544
545 if (fAnimating) { 545 if (fAnimating) {
546 title.prepend("<A> "); 546 title.prepend("<A> ");
547 } 547 }
548 548
549 this->setTitle(title.c_str()); 549 this->setTitle(title.c_str());
550 } 550 }
551 551
552 void SampleWindow::onSizeChange() { 552 void SampleWindow::onSizeChange() {
553 this->INHERITED::onSizeChange(); 553 this->INHERITED::onSizeChange();
554 554
555 SkView::F2BIter iter(this); 555 SkView::F2BIter iter(this);
556 SkView* view = iter.next(); 556 SkView* view = iter.next();
557 view->setSize(this->width(), this->height()); 557 view->setSize(this->width(), this->height());
558 558
559 // rebuild our clippath 559 // rebuild our clippath
560 { 560 {
561 const SkScalar W = this->width(); 561 const SkScalar W = this->width();
562 const SkScalar H = this->height(); 562 const SkScalar H = this->height();
563 563
564 fClipPath.reset(); 564 fClipPath.reset();
565 #if 0 565 #if 0
566 for (SkScalar y = SK_Scalar1; y < H; y += SkIntToScalar(32)) { 566 for (SkScalar y = SK_Scalar1; y < H; y += SkIntToScalar(32)) {
567 SkRect r; 567 SkRect r;
568 r.set(SK_Scalar1, y, SkIntToScalar(30), y + SkIntToScalar(30)); 568 r.set(SK_Scalar1, y, SkIntToScalar(30), y + SkIntToScalar(30));
569 for (; r.fLeft < W; r.offset(SkIntToScalar(32), 0)) 569 for (; r.fLeft < W; r.offset(SkIntToScalar(32), 0))
570 fClipPath.addRect(r); 570 fClipPath.addRect(r);
571 } 571 }
572 #else 572 #else
573 SkRect r; 573 SkRect r;
574 r.set(0, 0, W, H); 574 r.set(0, 0, W, H);
575 fClipPath.addRect(r, SkPath::kCCW_Direction); 575 fClipPath.addRect(r, SkPath::kCCW_Direction);
576 r.set(W/4, H/4, W*3/4, H*3/4); 576 r.set(W/4, H/4, W*3/4, H*3/4);
577 fClipPath.addRect(r, SkPath::kCW_Direction); 577 fClipPath.addRect(r, SkPath::kCW_Direction);
578 #endif 578 #endif
579 } 579 }
580 580
581 this->updateTitle(); // to refresh our config 581 this->updateTitle(); // to refresh our config
582 } 582 }
583 583
584 /////////////////////////////////////////////////////////////////////////////// 584 ///////////////////////////////////////////////////////////////////////////////
585 585
586 SkOSWindow* create_sk_window(void* hwnd) { 586 SkOSWindow* create_sk_window(void* hwnd) {
587 return new SampleWindow(hwnd); 587 return new SampleWindow(hwnd);
588 } 588 }
589 589
590 void get_preferred_size(int* x, int* y, int* width, int* height) { 590 void get_preferred_size(int* x, int* y, int* width, int* height) {
591 *x = 10; 591 *x = 10;
592 *y = 50; 592 *y = 50;
593 *width = 640; 593 *width = 640;
594 *height = 480; 594 *height = 480;
595 } 595 }
596 596
597 void application_init() { 597 void application_init() {
598 // setenv("ANDROID_ROOT", "../../../data", 0); 598 // setenv("ANDROID_ROOT", "../../../data", 0);
599 setenv("ANDROID_ROOT", "/android/device/data", 0); 599 setenv("ANDROID_ROOT", "/android/device/data", 0);
600 SkGraphics::Init(); 600 SkGraphics::Init();
601 SkEvent::Init(); 601 SkEvent::Init();
602 } 602 }
603 603
604 void application_term() { 604 void application_term() {
605 SkEvent::Term(); 605 SkEvent::Term();
606 SkGraphics::Term(); 606 SkGraphics::Term();
607 } 607 }
OLDNEW
« no previous file with comments | « samplecode/SampleAll.cpp ('k') | samplecode/SampleArc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b