1 | /* $Id: feedback_context.c 42499 2012-08-01 10:26:43Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | * VBox feedback spu, context tracking.
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2009 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include "cr_spu.h"
|
---|
20 | #include "cr_error.h"
|
---|
21 | #include "feedbackspu.h"
|
---|
22 |
|
---|
23 | /*@todo Multithreading case. (See feedback_spu.self.RenderMode)*/
|
---|
24 |
|
---|
25 | GLint FEEDBACKSPU_APIENTRY
|
---|
26 | feedbackspu_VBoxCreateContext( GLint con, const char *dpyName, GLint visual, GLint shareCtx )
|
---|
27 | {
|
---|
28 | GLint ctx, slot;
|
---|
29 |
|
---|
30 | #ifdef CHROMIUM_THREADSAFE
|
---|
31 | crLockMutex(&feedback_spu.mutex);
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | ctx = feedback_spu.child.VBoxCreateContext(con, dpyName, visual, shareCtx);
|
---|
35 |
|
---|
36 | /* find an empty context slot */
|
---|
37 | for (slot = 0; slot < feedback_spu.numContexts; slot++) {
|
---|
38 | if (!feedback_spu.context[slot].clientState) {
|
---|
39 | /* found empty slot */
|
---|
40 | break;
|
---|
41 | }
|
---|
42 | }
|
---|
43 | if (slot == feedback_spu.numContexts) {
|
---|
44 | feedback_spu.numContexts++;
|
---|
45 | }
|
---|
46 |
|
---|
47 | feedback_spu.context[slot].clientState = crStateCreateContext(NULL, visual, NULL);
|
---|
48 | feedback_spu.context[slot].clientCtx = ctx;
|
---|
49 |
|
---|
50 | #ifdef CHROMIUM_THREADSAFE
|
---|
51 | crUnlockMutex(&feedback_spu.mutex);
|
---|
52 | #endif
|
---|
53 |
|
---|
54 | return ctx;
|
---|
55 | }
|
---|
56 |
|
---|
57 | GLint FEEDBACKSPU_APIENTRY
|
---|
58 | feedbackspu_CreateContext( const char *dpyName, GLint visual, GLint shareCtx )
|
---|
59 | {
|
---|
60 | return feedbackspu_VBoxCreateContext( 0, dpyName, visual, shareCtx );
|
---|
61 | }
|
---|
62 |
|
---|
63 | void FEEDBACKSPU_APIENTRY
|
---|
64 | feedbackspu_MakeCurrent( GLint window, GLint nativeWindow, GLint ctx )
|
---|
65 | {
|
---|
66 | #ifdef CHROMIUM_THREADSAFE
|
---|
67 | crLockMutex(&feedback_spu.mutex);
|
---|
68 | #endif
|
---|
69 | feedback_spu.child.MakeCurrent(window, nativeWindow, ctx);
|
---|
70 |
|
---|
71 | if (ctx) {
|
---|
72 | int slot;
|
---|
73 | GLint oldmode;
|
---|
74 |
|
---|
75 | for (slot=0; slot<feedback_spu.numContexts; ++slot)
|
---|
76 | if (feedback_spu.context[slot].clientCtx == ctx) break;
|
---|
77 | CRASSERT(slot < feedback_spu.numContexts);
|
---|
78 |
|
---|
79 | crStateMakeCurrent(feedback_spu.context[slot].clientState);
|
---|
80 |
|
---|
81 | crStateGetIntegerv(GL_RENDER_MODE, &oldmode);
|
---|
82 |
|
---|
83 | if (oldmode!=feedback_spu.render_mode)
|
---|
84 | {
|
---|
85 | feedback_spu.self.RenderMode(oldmode);
|
---|
86 | }
|
---|
87 | }
|
---|
88 | else
|
---|
89 | {
|
---|
90 | crStateMakeCurrent(NULL);
|
---|
91 | }
|
---|
92 |
|
---|
93 | #ifdef CHROMIUM_THREADSAFE
|
---|
94 | crUnlockMutex(&feedback_spu.mutex);
|
---|
95 | #endif
|
---|
96 | }
|
---|
97 |
|
---|
98 | void FEEDBACKSPU_APIENTRY
|
---|
99 | feedbackspu_DestroyContext( GLint ctx )
|
---|
100 | {
|
---|
101 | #ifdef CHROMIUM_THREADSAFE
|
---|
102 | crLockMutex(&feedback_spu.mutex);
|
---|
103 | #endif
|
---|
104 | feedback_spu.child.DestroyContext(ctx);
|
---|
105 |
|
---|
106 | if (ctx) {
|
---|
107 | int slot;
|
---|
108 |
|
---|
109 | for (slot=0; slot<feedback_spu.numContexts; ++slot)
|
---|
110 | if (feedback_spu.context[slot].clientCtx == ctx) break;
|
---|
111 | CRASSERT(slot < feedback_spu.numContexts);
|
---|
112 |
|
---|
113 | crStateDestroyContext(feedback_spu.context[slot].clientState);
|
---|
114 |
|
---|
115 | feedback_spu.context[slot].clientState = NULL;
|
---|
116 | feedback_spu.context[slot].clientCtx = 0;
|
---|
117 | }
|
---|
118 |
|
---|
119 | #ifdef CHROMIUM_THREADSAFE
|
---|
120 | crUnlockMutex(&feedback_spu.mutex);
|
---|
121 | #endif
|
---|
122 | }
|
---|