Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(339)

Unified Diff: src/gpu/gl/SkNullGLContext.cpp

Issue 919783002: Make null GL context use callback to make current (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: struct- Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/gpu/gl/SkNullGLContext.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/gl/SkNullGLContext.cpp
diff --git a/src/gpu/gl/SkNullGLContext.cpp b/src/gpu/gl/SkNullGLContext.cpp
index 2bc417df92bc4be233d690127a4f843f9a3f4595..42dafc5dee0631c39ce772a0667cea6ac460a7b6 100644
--- a/src/gpu/gl/SkNullGLContext.cpp
+++ b/src/gpu/gl/SkNullGLContext.cpp
@@ -13,7 +13,7 @@
#include "SkTDArray.h"
#include "SkTLS.h"
-static const SkNullGLContext* current_context();
+static SkNullGLContext::ContextState* current_context();
/////////////////////////////////////////////////////////////////////////////////////////////////
@@ -115,7 +115,7 @@ private:
/**
* The state object for the null interface.
*/
-struct SkNullGLContext::ContextState {
+class SkNullGLContext::ContextState : public SkRefCnt {
public:
SK_DECLARE_INST_COUNT(ContextState);
@@ -132,11 +132,7 @@ public:
, fCurrProgramID(0)
, fCurrShaderID(0) {}
- static ContextState* Get() {
- const SkNullGLContext* context = current_context();
- SkASSERT(context);
- return context->fState;
- }
+ static ContextState* Get() { return current_context(); }
};
typedef SkNullGLContext::ContextState State;
@@ -338,10 +334,19 @@ GrGLvoid GR_GL_FUNCTION_TYPE nullGLGetBufferParameteriv(GrGLenum target, GrGLenu
}
};
+class NullInterface : public GrGLInterface {
+public:
+ NullInterface(State* state) : fState(SkRef(state)) {}
+ ~NullInterface() SK_OVERRIDE {
+ fState->unref();
+ }
+ State* fState;
+};
+
} // end anonymous namespace
-static const GrGLInterface* create_null_interface() {
- GrGLInterface* interface = SkNEW(GrGLInterface);
+static GrGLInterface* create_null_interface(State* state) {
+ GrGLInterface* interface = SkNEW_ARGS(NullInterface, (state));
interface->fStandard = kGL_GrGLStandard;
@@ -489,35 +494,40 @@ static const GrGLInterface* create_null_interface() {
//////////////////////////////////////////////////////////////////////////////
static void* create_tls() {
- const SkNullGLContext** current = SkNEW(const SkNullGLContext*);
+ State** current = SkNEW(State*);
*current = NULL;
return current;
}
static void delete_tls(void* ctx) {
- const SkNullGLContext** current = static_cast<const SkNullGLContext**>(ctx);
+ State** current = static_cast<State**>(ctx);
if (*current) {
(*current)->unref();
}
SkDELETE(current);
}
-static const SkNullGLContext* current_context() {
- return *static_cast<const SkNullGLContext**>(SkTLS::Get(create_tls, delete_tls));
+static State* current_context() {
+ return *static_cast<State**>(SkTLS::Get(create_tls, delete_tls));
}
-static void set_current_context(const SkNullGLContext* context) {
- const SkNullGLContext** current =
- static_cast<const SkNullGLContext**>(SkTLS::Get(create_tls, delete_tls));
+static void set_current_context(State* state) {
+ State** current = static_cast<State**>(SkTLS::Get(create_tls, delete_tls));
if (*current) {
(*current)->unref();
}
- *current = context;
- if (context) {
- context->ref();
+ *current = state;
+ if (state) {
+ state->ref();
}
}
+#if GR_GL_PER_GL_FUNC_CALLBACK
+static void set_current_context_from_interface(const GrGLInterface* interface) {
+ set_current_context(reinterpret_cast<State*>(interface->fCallbackData));
+}
+#endif
+
SkNullGLContext* SkNullGLContext::Create(GrGLStandard forcedGpuAPI) {
if (kGLES_GrGLStandard == forcedGpuAPI) {
return NULL;
@@ -531,13 +541,18 @@ SkNullGLContext* SkNullGLContext::Create(GrGLStandard forcedGpuAPI) {
}
SkNullGLContext::SkNullGLContext() {
- fGL.reset(create_null_interface());
fState = SkNEW(ContextState);
+ GrGLInterface* interface = create_null_interface(fState);
+ fGL.reset(interface);
+#if GR_GL_PER_GL_FUNC_CALLBACK
+ interface->fCallback = set_current_context_from_interface;
+ interface->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(fState);
+#endif
}
SkNullGLContext::~SkNullGLContext() {
fGL.reset(NULL);
- SkDELETE(fState);
+ fState->unref();
}
-void SkNullGLContext::makeCurrent() const { set_current_context(this); }
+void SkNullGLContext::makeCurrent() const { set_current_context(fState); }
« no previous file with comments | « include/gpu/gl/SkNullGLContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698