VirtualBox

source: vbox/trunk/src/VBox/Additions/common/crOpenGL/context.c@ 78942

Last change on this file since 78942 was 78341, checked in by vboxsync, 6 years ago

Config.kmk,Additions/common/crOpenGL,VBox/GuestHost/OpenGL,HostServices/SharedOpenGL: Remove CHROMIUM_THREADSAFE define and apply the current default

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 40.8 KB
Line 
1/* Copyright (c) 2001, Stanford University
2 * All rights reserved
3 *
4 * See the file LICENSE.txt for information on redistributing this software.
5 */
6
7/**
8 * \mainpage OpenGL_stub
9 *
10 * \section OpenGL_stubIntroduction Introduction
11 *
12 * Chromium consists of all the top-level files in the cr
13 * directory. The OpenGL_stub module basically takes care of API dispatch,
14 * and OpenGL state management.
15 *
16 */
17
18/**
19 * This file manages OpenGL rendering contexts in the faker library.
20 * The big issue is switching between Chromium and native GL context
21 * management. This is where we support multiple client OpenGL
22 * windows. Typically, one window is handled by Chromium while any
23 * other windows are handled by the native OpenGL library.
24 */
25
26#include "chromium.h"
27#include "cr_error.h"
28#include "cr_spu.h"
29#include "cr_mem.h"
30#include "cr_string.h"
31#include "stub.h"
32
33/**
34 * This function should be called from MakeCurrent(). It'll detect if
35 * we're in a multi-thread situation, and do the right thing for dispatch.
36 */
37static void stubCheckMultithread( void )
38{
39 static unsigned long knownID;
40 static GLboolean firstCall = GL_TRUE;
41
42 if (stub.threadSafe)
43 return; /* nothing new, nothing to do */
44
45 if (firstCall) {
46 knownID = crThreadID();
47 firstCall = GL_FALSE;
48 }
49 else if (knownID != crThreadID()) {
50 /* going thread-safe now! */
51 stub.threadSafe = GL_TRUE;
52 crSPUCopyDispatchTable(&glim, &stubThreadsafeDispatch);
53 }
54}
55
56
57/**
58 * Install the given dispatch table as the table used for all gl* calls.
59 */
60 static void
61stubSetDispatch( SPUDispatchTable *table )
62{
63 CRASSERT(table);
64
65 /* always set the per-thread dispatch pointer */
66 crSetTSD(&stub.dispatchTSD, (void *) table);
67 if (stub.threadSafe) {
68 /* Do nothing - the thread-safe dispatch functions will call GetTSD()
69 * to get a pointer to the dispatch table, and jump through it.
70 */
71 }
72 else
73 {
74 /* Single thread mode - just install the caller's dispatch table */
75 /* This conditional is an optimization to try to avoid unnecessary
76 * copying. It seems to work with atlantis, multiwin, etc. but
77 * _could_ be a problem. (Brian)
78 */
79 if (glim.copy_of != table->copy_of)
80 crSPUCopyDispatchTable(&glim, table);
81 }
82}
83
84void stubForcedFlush(GLint con)
85{
86#if 0
87 GLint buffer;
88 stub.spu->dispatch_table.GetIntegerv(GL_DRAW_BUFFER, &buffer);
89 stub.spu->dispatch_table.DrawBuffer(GL_FRONT);
90 stub.spu->dispatch_table.Flush();
91 stub.spu->dispatch_table.DrawBuffer(buffer);
92#else
93 if (con)
94 {
95 stub.spu->dispatch_table.VBoxConFlush(con);
96 }
97 else
98 {
99 stub.spu->dispatch_table.Flush();
100 }
101#endif
102}
103
104void stubConChromiumParameteriCR(GLint con, GLenum param, GLint value)
105{
106// if (con)
107 stub.spu->dispatch_table.VBoxConChromiumParameteriCR(con, param, value);
108// else
109// crError("VBoxConChromiumParameteriCR called with null connection");
110}
111
112void stubConChromiumParametervCR(GLint con, GLenum target, GLenum type, GLsizei count, const GLvoid *values)
113{
114// if (con)
115 stub.spu->dispatch_table.VBoxConChromiumParametervCR(con, target, type, count, values);
116// else
117// crError("VBoxConChromiumParameteriCR called with null connection");
118}
119
120void stubConFlush(GLint con)
121{
122 if (con)
123 stub.spu->dispatch_table.VBoxConFlush(con);
124 else
125 crError("stubConFlush called with null connection");
126}
127
128static void stubWindowCleanupForContextsCB(unsigned long key, void *data1, void *data2)
129{
130 ContextInfo *context = (ContextInfo *) data1;
131 RT_NOREF(key);
132
133 CRASSERT(context);
134
135 if (context->currentDrawable == data2)
136 context->currentDrawable = NULL;
137}
138
139void stubDestroyWindow( GLint con, GLint window )
140{
141 WindowInfo *winInfo = (WindowInfo *)
142 crHashtableSearch(stub.windowTable, (unsigned int) window);
143 if (winInfo && winInfo->type == CHROMIUM && stub.spu)
144 {
145 crHashtableLock(stub.windowTable);
146
147 stub.spu->dispatch_table.VBoxWindowDestroy(con, winInfo->spuWindow );
148
149#ifdef WINDOWS
150 if (winInfo->hVisibleRegion != INVALID_HANDLE_VALUE)
151 {
152 DeleteObject(winInfo->hVisibleRegion);
153 }
154#elif defined(GLX)
155 if (winInfo->pVisibleRegions)
156 {
157 XFree(winInfo->pVisibleRegions);
158 }
159# ifdef CR_NEWWINTRACK
160 if (winInfo->syncDpy)
161 {
162 XCloseDisplay(winInfo->syncDpy);
163 }
164# endif
165#endif
166
167 stubForcedFlush(con);
168
169 crHashtableWalk(stub.contextTable, stubWindowCleanupForContextsCB, winInfo);
170
171 crHashtableDelete(stub.windowTable, window, crFree);
172
173 crHashtableUnlock(stub.windowTable);
174 }
175}
176
177/**
178 * Create a new _Chromium_ window, not GLX, WGL or CGL.
179 * Called by crWindowCreate() only.
180 */
181 GLint
182stubNewWindow( const char *dpyName, GLint visBits )
183{
184 WindowInfo *winInfo;
185 GLint spuWin, size[2];
186
187 spuWin = stub.spu->dispatch_table.WindowCreate( dpyName, visBits );
188 if (spuWin < 0) {
189 return -1;
190 }
191
192 winInfo = (WindowInfo *) crCalloc(sizeof(WindowInfo));
193 if (!winInfo) {
194 stub.spu->dispatch_table.WindowDestroy(spuWin);
195 return -1;
196 }
197
198 winInfo->type = CHROMIUM;
199
200 /* Ask the head SPU for the initial window size */
201 size[0] = size[1] = 0;
202 stub.spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_SIZE_CR, 0, GL_INT, 2, size);
203 if (size[0] == 0 && size[1] == 0) {
204 /* use some reasonable defaults */
205 size[0] = size[1] = 512;
206 }
207 winInfo->width = size[0];
208 winInfo->height = size[1];
209#ifdef VBOX_WITH_WDDM
210 if (stub.bRunningUnderWDDM)
211 {
212 crError("Should not be here: WindowCreate/Destroy & VBoxPackGetInjectID require connection id!");
213 winInfo->mapped = 0;
214 }
215 else
216#endif
217 {
218 winInfo->mapped = 1;
219 }
220
221 if (!dpyName)
222 dpyName = "";
223
224 crStrncpy(winInfo->dpyName, dpyName, MAX_DPY_NAME);
225 winInfo->dpyName[MAX_DPY_NAME-1] = 0;
226
227 /* Use spuWin as the hash table index and GLX/WGL handle */
228#ifdef WINDOWS
229 winInfo->drawable = (HDC) spuWin;
230 winInfo->hVisibleRegion = INVALID_HANDLE_VALUE;
231#elif defined(Darwin)
232 winInfo->drawable = (CGSWindowID) spuWin;
233#elif defined(GLX)
234 winInfo->drawable = (GLXDrawable) spuWin;
235 winInfo->pVisibleRegions = NULL;
236 winInfo->cVisibleRegions = 0;
237#endif
238#ifdef CR_NEWWINTRACK
239 winInfo->u32ClientID = stub.spu->dispatch_table.VBoxPackGetInjectID(0);
240#endif
241 winInfo->spuWindow = spuWin;
242
243 crHashtableAdd(stub.windowTable, (unsigned int) spuWin, winInfo);
244
245 return spuWin;
246}
247
248#ifdef GLX
249# if 0 /* unused */
250static XErrorHandler oldErrorHandler;
251static unsigned char lastXError = Success;
252
253static int
254errorHandler (Display *dpy, XErrorEvent *e)
255{
256 RT_NOREF(dpy);
257
258 lastXError = e->error_code;
259 return 0;
260}
261# endif /* unused */
262#endif
263
264GLboolean
265stubIsWindowVisible(WindowInfo *win)
266{
267#if defined(WINDOWS)
268# ifdef VBOX_WITH_WDDM
269 if (stub.bRunningUnderWDDM)
270 return win->mapped;
271# endif
272 return GL_TRUE;
273#elif defined(Darwin)
274 return GL_TRUE;
275#elif defined(GLX)
276 Display *dpy = stubGetWindowDisplay(win);
277 if (dpy)
278 {
279 XWindowAttributes attr;
280 XLOCK(dpy);
281 XGetWindowAttributes(dpy, win->drawable, &attr);
282 XUNLOCK(dpy);
283
284 if (attr.map_state == IsUnmapped)
285 {
286 return GL_FALSE;
287 }
288# if 1
289 return GL_TRUE;
290# else
291 if (attr.override_redirect)
292 {
293 return GL_TRUE;
294 }
295
296 if (!stub.bXExtensionsChecked)
297 {
298 stubCheckXExtensions(win);
299 }
300
301 if (!stub.bHaveXComposite)
302 {
303 return GL_TRUE;
304 }
305 else
306 {
307 Pixmap p;
308
309 crLockMutex(&stub.mutex);
310
311 XLOCK(dpy);
312 XSync(dpy, false);
313 oldErrorHandler = XSetErrorHandler(errorHandler);
314 /** @todo this will create new pixmap for window every call*/
315 p = XCompositeNameWindowPixmap(dpy, win->drawable);
316 XSync(dpy, false);
317 XSetErrorHandler(oldErrorHandler);
318 XUNLOCK(dpy);
319
320 switch (lastXError)
321 {
322 case Success:
323 XFreePixmap(dpy, p);
324 crUnlockMutex(&stub.mutex);
325 return GL_FALSE;
326 break;
327 case BadMatch:
328 /*Window isn't redirected*/
329 lastXError = Success;
330 break;
331 default:
332 crWarning("Unexpected XError %i", (int)lastXError);
333 lastXError = Success;
334 }
335
336 crUnlockMutex(&stub.mutex);
337
338 return GL_TRUE;
339 }
340# endif
341 }
342 else {
343 /* probably created by crWindowCreate() */
344 return win->mapped;
345 }
346#endif
347}
348
349
350/**
351 * Given a Windows HDC or GLX Drawable, return the corresponding
352 * WindowInfo structure. Create a new one if needed.
353 */
354WindowInfo *
355#ifdef WINDOWS
356 stubGetWindowInfo( HDC drawable )
357#elif defined(Darwin)
358 stubGetWindowInfo( CGSWindowID drawable )
359#elif defined(GLX)
360stubGetWindowInfo( Display *dpy, GLXDrawable drawable )
361#endif
362{
363#ifndef WINDOWS
364 WindowInfo *winInfo = (WindowInfo *) crHashtableSearch(stub.windowTable, (unsigned int) drawable);
365#else
366 WindowInfo *winInfo;
367 HWND hwnd;
368 hwnd = WindowFromDC(drawable);
369
370 if (!hwnd)
371 {
372 return NULL;
373 }
374
375 winInfo = (WindowInfo *) crHashtableSearch(stub.windowTable, (unsigned int) hwnd);
376#endif
377 if (!winInfo) {
378 winInfo = (WindowInfo *) crCalloc(sizeof(WindowInfo));
379 if (!winInfo)
380 return NULL;
381#ifdef GLX
382 crStrncpy(winInfo->dpyName, DisplayString(dpy), MAX_DPY_NAME);
383 winInfo->dpyName[MAX_DPY_NAME-1] = 0;
384 winInfo->dpy = dpy;
385 winInfo->pVisibleRegions = NULL;
386#elif defined(Darwin)
387 winInfo->connection = _CGSDefaultConnection(); // store our connection as default
388#elif defined(WINDOWS)
389 winInfo->hVisibleRegion = INVALID_HANDLE_VALUE;
390 winInfo->hWnd = hwnd;
391#endif
392 winInfo->drawable = drawable;
393 winInfo->type = UNDECIDED;
394 winInfo->spuWindow = -1;
395#ifdef VBOX_WITH_WDDM
396 if (stub.bRunningUnderWDDM)
397 winInfo->mapped = 0;
398 else
399#endif
400 {
401 winInfo->mapped = -1; /* don't know */
402 }
403 winInfo->pOwner = NULL;
404#ifdef CR_NEWWINTRACK
405 winInfo->u32ClientID = -1;
406#endif
407#ifndef WINDOWS
408 crHashtableAdd(stub.windowTable, (unsigned int) drawable, winInfo);
409#else
410 crHashtableAdd(stub.windowTable, (unsigned int) hwnd, winInfo);
411#endif
412 }
413#ifdef WINDOWS
414 else
415 {
416 winInfo->drawable = drawable;
417 }
418#endif
419 return winInfo;
420}
421
422static void stubWindowCheckOwnerCB(unsigned long key, void *data1, void *data2);
423
424static void
425stubContextFree( ContextInfo *context )
426{
427 crMemZero(context, sizeof(ContextInfo)); /* just to be safe */
428 crFree(context);
429}
430
431static void
432stubDestroyContextLocked( ContextInfo *context )
433{
434 unsigned long contextId = context->id;
435 if (context->type == NATIVE) {
436#ifdef WINDOWS
437 stub.wsInterface.wglDeleteContext( context->hglrc );
438#elif defined(Darwin)
439 stub.wsInterface.CGLDestroyContext( context->cglc );
440#elif defined(GLX)
441 stub.wsInterface.glXDestroyContext( context->dpy, context->glxContext );
442#endif
443 }
444 else if (context->type == CHROMIUM) {
445 /* Have pack SPU or tilesort SPU, etc. destroy the context */
446 CRASSERT(context->spuContext >= 0);
447 stub.spu->dispatch_table.DestroyContext( context->spuContext );
448 crHashtableWalk(stub.windowTable, stubWindowCheckOwnerCB, context);
449#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
450 if (context->spuConnection)
451 {
452 stub.spu->dispatch_table.VBoxConDestroy(context->spuConnection);
453 context->spuConnection = 0;
454 }
455#endif
456 }
457
458#ifdef GLX
459 crFreeHashtable(context->pGLXPixmapsHash, crFree);
460#endif
461
462 crHashtableDelete(stub.contextTable, contextId, NULL);
463}
464
465static DECLCALLBACK(void) stubContextDtor(void*pvContext)
466{
467 stubContextFree((ContextInfo*)pvContext);
468}
469
470/**
471 * Allocate a new ContextInfo object, initialize it, put it into the
472 * context hash table. If type==CHROMIUM, call the head SPU's
473 * CreateContext() function too.
474 */
475 ContextInfo *
476stubNewContext(char *dpyName, GLint visBits, ContextType type, unsigned long shareCtx
477#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
478 , struct VBOXUHGSMI *pHgsmi
479#endif
480 )
481{
482 GLint spuContext = -1, spuShareCtx = 0, spuConnection = 0;
483 ContextInfo *context;
484
485 if (shareCtx > 0) {
486 /* translate shareCtx to a SPU context ID */
487 context = (ContextInfo *)
488 crHashtableSearch(stub.contextTable, shareCtx);
489 if (context)
490 spuShareCtx = context->spuContext;
491 }
492
493 if (type == CHROMIUM) {
494#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
495 if (pHgsmi)
496 {
497 spuConnection = stub.spu->dispatch_table.VBoxConCreate(pHgsmi);
498 if (!spuConnection)
499 {
500 crWarning("VBoxConCreate failed");
501 return NULL;
502 }
503 }
504#endif
505 spuContext
506 = stub.spu->dispatch_table.VBoxCreateContext(spuConnection, dpyName, visBits, spuShareCtx);
507 if (spuContext < 0)
508 {
509 crWarning("VBoxCreateContext failed");
510#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
511 if (spuConnection)
512 stub.spu->dispatch_table.VBoxConDestroy(spuConnection);
513#endif
514 return NULL;
515 }
516 }
517
518 context = crCalloc(sizeof(ContextInfo));
519 if (!context) {
520 stub.spu->dispatch_table.DestroyContext(spuContext);
521#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
522 if (spuConnection)
523 stub.spu->dispatch_table.VBoxConDestroy(spuConnection);
524#endif
525 return NULL;
526 }
527
528 if (!dpyName)
529 dpyName = "";
530
531 context->id = stub.freeContextNumber++;
532 context->type = type;
533 context->spuContext = spuContext;
534 context->visBits = visBits;
535 context->currentDrawable = NULL;
536 crStrncpy(context->dpyName, dpyName, MAX_DPY_NAME);
537 context->dpyName[MAX_DPY_NAME-1] = 0;
538
539#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
540 context->spuConnection = spuConnection;
541 context->pHgsmi = pHgsmi;
542#endif
543
544 VBoxTlsRefInit(context, stubContextDtor);
545
546#if defined(GLX) || defined(DARWIN)
547 context->share = (ContextInfo *)
548 crHashtableSearch(stub.contextTable, (unsigned long) shareCtx);
549#endif
550
551#ifdef GLX
552 context->pGLXPixmapsHash = crAllocHashtable();
553 context->damageQueryFailed = GL_FALSE;
554 context->damageEventsBase = 0;
555#endif
556
557 crHashtableAdd(stub.contextTable, context->id, (void *) context);
558
559 return context;
560}
561
562
563#ifdef Darwin
564
565#define SET_ATTR(l,i,a) ( (l)[(i)++] = (a) )
566#define SET_ATTR_V(l,i,a,v) ( SET_ATTR(l,i,a), SET_ATTR(l,i,v) )
567
568void stubSetPFA( ContextInfo *ctx, CGLPixelFormatAttribute *attribs, int size, GLint *num ) {
569 GLuint visual = ctx->visBits;
570 int i = 0;
571
572 CRASSERT(visual & CR_RGB_BIT);
573
574 SET_ATTR_V(attribs, i, kCGLPFAColorSize, 8);
575
576 if( visual & CR_DEPTH_BIT )
577 SET_ATTR_V(attribs, i, kCGLPFADepthSize, 16);
578
579 if( visual & CR_ACCUM_BIT )
580 SET_ATTR_V(attribs, i, kCGLPFAAccumSize, 1);
581
582 if( visual & CR_STENCIL_BIT )
583 SET_ATTR_V(attribs, i, kCGLPFAStencilSize, 1);
584
585 if( visual & CR_ALPHA_BIT )
586 SET_ATTR_V(attribs, i, kCGLPFAAlphaSize, 1);
587
588 if( visual & CR_DOUBLE_BIT )
589 SET_ATTR(attribs, i, kCGLPFADoubleBuffer);
590
591 if( visual & CR_STEREO_BIT )
592 SET_ATTR(attribs, i, kCGLPFAStereo);
593
594/* SET_ATTR_V(attribs, i, kCGLPFASampleBuffers, 1);
595 SET_ATTR_V(attribs, i, kCGLPFASamples, 0);
596 SET_ATTR_V(attribs, i, kCGLPFADisplayMask, 0); */
597 SET_ATTR(attribs, i, kCGLPFABackingStore);
598 //SET_ATTR(attribs, i, kCGLPFAWindow); // kCGLPFAWindow deprecated starting from OSX 10.7
599 SET_ATTR_V(attribs, i, kCGLPFADisplayMask, ctx->disp_mask);
600
601 SET_ATTR(attribs, i, 0);
602
603 *num = i;
604}
605
606#endif
607
608#ifndef GLX
609/**
610 * This creates a native GLX/WGL context.
611 */
612static GLboolean
613InstantiateNativeContext( WindowInfo *window, ContextInfo *context )
614{
615#ifdef WINDOWS
616 context->hglrc = stub.wsInterface.wglCreateContext( window->drawable );
617 return context->hglrc ? GL_TRUE : GL_FALSE;
618#elif defined(Darwin)
619 CGLContextObj shareCtx = NULL;
620 CGLPixelFormatObj pix;
621 long npix;
622
623 CGLPixelFormatAttribute attribs[16];
624 GLint ind = 0;
625
626 if( context->share ) {
627 if( context->cglc != context->share->cglc ) {
628 crWarning("CGLCreateContext() is trying to share a non-existant "
629 "CGL context. Setting share context to zero.");
630 shareCtx = 0;
631 }
632 else
633 shareCtx = context->cglc;
634 }
635
636 stubSetPFA( context, attribs, 16, &ind );
637
638 stub.wsInterface.CGLChoosePixelFormat( attribs, &pix, &npix );
639 stub.wsInterface.CGLCreateContext( pix, shareCtx, &context->cglc );
640 if( !context->cglc )
641 crError("InstantiateNativeContext: Couldn't Create the context!");
642
643 stub.wsInterface.CGLDestroyPixelFormat( pix );
644
645 if( context->parambits ) {
646 /* Set the delayed parameters */
647 if( context->parambits & VISBIT_SWAP_RECT )
648 stub.wsInterface.CGLSetParameter( context->cglc, kCGLCPSwapRectangle, context->swap_rect );
649
650 if( context->parambits & VISBIT_SWAP_INTERVAL )
651 stub.wsInterface.CGLSetParameter( context->cglc, kCGLCPSwapInterval, &(context->swap_interval) );
652
653 if( context->parambits & VISBIT_CLIENT_STORAGE )
654 stub.wsInterface.CGLSetParameter( context->cglc, kCGLCPClientStorage, (long*)&(context->client_storage) );
655
656 context->parambits = 0;
657 }
658
659 return context->cglc ? GL_TRUE : GL_FALSE;
660#elif defined(GLX)
661 GLXContext shareCtx = 0;
662
663 /* sort out context sharing here */
664 if (context->share) {
665 if (context->glxContext != context->share->glxContext) {
666 crWarning("glXCreateContext() is trying to share a non-existant "
667 "GLX context. Setting share context to zero.");
668 shareCtx = 0;
669 }
670 else {
671 shareCtx = context->glxContext;
672 }
673 }
674
675 context->glxContext = stub.wsInterface.glXCreateContext( window->dpy,
676 context->visual, shareCtx, context->direct );
677
678 return context->glxContext ? GL_TRUE : GL_FALSE;
679#endif
680}
681#endif /* !GLX */
682
683
684/**
685 * Utility functions to get window size and titlebar text.
686 */
687#ifdef WINDOWS
688
689void
690stubGetWindowGeometry(WindowInfo *window, int *x, int *y,
691 unsigned int *w, unsigned int *h )
692{
693 RECT rect;
694
695 if (!window->drawable || !window->hWnd) {
696 *w = *h = 0;
697 return;
698 }
699
700 if (window->hWnd!=WindowFromDC(window->drawable))
701 {
702 crWarning("Window(%i) DC is no longer valid", window->spuWindow);
703 return;
704 }
705
706 if (!GetClientRect(window->hWnd, &rect))
707 {
708 crWarning("GetClientRect failed for %p", window->hWnd);
709 *w = *h = 0;
710 return;
711 }
712 *w = rect.right - rect.left;
713 *h = rect.bottom - rect.top;
714
715 if (!ClientToScreen( window->hWnd, (LPPOINT) &rect ))
716 {
717 crWarning("ClientToScreen failed for %p", window->hWnd);
718 *w = *h = 0;
719 return;
720 }
721 *x = rect.left;
722 *y = rect.top;
723}
724
725static void
726GetWindowTitle( const WindowInfo *window, char *title )
727{
728 /* XXX - we don't handle recurseUp */
729 if (window->hWnd)
730 GetWindowText(window->hWnd, title, 100);
731 else
732 title[0] = 0;
733}
734
735static void
736GetCursorPosition(WindowInfo *window, int pos[2])
737{
738 RECT rect;
739 POINT point;
740 GLint size[2], x, y;
741 unsigned int NativeHeight, NativeWidth, ChromiumHeight, ChromiumWidth;
742 float WidthRatio, HeightRatio;
743 static int DebugFlag = 0;
744
745 // apparently the "window" parameter passed to this
746 // function contains the native window information
747 HWND NATIVEhwnd = window->hWnd;
748
749 if (NATIVEhwnd!=WindowFromDC(window->drawable))
750 {
751 crWarning("Window(%i) DC is no longer valid", window->spuWindow);
752 return;
753 }
754
755 // get the native window's height and width
756 stubGetWindowGeometry(window, &x, &y, &NativeWidth, &NativeHeight);
757
758 // get the spu window's height and width
759 stub.spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_SIZE_CR, window->spuWindow, GL_INT, 2, size);
760 ChromiumWidth = size[0];
761 ChromiumHeight = size[1];
762
763 // get the ratio of the size of the native window to the cr window
764 WidthRatio = (float)ChromiumWidth / (float)NativeWidth;
765 HeightRatio = (float)ChromiumHeight / (float)NativeHeight;
766
767 // output some debug information at the beginning
768 if(DebugFlag)
769 {
770 DebugFlag = 0;
771 crDebug("Native Window Handle = %d", NATIVEhwnd);
772 crDebug("Native Width = %i", NativeWidth);
773 crDebug("Native Height = %i", NativeHeight);
774 crDebug("Chromium Width = %i", ChromiumWidth);
775 crDebug("Chromium Height = %i", ChromiumHeight);
776 }
777
778 if (NATIVEhwnd)
779 {
780 GetClientRect( NATIVEhwnd, &rect );
781 GetCursorPos (&point);
782
783 // make sure these coordinates are relative to the native window,
784 // not the whole desktop
785 ScreenToClient(NATIVEhwnd, &point);
786
787 // calculate the new position of the virtual cursor
788 pos[0] = (int)(point.x * WidthRatio);
789 pos[1] = (int)((NativeHeight - point.y) * HeightRatio);
790 }
791 else
792 {
793 pos[0] = 0;
794 pos[1] = 0;
795 }
796}
797
798#elif defined(Darwin)
799
800extern OSStatus CGSGetScreenRectForWindow( CGSConnectionID cid, CGSWindowID wid, float *outRect );
801extern OSStatus CGSGetWindowBounds( CGSConnectionID cid, CGSWindowID wid, float *bounds );
802
803void
804stubGetWindowGeometry( const WindowInfo *window, int *x, int *y, unsigned int *w, unsigned int *h )
805{
806 float rect[4];
807
808 if( !window ||
809 !window->connection ||
810 !window->drawable ||
811 CGSGetWindowBounds( window->connection, window->drawable, rect ) != noErr )
812 {
813 *x = *y = 0;
814 *w = *h = 0;
815 } else {
816 *x = (int) rect[0];
817 *y = (int) rect[1];
818 *w = (int) rect[2];
819 *h = (int) rect[3];
820 }
821}
822
823
824static void
825GetWindowTitle( const WindowInfo *window, char *title )
826{
827 /* XXX \todo Darwin window Title */
828 title[0] = '\0';
829}
830
831
832static void
833GetCursorPosition( const WindowInfo *window, int pos[2] )
834{
835 Point mouse_pos;
836 float window_rect[4];
837
838 GetMouse( &mouse_pos );
839 CGSGetScreenRectForWindow( window->connection, window->drawable, window_rect );
840
841 pos[0] = mouse_pos.h - (int) window_rect[0];
842 pos[1] = (int) window_rect[3] - (mouse_pos.v - (int) window_rect[1]);
843
844 /*crDebug( "%i %i", pos[0], pos[1] );*/
845}
846
847#elif defined(GLX)
848
849void
850stubGetWindowGeometry(WindowInfo *window, int *x, int *y, unsigned int *w, unsigned int *h)
851{
852 Window root, child;
853 unsigned int border, depth;
854 Display *dpy;
855
856 dpy = stubGetWindowDisplay(window);
857
858 /// @todo Performing those checks is expensive operation, especially for simple apps with high FPS.
859 // Disabling those triples glxgears fps, thus using xevents instead of per frame polling is much more preferred.
860 /// @todo Check similar on windows guests, though doubtful as there're no XSync like calls on windows.
861 if (window && dpy)
862 {
863 XLOCK(dpy);
864 }
865
866 if (!window
867 || !dpy
868 || !window->drawable
869 || !XGetGeometry(dpy, window->drawable, &root, x, y, w, h, &border, &depth)
870 || !XTranslateCoordinates(dpy, window->drawable, root, 0, 0, x, y, &child))
871 {
872 crWarning("Failed to get windows geometry for %p, try xwininfo", window);
873 *x = *y = 0;
874 *w = *h = 0;
875 }
876
877 if (window && dpy)
878 {
879 XUNLOCK(dpy);
880 }
881}
882
883static char *
884GetWindowTitleHelper( Display *dpy, Window window, GLboolean recurseUp )
885{
886 while (1) {
887 char *name;
888 if (!XFetchName(dpy, window, &name))
889 return NULL;
890 if (name[0]) {
891 return name;
892 }
893 else if (recurseUp) {
894 /* This window has no name, try the parent */
895 Status stat;
896 Window root, parent, *children;
897 unsigned int numChildren;
898 stat = XQueryTree( dpy, window, &root, &parent,
899 &children, &numChildren );
900 if (!stat || window == root)
901 return NULL;
902 if (children)
903 XFree(children);
904 window = parent;
905 }
906 else {
907 XFree(name);
908 return NULL;
909 }
910 }
911}
912
913static void
914GetWindowTitle( const WindowInfo *window, char *title )
915{
916 char *t = GetWindowTitleHelper(window->dpy, window->drawable, GL_TRUE);
917 if (t) {
918 crStrcpy(title, t);
919 XFree(t);
920 }
921 else {
922 title[0] = 0;
923 }
924}
925
926
927/**
928 *Return current cursor position in local window coords.
929 */
930static void
931GetCursorPosition(WindowInfo *window, int pos[2] )
932{
933 int rootX, rootY;
934 Window root, child;
935 unsigned int mask;
936 int x, y;
937
938 XLOCK(window->dpy);
939
940 Bool q = XQueryPointer(window->dpy, window->drawable, &root, &child,
941 &rootX, &rootY, &pos[0], &pos[1], &mask);
942 if (q) {
943 unsigned int w, h;
944 stubGetWindowGeometry( window, &x, &y, &w, &h );
945 /* invert Y */
946 pos[1] = (int) h - pos[1] - 1;
947 }
948 else {
949 pos[0] = pos[1] = 0;
950 }
951
952 XUNLOCK(window->dpy);
953}
954
955#endif
956
957
958/**
959 * This function is called by MakeCurrent() and determines whether or
960 * not a new rendering context should be bound to Chromium or the native
961 * OpenGL.
962 * \return GL_FALSE if native OpenGL should be used, or GL_TRUE if Chromium
963 * should be used.
964 */
965static GLboolean
966stubCheckUseChromium( WindowInfo *window )
967{
968 int x, y;
969 unsigned int w, h;
970
971 /* If the provided window is CHROMIUM, we're clearly intended
972 * to create a CHROMIUM context.
973 */
974 if (window->type == CHROMIUM)
975 return GL_TRUE;
976
977 if (stub.ignoreFreeglutMenus) {
978 const char *glutMenuTitle = "freeglut menu";
979 char title[1000];
980 GetWindowTitle(window, title);
981 if (crStrcmp(title, glutMenuTitle) == 0) {
982 crDebug("GL faker: Ignoring freeglut menu window");
983 return GL_FALSE;
984 }
985 }
986
987 /* If the user's specified a window count for Chromium, see if
988 * this window satisfies that criterium.
989 */
990 stub.matchChromiumWindowCounter++;
991 if (stub.matchChromiumWindowCount > 0) {
992 if (stub.matchChromiumWindowCounter != stub.matchChromiumWindowCount) {
993 crDebug("Using native GL, app window doesn't meet match_window_count");
994 return GL_FALSE;
995 }
996 }
997
998 /* If the user's specified a window list to ignore, see if this
999 * window satisfies that criterium.
1000 */
1001 if (stub.matchChromiumWindowID) {
1002 GLuint i;
1003
1004 for (i = 0; i <= stub.numIgnoreWindowID; i++) {
1005 if (stub.matchChromiumWindowID[i] == stub.matchChromiumWindowCounter) {
1006 crDebug("Ignore window ID %d, using native GL", stub.matchChromiumWindowID[i]);
1007 return GL_FALSE;
1008 }
1009 }
1010 }
1011
1012 /* If the user's specified a minimum window size for Chromium, see if
1013 * this window satisfies that criterium.
1014 */
1015 if (stub.minChromiumWindowWidth > 0 &&
1016 stub.minChromiumWindowHeight > 0) {
1017 stubGetWindowGeometry( window, &x, &y, &w, &h );
1018 if (w >= stub.minChromiumWindowWidth &&
1019 h >= stub.minChromiumWindowHeight) {
1020
1021 /* Check for maximum sized window now too */
1022 if (stub.maxChromiumWindowWidth &&
1023 stub.maxChromiumWindowHeight) {
1024 if (w < stub.maxChromiumWindowWidth &&
1025 h < stub.maxChromiumWindowHeight)
1026 return GL_TRUE;
1027 else
1028 return GL_FALSE;
1029 }
1030
1031 return GL_TRUE;
1032 }
1033 crDebug("Using native GL, app window doesn't meet minimum_window_size");
1034 return GL_FALSE;
1035 }
1036 else if (stub.matchWindowTitle) {
1037 /* If the user's specified a window title for Chromium, see if this
1038 * window satisfies that criterium.
1039 */
1040 GLboolean wildcard = GL_FALSE;
1041 char title[1000];
1042 char *titlePattern;
1043 int len;
1044 /* check for leading '*' wildcard */
1045 if (stub.matchWindowTitle[0] == '*') {
1046 titlePattern = crStrdup( stub.matchWindowTitle + 1 );
1047 wildcard = GL_TRUE;
1048 }
1049 else {
1050 titlePattern = crStrdup( stub.matchWindowTitle );
1051 }
1052 /* check for trailing '*' wildcard */
1053 len = crStrlen(titlePattern);
1054 if (len > 0 && titlePattern[len - 1] == '*') {
1055 titlePattern[len - 1] = '\0'; /* terminate here */
1056 wildcard = GL_TRUE;
1057 }
1058
1059 GetWindowTitle( window, title );
1060 if (title[0]) {
1061 if (wildcard) {
1062 if (crStrstr(title, titlePattern)) {
1063 crFree(titlePattern);
1064 return GL_TRUE;
1065 }
1066 }
1067 else if (crStrcmp(title, titlePattern) == 0) {
1068 crFree(titlePattern);
1069 return GL_TRUE;
1070 }
1071 }
1072 crFree(titlePattern);
1073 crDebug("Using native GL, app window title doesn't match match_window_title string (\"%s\" != \"%s\")", title, stub.matchWindowTitle);
1074 return GL_FALSE;
1075 }
1076
1077 /* Window title and size don't matter */
1078 CRASSERT(stub.minChromiumWindowWidth == 0);
1079 CRASSERT(stub.minChromiumWindowHeight == 0);
1080 CRASSERT(stub.matchWindowTitle == NULL);
1081
1082 /* User hasn't specified a width/height or window title.
1083 * We'll use chromium for this window (and context) if no other is.
1084 */
1085
1086 return GL_TRUE; /* use Chromium! */
1087}
1088
1089static void stubWindowCheckOwnerCB(unsigned long key, void *data1, void *data2)
1090{
1091 WindowInfo *pWindow = (WindowInfo *) data1;
1092 ContextInfo *pCtx = (ContextInfo *) data2;
1093
1094 RT_NOREF(key);
1095
1096
1097 if (pWindow->pOwner == pCtx)
1098 {
1099#ifdef WINDOWS
1100 /* Note: can't use WindowFromDC(context->pOwnWindow->drawable) here
1101 because GL context is already released from DC and actual guest window
1102 could be destroyed.
1103 */
1104 stubDestroyWindow(CR_CTX_CON(pCtx), (GLint)pWindow->hWnd);
1105#else
1106 stubDestroyWindow(CR_CTX_CON(pCtx), (GLint)pWindow->drawable);
1107#endif
1108 }
1109}
1110
1111GLboolean stubCtxCreate(ContextInfo *context)
1112{
1113 /*
1114 * Create a Chromium context.
1115 */
1116#if defined(GLX) || defined(DARWIN)
1117 GLint spuShareCtx = context->share ? context->share->spuContext : 0;
1118#else
1119 GLint spuShareCtx = 0;
1120#endif
1121 GLint spuConnection = 0;
1122 CRASSERT(stub.spu);
1123 CRASSERT(stub.spu->dispatch_table.CreateContext);
1124 context->type = CHROMIUM;
1125
1126#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
1127 if (context->pHgsmi)
1128 {
1129 spuConnection = stub.spu->dispatch_table.VBoxConCreate(context->pHgsmi);
1130 if (!spuConnection)
1131 {
1132 crError("VBoxConCreate failed");
1133 return GL_FALSE;
1134 }
1135 context->spuConnection = spuConnection;
1136 }
1137#endif
1138
1139 context->spuContext
1140 = stub.spu->dispatch_table.VBoxCreateContext(spuConnection, context->dpyName,
1141 context->visBits,
1142 spuShareCtx);
1143
1144 return GL_TRUE;
1145}
1146
1147GLboolean stubCtxCheckCreate(ContextInfo *context)
1148{
1149 if (context->type == UNDECIDED)
1150 return stubCtxCreate(context);
1151 return CHROMIUM == context->type;
1152}
1153
1154
1155GLboolean
1156stubMakeCurrent( WindowInfo *window, ContextInfo *context )
1157{
1158 GLboolean retVal = GL_FALSE;
1159
1160 /*
1161 * Get WindowInfo and ContextInfo pointers.
1162 */
1163
1164 if (!context || !window) {
1165 ContextInfo * currentContext = stubGetCurrentContext();
1166 if (currentContext)
1167 currentContext->currentDrawable = NULL;
1168 if (context)
1169 context->currentDrawable = NULL;
1170 stubSetCurrentContext(NULL);
1171 return GL_TRUE; /* OK */
1172 }
1173
1174 stubCheckMultithread();
1175
1176 if (context->type == UNDECIDED) {
1177 /* Here's where we really create contexts */
1178 crLockMutex(&stub.mutex);
1179
1180 if (stubCheckUseChromium(window)) {
1181 GLint spuConnection = 0;
1182
1183 if (!stubCtxCreate(context))
1184 {
1185 crWarning("stubCtxCreate failed");
1186 return GL_FALSE;
1187 }
1188
1189#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
1190 spuConnection = context->spuConnection;
1191#endif
1192
1193 if (window->spuWindow == -1)
1194 {
1195 /*crDebug("(1)stubMakeCurrent ctx=%p(%i) window=%p(%i)", context, context->spuContext, window, window->spuWindow);*/
1196 window->spuWindow = stub.spu->dispatch_table.VBoxWindowCreate(spuConnection, window->dpyName, context->visBits );
1197#ifdef CR_NEWWINTRACK
1198 window->u32ClientID = stub.spu->dispatch_table.VBoxPackGetInjectID(spuConnection);
1199#endif
1200 }
1201 }
1202#ifndef GLX
1203 else {
1204 /*
1205 * Create a native OpenGL context.
1206 */
1207 if (!InstantiateNativeContext(window, context))
1208 {
1209 crUnlockMutex(&stub.mutex);
1210 return 0; /* false */
1211 }
1212 context->type = NATIVE;
1213 }
1214#endif /* !GLX */
1215
1216 crUnlockMutex(&stub.mutex);
1217 }
1218
1219
1220 if (context->type == NATIVE) {
1221 /*
1222 * Native OpenGL MakeCurrent().
1223 */
1224#ifdef WINDOWS
1225 retVal = (GLboolean) stub.wsInterface.wglMakeCurrent( window->drawable, context->hglrc );
1226#elif defined(Darwin)
1227 // XXX \todo We need to differentiate between these two..
1228 retVal = ( stub.wsInterface.CGLSetSurface(context->cglc, window->connection, window->drawable, window->surface) == noErr );
1229 retVal = ( stub.wsInterface.CGLSetCurrentContext(context->cglc) == noErr );
1230#elif defined(GLX)
1231 retVal = (GLboolean) stub.wsInterface.glXMakeCurrent( window->dpy, window->drawable, context->glxContext );
1232#endif
1233 }
1234 else {
1235 /*
1236 * SPU chain MakeCurrent().
1237 */
1238 CRASSERT(context->type == CHROMIUM);
1239 CRASSERT(context->spuContext >= 0);
1240
1241 /*if (context->currentDrawable && context->currentDrawable != window)
1242 crDebug("Rebinding context %p to a different window", context);*/
1243
1244 if (window->type == NATIVE) {
1245 crWarning("Can't rebind a chromium context to a native window\n");
1246 retVal = 0;
1247 }
1248 else {
1249 if (window->spuWindow == -1)
1250 {
1251 /*crDebug("(2)stubMakeCurrent ctx=%p(%i) window=%p(%i)", context, context->spuContext, window, window->spuWindow);*/
1252 window->spuWindow = stub.spu->dispatch_table.VBoxWindowCreate(
1253#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
1254 context->spuConnection,
1255#else
1256 0,
1257#endif
1258 window->dpyName, context->visBits );
1259#ifdef CR_NEWWINTRACK
1260 window->u32ClientID = stub.spu->dispatch_table.VBoxPackGetInjectID(
1261# if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
1262 context->spuConnection
1263# else
1264 0
1265# endif
1266 );
1267#endif
1268 if (context->currentDrawable && context->currentDrawable->type==CHROMIUM
1269 && context->currentDrawable->pOwner==context)
1270 {
1271#ifdef WINDOWS
1272 if (context->currentDrawable->hWnd!=WindowFromDC(context->currentDrawable->drawable))
1273 {
1274 stubDestroyWindow(CR_CTX_CON(context), (GLint)context->currentDrawable->hWnd);
1275 }
1276#else
1277 Window root;
1278 int x, y;
1279 unsigned int border, depth, w, h;
1280
1281 XLOCK(context->currentDrawable->dpy);
1282 if (!XGetGeometry(context->currentDrawable->dpy, context->currentDrawable->drawable, &root, &x, &y, &w, &h, &border, &depth))
1283 {
1284 stubDestroyWindow(CR_CTX_CON(context), (GLint)context->currentDrawable->drawable);
1285 }
1286 XUNLOCK(context->currentDrawable->dpy);
1287#endif
1288
1289 }
1290 }
1291
1292 if (window->spuWindow != (GLint)window->drawable)
1293 stub.spu->dispatch_table.MakeCurrent( window->spuWindow, (GLint) window->drawable, context->spuContext );
1294 else
1295 stub.spu->dispatch_table.MakeCurrent( window->spuWindow, 0, /* native window handle */ context->spuContext );
1296
1297 retVal = 1;
1298 }
1299 }
1300
1301 window->type = context->type;
1302 window->pOwner = context;
1303 context->currentDrawable = window;
1304 stubSetCurrentContext(context);
1305
1306 if (retVal) {
1307 /* Now, if we've transitions from Chromium to native rendering, or
1308 * vice versa, we have to change all the OpenGL entrypoint pointers.
1309 */
1310 if (context->type == NATIVE) {
1311 /* Switch to native API */
1312 /*printf(" Switching to native API\n");*/
1313 stubSetDispatch(&stub.nativeDispatch);
1314 }
1315 else if (context->type == CHROMIUM) {
1316 /* Switch to stub (SPU) API */
1317 /*printf(" Switching to spu API\n");*/
1318 stubSetDispatch(&stub.spuDispatch);
1319 }
1320 else {
1321 /* no API switch needed */
1322 }
1323 }
1324
1325 if (!window->width && window->type == CHROMIUM) {
1326 /* One time window setup */
1327 int x, y;
1328 unsigned int winW, winH;
1329
1330 stubGetWindowGeometry( window, &x, &y, &winW, &winH );
1331
1332 /* If we're not using GLX/WGL (no app window) we'll always get
1333 * a width and height of zero here. In that case, skip the viewport
1334 * call since we're probably using a tilesort SPU with fake_window_dims
1335 * which the tilesort SPU will use for the viewport.
1336 */
1337 window->width = winW;
1338 window->height = winH;
1339#if defined(WINDOWS) && defined(VBOX_WITH_WDDM)
1340 if (stubIsWindowVisible(window))
1341#endif
1342 {
1343 if (stub.trackWindowSize)
1344 stub.spuDispatch.WindowSize( window->spuWindow, winW, winH );
1345 if (stub.trackWindowPos)
1346 stub.spuDispatch.WindowPosition(window->spuWindow, x, y);
1347 if (winW > 0 && winH > 0)
1348 stub.spu->dispatch_table.Viewport( 0, 0, winW, winH );
1349 }
1350#ifdef VBOX_WITH_WDDM
1351 if (stub.trackWindowVisibleRgn)
1352 stub.spu->dispatch_table.WindowVisibleRegion(window->spuWindow, 0, NULL);
1353#endif
1354 }
1355
1356 /* Update window mapping state.
1357 * Basically, this lets us hide render SPU windows which correspond
1358 * to unmapped application windows. Without this, "pertly" (for example)
1359 * opens *lots* of temporary windows which otherwise clutter the screen.
1360 */
1361 if (stub.trackWindowVisibility && window->type == CHROMIUM && window->drawable) {
1362 const int mapped = stubIsWindowVisible(window);
1363 if (mapped != window->mapped) {
1364 crDebug("Dispatched: WindowShow(%i, %i)", window->spuWindow, mapped);
1365 stub.spu->dispatch_table.WindowShow(window->spuWindow, mapped);
1366 window->mapped = mapped;
1367 }
1368 }
1369
1370 return retVal;
1371}
1372
1373void
1374stubDestroyContext( unsigned long contextId )
1375{
1376 ContextInfo *context;
1377
1378 if (!stub.contextTable) {
1379 return;
1380 }
1381
1382 /* the lock order is windowTable->contextTable (see wglMakeCurrent_prox, glXMakeCurrent)
1383 * this is why we need to take a windowTable lock since we will later do stub.windowTable access & locking */
1384 crHashtableLock(stub.windowTable);
1385 crHashtableLock(stub.contextTable);
1386
1387 context = (ContextInfo *) crHashtableSearch(stub.contextTable, contextId);
1388 if (context)
1389 stubDestroyContextLocked(context);
1390 else
1391 crError("No context.");
1392
1393 if (stubGetCurrentContext() == context) {
1394 stubSetCurrentContext(NULL);
1395 }
1396
1397 VBoxTlsRefMarkDestroy(context);
1398 VBoxTlsRefRelease(context);
1399 crHashtableUnlock(stub.contextTable);
1400 crHashtableUnlock(stub.windowTable);
1401}
1402
1403void
1404stubSwapBuffers(WindowInfo *window, GLint flags)
1405{
1406 if (!window)
1407 return;
1408
1409 /* Determine if this window is being rendered natively or through
1410 * Chromium.
1411 */
1412
1413 if (window->type == NATIVE) {
1414 /*printf("*** Swapping native window %d\n", (int) drawable);*/
1415#ifdef WINDOWS
1416 (void) stub.wsInterface.wglSwapBuffers( window->drawable );
1417#elif defined(Darwin)
1418 /* ...is this ok? */
1419/* stub.wsInterface.CGLFlushDrawable( context->cglc ); */
1420 crDebug("stubSwapBuffers: unable to swap (no context!)");
1421#elif defined(GLX)
1422 stub.wsInterface.glXSwapBuffers( window->dpy, window->drawable );
1423#endif
1424 }
1425 else if (window->type == CHROMIUM) {
1426 /* Let the SPU do the buffer swap */
1427 /*printf("*** Swapping chromium window %d\n", (int) drawable);*/
1428 if (stub.appDrawCursor) {
1429 int pos[2];
1430 GetCursorPosition(window, pos);
1431 stub.spu->dispatch_table.ChromiumParametervCR(GL_CURSOR_POSITION_CR, GL_INT, 2, pos);
1432 }
1433 stub.spu->dispatch_table.SwapBuffers( window->spuWindow, flags );
1434 }
1435 else {
1436 crDebug("Calling SwapBuffers on a window we haven't seen before (no-op).");
1437 }
1438}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette