1 | /* $Id: feedback_context.c 19099 2009-04-22 09:13:20Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | * VBox feedback spu, context tracking.
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2009 Sun Microsystems, Inc.
|
---|
9 | *
|
---|
10 | * Sun Microsystems, Inc. confidential
|
---|
11 | * All rights reserved
|
---|
12 | */
|
---|
13 |
|
---|
14 | #include "cr_spu.h"
|
---|
15 | #include "cr_error.h"
|
---|
16 | #include "feedbackspu.h"
|
---|
17 |
|
---|
18 | /*@todo Multithreading case. (See feedback_spu.self.RenderMode)*/
|
---|
19 |
|
---|
20 | GLint FEEDBACKSPU_APIENTRY
|
---|
21 | feedbackspu_CreateContext( const char *dpyName, GLint visual, GLint shareCtx )
|
---|
22 | {
|
---|
23 | GLint ctx, slot;
|
---|
24 |
|
---|
25 | #ifdef CHROMIUM_THREADSAFE
|
---|
26 | crLockMutex(&feedback_spu.mutex);
|
---|
27 | #endif
|
---|
28 |
|
---|
29 | ctx = feedback_spu.child.CreateContext(dpyName, visual, shareCtx);
|
---|
30 |
|
---|
31 | /* find an empty context slot */
|
---|
32 | for (slot = 0; slot < feedback_spu.numContexts; slot++) {
|
---|
33 | if (!feedback_spu.context[slot].clientState) {
|
---|
34 | /* found empty slot */
|
---|
35 | break;
|
---|
36 | }
|
---|
37 | }
|
---|
38 | if (slot == feedback_spu.numContexts) {
|
---|
39 | feedback_spu.numContexts++;
|
---|
40 | }
|
---|
41 |
|
---|
42 | feedback_spu.context[slot].clientState = crStateCreateContext(NULL, visual, NULL);
|
---|
43 | feedback_spu.context[slot].clientCtx = ctx;
|
---|
44 |
|
---|
45 | #ifdef CHROMIUM_THREADSAFE
|
---|
46 | crUnlockMutex(&feedback_spu.mutex);
|
---|
47 | #endif
|
---|
48 |
|
---|
49 | return ctx;
|
---|
50 | }
|
---|
51 |
|
---|
52 | void FEEDBACKSPU_APIENTRY
|
---|
53 | feedbackspu_MakeCurrent( GLint window, GLint nativeWindow, GLint ctx )
|
---|
54 | {
|
---|
55 | #ifdef CHROMIUM_THREADSAFE
|
---|
56 | crLockMutex(&feedback_spu.mutex);
|
---|
57 | #endif
|
---|
58 | feedback_spu.child.MakeCurrent(window, nativeWindow, ctx);
|
---|
59 |
|
---|
60 | if (ctx) {
|
---|
61 | int slot;
|
---|
62 | GLint oldmode;
|
---|
63 |
|
---|
64 | for (slot=0; slot<feedback_spu.numContexts; ++slot)
|
---|
65 | if (feedback_spu.context[slot].clientCtx == ctx) break;
|
---|
66 | CRASSERT(slot < feedback_spu.numContexts);
|
---|
67 |
|
---|
68 | crStateMakeCurrent(feedback_spu.context[slot].clientState);
|
---|
69 |
|
---|
70 | crStateGetIntegerv(GL_RENDER_MODE, &oldmode);
|
---|
71 |
|
---|
72 | if (oldmode!=feedback_spu.render_mode)
|
---|
73 | {
|
---|
74 | feedback_spu.self.RenderMode(oldmode);
|
---|
75 | }
|
---|
76 | }
|
---|
77 | else
|
---|
78 | {
|
---|
79 | crStateMakeCurrent(NULL);
|
---|
80 | }
|
---|
81 |
|
---|
82 | #ifdef CHROMIUM_THREADSAFE
|
---|
83 | crUnlockMutex(&feedback_spu.mutex);
|
---|
84 | #endif
|
---|
85 | }
|
---|
86 |
|
---|
87 | void FEEDBACKSPU_APIENTRY
|
---|
88 | feedbackspu_DestroyContext( GLint ctx )
|
---|
89 | {
|
---|
90 | #ifdef CHROMIUM_THREADSAFE
|
---|
91 | crLockMutex(&feedback_spu.mutex);
|
---|
92 | #endif
|
---|
93 | feedback_spu.child.DestroyContext(ctx);
|
---|
94 |
|
---|
95 | if (ctx) {
|
---|
96 | int slot;
|
---|
97 |
|
---|
98 | for (slot=0; slot<feedback_spu.numContexts; ++slot)
|
---|
99 | if (feedback_spu.context[slot].clientCtx == ctx) break;
|
---|
100 | CRASSERT(slot < feedback_spu.numContexts);
|
---|
101 |
|
---|
102 | crStateDestroyContext(feedback_spu.context[slot].clientState);
|
---|
103 |
|
---|
104 | feedback_spu.context[slot].clientState = NULL;
|
---|
105 | feedback_spu.context[slot].clientCtx = 0;
|
---|
106 | }
|
---|
107 |
|
---|
108 | #ifdef CHROMIUM_THREADSAFE
|
---|
109 | crUnlockMutex(&feedback_spu.mutex);
|
---|
110 | #endif
|
---|
111 | }
|
---|