-#include <gltrace.hpp>
-#include <os_thread.hpp>
+/*********************************************************************
+ *
+ * Copyright 2012 Intel Corporation
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ *********************************************************************/
+
#include <assert.h>
+
+#include <map>
+#if defined(_MSC_VER)
+#include <memory>
+#else
#include <tr1/memory>
+#endif
+
+#include <os_thread.hpp>
+#include <glproc.hpp>
+#include <gltrace.hpp>
namespace gltrace {
}
};
-static os::thread_specific_ptr<struct ThreadState> thread_state;
+static OS_THREAD_SPECIFIC_PTR(ThreadState) thread_state;
static ThreadState *get_ts(void)
{
- ThreadState *ts = thread_state.get();
-
+ ThreadState *ts = thread_state;
if (!ts) {
- ts = new ThreadState;
- thread_state.reset(ts);
+ thread_state = ts = new ThreadState;
}
return ts;
*/
bool releaseContext(uintptr_t context_id)
{
- bool res;
+ bool res = false;
context_map_mutex.lock();
/*
void createContext(uintptr_t context_id)
{
+ // wglCreateContextAttribsARB causes internal calls to wglCreateContext to be
+ // traced, causing context to be defined twice.
+ if (context_map.find(context_id) != context_map.end()) {
+ return;
+ }
+
context_ptr_t ctx(new Context);
context_map_mutex.lock();
_retainContext(ctx);
- assert(context_map.find(context_id) == context_map.end());
context_map[context_id] = ctx;
context_map_mutex.unlock();
}
-/*
- * return true if the context has been destroyed, false otherwise. See
- * the note at releaseContext about the actual ccontext lifetime.
- */
-bool destroyContext(uintptr_t context_id)
-{
- return releaseContext(context_id);
-}
-
void setContext(uintptr_t context_id)
{
ThreadState *ts = get_ts();
context_map_mutex.unlock();
ts->current_context = ctx;
+
+ if (!ctx->bound) {
+ ctx->bound = true;
+
+ /*
+ * The default viewport and scissor state is set when a context is
+ * first made current, with values matching the bound drawable. Many
+ * applications never thouch the default state ever again.
+ *
+ * Since we currently don't trace window sizes, and rely on viewport
+ * calls to deduct, emit fake calls here so that viewport/scissor state
+ * can be deducated.
+ *
+ * FIXME: don't call the real functions here -- just emit the fake
+ * calls.
+ */
+ GLint viewport[4] = {0, 0, 0, 0};
+ GLint scissor_box[4] = {0, 0, 0, 0};
+ _glGetIntegerv(GL_VIEWPORT, viewport);
+ _glGetIntegerv(GL_SCISSOR_BOX, scissor_box);
+ glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
+ glScissor(scissor_box[0], scissor_box[1], scissor_box[2], scissor_box[3]);
+ }
}
void clearContext(void)