gfx/skia/trunk/src/views/mac/SkOSWindow_Mac.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /*
michael@0 2 * Copyright 2011 Google Inc.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8 #include "SkTypes.h"
michael@0 9
michael@0 10 #if defined(SK_BUILD_FOR_MAC)
michael@0 11
michael@0 12 #include <AGL/agl.h>
michael@0 13
michael@0 14 #include <Carbon/Carbon.h>
michael@0 15 #include "SkCGUtils.h"
michael@0 16
michael@0 17 #include "SkWindow.h"
michael@0 18 #include "SkCanvas.h"
michael@0 19 #include "SkOSMenu.h"
michael@0 20 #include "SkTime.h"
michael@0 21
michael@0 22 #include "SkGraphics.h"
michael@0 23 #include <new.h>
michael@0 24
michael@0 25 static void (*gPrevNewHandler)();
michael@0 26
michael@0 27 extern "C" {
michael@0 28 static void sk_new_handler()
michael@0 29 {
michael@0 30 if (SkGraphics::SetFontCacheUsed(0))
michael@0 31 return;
michael@0 32 if (gPrevNewHandler)
michael@0 33 gPrevNewHandler();
michael@0 34 else
michael@0 35 sk_throw();
michael@0 36 }
michael@0 37 }
michael@0 38
michael@0 39 static SkOSWindow* gCurrOSWin;
michael@0 40 static EventTargetRef gEventTarget;
michael@0 41 static EventQueueRef gCurrEventQ;
michael@0 42
michael@0 43 static OSStatus MyDrawEventHandler(EventHandlerCallRef myHandler,
michael@0 44 EventRef event, void *userData) {
michael@0 45 // NOTE: GState is save/restored by the HIView system doing the callback,
michael@0 46 // so the draw handler doesn't need to do it
michael@0 47
michael@0 48 OSStatus status = noErr;
michael@0 49 CGContextRef context;
michael@0 50 HIRect bounds;
michael@0 51
michael@0 52 // Get the CGContextRef
michael@0 53 status = GetEventParameter (event, kEventParamCGContextRef,
michael@0 54 typeCGContextRef, NULL,
michael@0 55 sizeof (CGContextRef),
michael@0 56 NULL,
michael@0 57 &context);
michael@0 58
michael@0 59 if (status != noErr) {
michael@0 60 SkDebugf("Got error %d getting the context!\n", status);
michael@0 61 return status;
michael@0 62 }
michael@0 63
michael@0 64 // Get the bounding rectangle
michael@0 65 HIViewGetBounds ((HIViewRef) userData, &bounds);
michael@0 66
michael@0 67 gCurrOSWin->doPaint(context);
michael@0 68 return status;
michael@0 69 }
michael@0 70
michael@0 71 #define SK_MacEventClass FOUR_CHAR_CODE('SKec')
michael@0 72 #define SK_MacEventKind FOUR_CHAR_CODE('SKek')
michael@0 73 #define SK_MacEventParamName FOUR_CHAR_CODE('SKev')
michael@0 74 #define SK_MacEventSinkIDParamName FOUR_CHAR_CODE('SKes')
michael@0 75
michael@0 76 static void set_bindingside(HISideBinding* side, HIViewRef parent, HIBindingKind kind) {
michael@0 77 side->toView = parent;
michael@0 78 side->kind = kind;
michael@0 79 side->offset = 0;
michael@0 80 }
michael@0 81
michael@0 82 static void set_axisscale(HIAxisScale* axis, HIViewRef parent) {
michael@0 83 axis->toView = parent;
michael@0 84 axis->kind = kHILayoutScaleAbsolute;
michael@0 85 axis->ratio = 1;
michael@0 86 }
michael@0 87
michael@0 88 static void set_axisposition(HIAxisPosition* pos, HIViewRef parent, HIPositionKind kind) {
michael@0 89 pos->toView = parent;
michael@0 90 pos->kind = kind;
michael@0 91 pos->offset = 0;
michael@0 92 }
michael@0 93
michael@0 94 SkOSWindow::SkOSWindow(void* hWnd) : fHWND(hWnd), fAGLCtx(NULL)
michael@0 95 {
michael@0 96 OSStatus result;
michael@0 97 WindowRef wr = (WindowRef)hWnd;
michael@0 98
michael@0 99 HIViewRef imageView, parent;
michael@0 100 HIViewRef rootView = HIViewGetRoot(wr);
michael@0 101 HIViewFindByID(rootView, kHIViewWindowContentID, &parent);
michael@0 102 result = HIImageViewCreate(NULL, &imageView);
michael@0 103 SkASSERT(result == noErr);
michael@0 104
michael@0 105 result = HIViewAddSubview(parent, imageView);
michael@0 106 SkASSERT(result == noErr);
michael@0 107
michael@0 108 fHVIEW = imageView;
michael@0 109
michael@0 110 HIViewSetVisible(imageView, true);
michael@0 111 HIViewPlaceInSuperviewAt(imageView, 0, 0);
michael@0 112
michael@0 113 if (true) {
michael@0 114 HILayoutInfo layout;
michael@0 115 layout.version = kHILayoutInfoVersionZero;
michael@0 116 set_bindingside(&layout.binding.left, parent, kHILayoutBindLeft);
michael@0 117 set_bindingside(&layout.binding.top, parent, kHILayoutBindTop);
michael@0 118 set_bindingside(&layout.binding.right, parent, kHILayoutBindRight);
michael@0 119 set_bindingside(&layout.binding.bottom, parent, kHILayoutBindBottom);
michael@0 120 set_axisscale(&layout.scale.x, parent);
michael@0 121 set_axisscale(&layout.scale.y, parent);
michael@0 122 set_axisposition(&layout.position.x, parent, kHILayoutPositionLeft);
michael@0 123 set_axisposition(&layout.position.y, rootView, kHILayoutPositionTop);
michael@0 124 HIViewSetLayoutInfo(imageView, &layout);
michael@0 125 }
michael@0 126
michael@0 127 HIImageViewSetOpaque(imageView, true);
michael@0 128 HIImageViewSetScaleToFit(imageView, false);
michael@0 129
michael@0 130 static const EventTypeSpec gTypes[] = {
michael@0 131 { kEventClassKeyboard, kEventRawKeyDown },
michael@0 132 { kEventClassKeyboard, kEventRawKeyUp },
michael@0 133 { kEventClassMouse, kEventMouseDown },
michael@0 134 { kEventClassMouse, kEventMouseDragged },
michael@0 135 { kEventClassMouse, kEventMouseMoved },
michael@0 136 { kEventClassMouse, kEventMouseUp },
michael@0 137 { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent },
michael@0 138 { kEventClassWindow, kEventWindowBoundsChanged },
michael@0 139 // { kEventClassWindow, kEventWindowDrawContent },
michael@0 140 { SK_MacEventClass, SK_MacEventKind }
michael@0 141 };
michael@0 142
michael@0 143 EventHandlerUPP handlerUPP = NewEventHandlerUPP(SkOSWindow::EventHandler);
michael@0 144 int count = SK_ARRAY_COUNT(gTypes);
michael@0 145
michael@0 146 result = InstallEventHandler(GetWindowEventTarget(wr), handlerUPP,
michael@0 147 count, gTypes, this, nil);
michael@0 148 SkASSERT(result == noErr);
michael@0 149
michael@0 150 gCurrOSWin = this;
michael@0 151 gCurrEventQ = GetCurrentEventQueue();
michael@0 152 gEventTarget = GetWindowEventTarget(wr);
michael@0 153
michael@0 154 static bool gOnce = true;
michael@0 155 if (gOnce) {
michael@0 156 gOnce = false;
michael@0 157 gPrevNewHandler = set_new_handler(sk_new_handler);
michael@0 158 }
michael@0 159 }
michael@0 160
michael@0 161 void SkOSWindow::doPaint(void* ctx)
michael@0 162 {
michael@0 163 #if 0
michael@0 164 this->update(NULL);
michael@0 165
michael@0 166 const SkBitmap& bm = this->getBitmap();
michael@0 167 CGImageRef img = SkCreateCGImageRef(bm);
michael@0 168
michael@0 169 if (img) {
michael@0 170 CGRect r = CGRectMake(0, 0, bm.width(), bm.height());
michael@0 171
michael@0 172 CGContextRef cg = reinterpret_cast<CGContextRef>(ctx);
michael@0 173
michael@0 174 CGContextSaveGState(cg);
michael@0 175 CGContextTranslateCTM(cg, 0, r.size.height);
michael@0 176 CGContextScaleCTM(cg, 1, -1);
michael@0 177
michael@0 178 CGContextDrawImage(cg, r, img);
michael@0 179
michael@0 180 CGContextRestoreGState(cg);
michael@0 181
michael@0 182 CGImageRelease(img);
michael@0 183 }
michael@0 184 #endif
michael@0 185 }
michael@0 186
michael@0 187 void SkOSWindow::updateSize()
michael@0 188 {
michael@0 189 Rect r;
michael@0 190
michael@0 191 GetWindowBounds((WindowRef)fHWND, kWindowContentRgn, &r);
michael@0 192 this->resize(r.right - r.left, r.bottom - r.top);
michael@0 193
michael@0 194 #if 0
michael@0 195 HIRect frame;
michael@0 196 HIViewRef imageView = (HIViewRef)getHVIEW();
michael@0 197 HIViewRef parent = HIViewGetSuperview(imageView);
michael@0 198
michael@0 199 HIViewGetBounds(imageView, &frame);
michael@0 200 SkDebugf("------ %d bounds %g %g %g %g\n", r.right - r.left,
michael@0 201 frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
michael@0 202 #endif
michael@0 203 }
michael@0 204
michael@0 205 void SkOSWindow::onHandleInval(const SkIRect& r)
michael@0 206 {
michael@0 207 (new SkEvent("inval-imageview", this->getSinkID()))->post();
michael@0 208 }
michael@0 209
michael@0 210 bool SkOSWindow::onEvent(const SkEvent& evt) {
michael@0 211 if (evt.isType("inval-imageview")) {
michael@0 212 this->update(NULL);
michael@0 213
michael@0 214 SkEvent query("ignore-window-bitmap");
michael@0 215 if (!this->doQuery(&query) || !query.getFast32()) {
michael@0 216 const SkBitmap& bm = this->getBitmap();
michael@0 217
michael@0 218 CGImageRef img = SkCreateCGImageRef(bm);
michael@0 219 HIImageViewSetImage((HIViewRef)getHVIEW(), img);
michael@0 220 CGImageRelease(img);
michael@0 221 }
michael@0 222 return true;
michael@0 223 }
michael@0 224 return INHERITED::onEvent(evt);
michael@0 225 }
michael@0 226
michael@0 227 void SkOSWindow::onSetTitle(const char title[])
michael@0 228 {
michael@0 229 CFStringRef str = CFStringCreateWithCString(NULL, title, kCFStringEncodingUTF8);
michael@0 230 SetWindowTitleWithCFString((WindowRef)fHWND, str);
michael@0 231 CFRelease(str);
michael@0 232 }
michael@0 233
michael@0 234 void SkOSWindow::onAddMenu(const SkOSMenu* sk_menu)
michael@0 235 {
michael@0 236 }
michael@0 237
michael@0 238 static void getparam(EventRef inEvent, OSType name, OSType type, UInt32 size, void* data)
michael@0 239 {
michael@0 240 EventParamType actualType;
michael@0 241 UInt32 actualSize;
michael@0 242 OSStatus status;
michael@0 243
michael@0 244 status = GetEventParameter(inEvent, name, type, &actualType, size, &actualSize, data);
michael@0 245 SkASSERT(status == noErr);
michael@0 246 SkASSERT(actualType == type);
michael@0 247 SkASSERT(actualSize == size);
michael@0 248 }
michael@0 249
michael@0 250 enum {
michael@0 251 SK_MacReturnKey = 36,
michael@0 252 SK_MacDeleteKey = 51,
michael@0 253 SK_MacEndKey = 119,
michael@0 254 SK_MacLeftKey = 123,
michael@0 255 SK_MacRightKey = 124,
michael@0 256 SK_MacDownKey = 125,
michael@0 257 SK_MacUpKey = 126,
michael@0 258
michael@0 259 SK_Mac0Key = 0x52,
michael@0 260 SK_Mac1Key = 0x53,
michael@0 261 SK_Mac2Key = 0x54,
michael@0 262 SK_Mac3Key = 0x55,
michael@0 263 SK_Mac4Key = 0x56,
michael@0 264 SK_Mac5Key = 0x57,
michael@0 265 SK_Mac6Key = 0x58,
michael@0 266 SK_Mac7Key = 0x59,
michael@0 267 SK_Mac8Key = 0x5b,
michael@0 268 SK_Mac9Key = 0x5c
michael@0 269 };
michael@0 270
michael@0 271 static SkKey raw2key(UInt32 raw)
michael@0 272 {
michael@0 273 static const struct {
michael@0 274 UInt32 fRaw;
michael@0 275 SkKey fKey;
michael@0 276 } gKeys[] = {
michael@0 277 { SK_MacUpKey, kUp_SkKey },
michael@0 278 { SK_MacDownKey, kDown_SkKey },
michael@0 279 { SK_MacLeftKey, kLeft_SkKey },
michael@0 280 { SK_MacRightKey, kRight_SkKey },
michael@0 281 { SK_MacReturnKey, kOK_SkKey },
michael@0 282 { SK_MacDeleteKey, kBack_SkKey },
michael@0 283 { SK_MacEndKey, kEnd_SkKey },
michael@0 284 { SK_Mac0Key, k0_SkKey },
michael@0 285 { SK_Mac1Key, k1_SkKey },
michael@0 286 { SK_Mac2Key, k2_SkKey },
michael@0 287 { SK_Mac3Key, k3_SkKey },
michael@0 288 { SK_Mac4Key, k4_SkKey },
michael@0 289 { SK_Mac5Key, k5_SkKey },
michael@0 290 { SK_Mac6Key, k6_SkKey },
michael@0 291 { SK_Mac7Key, k7_SkKey },
michael@0 292 { SK_Mac8Key, k8_SkKey },
michael@0 293 { SK_Mac9Key, k9_SkKey }
michael@0 294 };
michael@0 295
michael@0 296 for (unsigned i = 0; i < SK_ARRAY_COUNT(gKeys); i++)
michael@0 297 if (gKeys[i].fRaw == raw)
michael@0 298 return gKeys[i].fKey;
michael@0 299 return kNONE_SkKey;
michael@0 300 }
michael@0 301
michael@0 302 static void post_skmacevent()
michael@0 303 {
michael@0 304 EventRef ref;
michael@0 305 OSStatus status = CreateEvent(nil, SK_MacEventClass, SK_MacEventKind, 0, 0, &ref);
michael@0 306 SkASSERT(status == noErr);
michael@0 307
michael@0 308 #if 0
michael@0 309 status = SetEventParameter(ref, SK_MacEventParamName, SK_MacEventParamName, sizeof(evt), &evt);
michael@0 310 SkASSERT(status == noErr);
michael@0 311 status = SetEventParameter(ref, SK_MacEventSinkIDParamName, SK_MacEventSinkIDParamName, sizeof(sinkID), &sinkID);
michael@0 312 SkASSERT(status == noErr);
michael@0 313 #endif
michael@0 314
michael@0 315 EventTargetRef target = gEventTarget;
michael@0 316 SetEventParameter(ref, kEventParamPostTarget, typeEventTargetRef, sizeof(target), &target);
michael@0 317 SkASSERT(status == noErr);
michael@0 318
michael@0 319 status = PostEventToQueue(gCurrEventQ, ref, kEventPriorityStandard);
michael@0 320 SkASSERT(status == noErr);
michael@0 321
michael@0 322 ReleaseEvent(ref);
michael@0 323 }
michael@0 324
michael@0 325 pascal OSStatus SkOSWindow::EventHandler( EventHandlerCallRef inHandler, EventRef inEvent, void* userData )
michael@0 326 {
michael@0 327 SkOSWindow* win = (SkOSWindow*)userData;
michael@0 328 OSStatus result = eventNotHandledErr;
michael@0 329 UInt32 wClass = GetEventClass(inEvent);
michael@0 330 UInt32 wKind = GetEventKind(inEvent);
michael@0 331
michael@0 332 gCurrOSWin = win; // will need to be in TLS. Set this so PostEvent will work
michael@0 333
michael@0 334 switch (wClass) {
michael@0 335 case kEventClassMouse: {
michael@0 336 Point pt;
michael@0 337 getparam(inEvent, kEventParamMouseLocation, typeQDPoint, sizeof(pt), &pt);
michael@0 338 SetPortWindowPort((WindowRef)win->getHWND());
michael@0 339 GlobalToLocal(&pt);
michael@0 340
michael@0 341 switch (wKind) {
michael@0 342 case kEventMouseDown:
michael@0 343 if (win->handleClick(pt.h, pt.v, Click::kDown_State)) {
michael@0 344 result = noErr;
michael@0 345 }
michael@0 346 break;
michael@0 347 case kEventMouseMoved:
michael@0 348 // fall through
michael@0 349 case kEventMouseDragged:
michael@0 350 (void)win->handleClick(pt.h, pt.v, Click::kMoved_State);
michael@0 351 // result = noErr;
michael@0 352 break;
michael@0 353 case kEventMouseUp:
michael@0 354 (void)win->handleClick(pt.h, pt.v, Click::kUp_State);
michael@0 355 // result = noErr;
michael@0 356 break;
michael@0 357 default:
michael@0 358 break;
michael@0 359 }
michael@0 360 break;
michael@0 361 }
michael@0 362 case kEventClassKeyboard:
michael@0 363 if (wKind == kEventRawKeyDown) {
michael@0 364 UInt32 raw;
michael@0 365 getparam(inEvent, kEventParamKeyCode, typeUInt32, sizeof(raw), &raw);
michael@0 366 SkKey key = raw2key(raw);
michael@0 367 if (key != kNONE_SkKey)
michael@0 368 (void)win->handleKey(key);
michael@0 369 } else if (wKind == kEventRawKeyUp) {
michael@0 370 UInt32 raw;
michael@0 371 getparam(inEvent, kEventParamKeyCode, typeUInt32, sizeof(raw), &raw);
michael@0 372 SkKey key = raw2key(raw);
michael@0 373 if (key != kNONE_SkKey)
michael@0 374 (void)win->handleKeyUp(key);
michael@0 375 }
michael@0 376 break;
michael@0 377 case kEventClassTextInput:
michael@0 378 if (wKind == kEventTextInputUnicodeForKeyEvent) {
michael@0 379 UInt16 uni;
michael@0 380 getparam(inEvent, kEventParamTextInputSendText, typeUnicodeText, sizeof(uni), &uni);
michael@0 381 win->handleChar(uni);
michael@0 382 }
michael@0 383 break;
michael@0 384 case kEventClassWindow:
michael@0 385 switch (wKind) {
michael@0 386 case kEventWindowBoundsChanged:
michael@0 387 win->updateSize();
michael@0 388 break;
michael@0 389 case kEventWindowDrawContent: {
michael@0 390 CGContextRef cg;
michael@0 391 result = GetEventParameter(inEvent,
michael@0 392 kEventParamCGContextRef,
michael@0 393 typeCGContextRef,
michael@0 394 NULL,
michael@0 395 sizeof (CGContextRef),
michael@0 396 NULL,
michael@0 397 &cg);
michael@0 398 if (result != 0) {
michael@0 399 cg = NULL;
michael@0 400 }
michael@0 401 win->doPaint(cg);
michael@0 402 break;
michael@0 403 }
michael@0 404 default:
michael@0 405 break;
michael@0 406 }
michael@0 407 break;
michael@0 408 case SK_MacEventClass: {
michael@0 409 SkASSERT(wKind == SK_MacEventKind);
michael@0 410 if (SkEvent::ProcessEvent()) {
michael@0 411 post_skmacevent();
michael@0 412 }
michael@0 413 #if 0
michael@0 414 SkEvent* evt;
michael@0 415 SkEventSinkID sinkID;
michael@0 416 getparam(inEvent, SK_MacEventParamName, SK_MacEventParamName, sizeof(evt), &evt);
michael@0 417 getparam(inEvent, SK_MacEventSinkIDParamName, SK_MacEventSinkIDParamName, sizeof(sinkID), &sinkID);
michael@0 418 #endif
michael@0 419 result = noErr;
michael@0 420 break;
michael@0 421 }
michael@0 422 default:
michael@0 423 break;
michael@0 424 }
michael@0 425 if (result == eventNotHandledErr) {
michael@0 426 result = CallNextEventHandler(inHandler, inEvent);
michael@0 427 }
michael@0 428 return result;
michael@0 429 }
michael@0 430
michael@0 431 ///////////////////////////////////////////////////////////////////////////////////////
michael@0 432
michael@0 433 void SkEvent::SignalNonEmptyQueue()
michael@0 434 {
michael@0 435 post_skmacevent();
michael@0 436 // SkDebugf("signal nonempty\n");
michael@0 437 }
michael@0 438
michael@0 439 static TMTask gTMTaskRec;
michael@0 440 static TMTask* gTMTaskPtr;
michael@0 441
michael@0 442 static void sk_timer_proc(TMTask* rec)
michael@0 443 {
michael@0 444 SkEvent::ServiceQueueTimer();
michael@0 445 // SkDebugf("timer task fired\n");
michael@0 446 }
michael@0 447
michael@0 448 void SkEvent::SignalQueueTimer(SkMSec delay)
michael@0 449 {
michael@0 450 if (gTMTaskPtr)
michael@0 451 {
michael@0 452 RemoveTimeTask((QElem*)gTMTaskPtr);
michael@0 453 DisposeTimerUPP(gTMTaskPtr->tmAddr);
michael@0 454 gTMTaskPtr = nil;
michael@0 455 }
michael@0 456 if (delay)
michael@0 457 {
michael@0 458 gTMTaskPtr = &gTMTaskRec;
michael@0 459 memset(gTMTaskPtr, 0, sizeof(gTMTaskRec));
michael@0 460 gTMTaskPtr->tmAddr = NewTimerUPP(sk_timer_proc);
michael@0 461 OSErr err = InstallTimeTask((QElem*)gTMTaskPtr);
michael@0 462 // SkDebugf("installtimetask of %d returned %d\n", delay, err);
michael@0 463 PrimeTimeTask((QElem*)gTMTaskPtr, delay);
michael@0 464 }
michael@0 465 }
michael@0 466
michael@0 467 #define USE_MSAA 0
michael@0 468
michael@0 469 AGLContext create_gl(WindowRef wref)
michael@0 470 {
michael@0 471 GLint major, minor;
michael@0 472 AGLContext ctx;
michael@0 473
michael@0 474 aglGetVersion(&major, &minor);
michael@0 475 SkDebugf("---- agl version %d %d\n", major, minor);
michael@0 476
michael@0 477 const GLint pixelAttrs[] = {
michael@0 478 AGL_RGBA,
michael@0 479 AGL_STENCIL_SIZE, 8,
michael@0 480 #if USE_MSAA
michael@0 481 AGL_SAMPLE_BUFFERS_ARB, 1,
michael@0 482 AGL_MULTISAMPLE,
michael@0 483 AGL_SAMPLES_ARB, 8,
michael@0 484 #endif
michael@0 485 AGL_ACCELERATED,
michael@0 486 AGL_DOUBLEBUFFER,
michael@0 487 AGL_NONE
michael@0 488 };
michael@0 489 AGLPixelFormat format = aglChoosePixelFormat(NULL, 0, pixelAttrs);
michael@0 490 //AGLPixelFormat format = aglCreatePixelFormat(pixelAttrs);
michael@0 491 SkDebugf("----- agl format %p\n", format);
michael@0 492 ctx = aglCreateContext(format, NULL);
michael@0 493 SkDebugf("----- agl context %p\n", ctx);
michael@0 494 aglDestroyPixelFormat(format);
michael@0 495
michael@0 496 static const GLint interval = 1;
michael@0 497 aglSetInteger(ctx, AGL_SWAP_INTERVAL, &interval);
michael@0 498 aglSetCurrentContext(ctx);
michael@0 499 return ctx;
michael@0 500 }
michael@0 501
michael@0 502 bool SkOSWindow::attach(SkBackEndTypes /* attachType */)
michael@0 503 {
michael@0 504 if (NULL == fAGLCtx) {
michael@0 505 fAGLCtx = create_gl((WindowRef)fHWND);
michael@0 506 if (NULL == fAGLCtx) {
michael@0 507 return false;
michael@0 508 }
michael@0 509 }
michael@0 510
michael@0 511 GLboolean success = true;
michael@0 512
michael@0 513 int width, height;
michael@0 514
michael@0 515 success = aglSetWindowRef((AGLContext)fAGLCtx, (WindowRef)fHWND);
michael@0 516 width = this->width();
michael@0 517 height = this->height();
michael@0 518
michael@0 519 GLenum err = aglGetError();
michael@0 520 if (err) {
michael@0 521 SkDebugf("---- aglSetWindowRef %d %d %s [%d %d]\n", success, err,
michael@0 522 aglErrorString(err), width, height);
michael@0 523 }
michael@0 524
michael@0 525 if (success) {
michael@0 526 glViewport(0, 0, width, height);
michael@0 527 glClearColor(0, 0, 0, 0);
michael@0 528 glClearStencil(0);
michael@0 529 glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
michael@0 530 }
michael@0 531 return success;
michael@0 532 }
michael@0 533
michael@0 534 void SkOSWindow::detach() {
michael@0 535 aglSetWindowRef((AGLContext)fAGLCtx, NULL);
michael@0 536 }
michael@0 537
michael@0 538 void SkOSWindow::present() {
michael@0 539 aglSwapBuffers((AGLContext)fAGLCtx);
michael@0 540 }
michael@0 541
michael@0 542 #endif

mercurial