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

Unified Diff: src/gpu/GrGpuFactory.cpp

Issue 1038643002: Add support for using alternative backends (like DirectX) when creating a GrGpu. (Closed) Base URL: https://chromium.googlesource.com/skia@master
Patch Set: Created 5 years, 9 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 | « src/gpu/GrGpuFactory.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrGpuFactory.cpp
diff --git a/src/gpu/GrGpuFactory.cpp b/src/gpu/GrGpuFactory.cpp
index 4b09c14e5182ae9e299c073403f5835b3537cec1..74adf98236706662fe04c1582e14276913c007c4 100644
--- a/src/gpu/GrGpuFactory.cpp
+++ b/src/gpu/GrGpuFactory.cpp
@@ -7,37 +7,49 @@
*/
-#include "GrTypes.h"
+#include "GrGpuFactory.h"
#include "gl/GrGLConfig.h"
#include "GrGpu.h"
#include "gl/GrGLGpu.h"
-GrGpu* GrGpu::Create(GrBackend backend, GrBackendContext backendContext, GrContext* context) {
-
+static GrGpu* gl_gpu_create(GrBackendContext backendContext, GrContext* context) {
const GrGLInterface* glInterface = NULL;
SkAutoTUnref<const GrGLInterface> glInterfaceUnref;
- if (kOpenGL_GrBackend == backend) {
- glInterface = reinterpret_cast<const GrGLInterface*>(backendContext);
- if (NULL == glInterface) {
- glInterface = GrGLDefaultInterface();
- // By calling GrGLDefaultInterface we've taken a ref on the
- // returned object. We only want to hold that ref until after
- // the GrGpu is constructed and has taken ownership.
- glInterfaceUnref.reset(glInterface);
- }
- if (NULL == glInterface) {
+ glInterface = reinterpret_cast<const GrGLInterface*>(backendContext);
+ if (NULL == glInterface) {
+ glInterface = GrGLDefaultInterface();
+ // By calling GrGLDefaultInterface we've taken a ref on the
+ // returned object. We only want to hold that ref until after
+ // the GrGpu is constructed and has taken ownership.
+ glInterfaceUnref.reset(glInterface);
+ }
+ if (NULL == glInterface) {
#ifdef SK_DEBUG
- SkDebugf("No GL interface provided!\n");
+ SkDebugf("No GL interface provided!\n");
#endif
- return NULL;
- }
- GrGLContext ctx(glInterface);
- if (ctx.isInitialized()) {
- return SkNEW_ARGS(GrGLGpu, (ctx, context));
- }
+ return NULL;
+ }
+ GrGLContext ctx(glInterface);
+ if (ctx.isInitialized()) {
+ return SkNEW_ARGS(GrGLGpu, (ctx, context));
}
return NULL;
}
+
+static const int kMaxNumBackends = 4;
+static CreateGpuProc gGpuFactories[kMaxNumBackends] = {gl_gpu_create, NULL, NULL, NULL};
+
+GrGpuFactoryRegistrar::GrGpuFactoryRegistrar(int i, CreateGpuProc proc) {
+ gGpuFactories[i] = proc;
+}
+
+GrGpu* GrGpu::Create(GrBackend backend, GrBackendContext backendContext, GrContext* context) {
+ SkASSERT((int)backend < kMaxNumBackends);
+ if (!gGpuFactories[backend]) {
+ return NULL;
+ }
+ return (gGpuFactories[backend])(backendContext, context);
+}
« no previous file with comments | « src/gpu/GrGpuFactory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698