1
2 /*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
10 #include "GrGpuFactory.h"
11
12 #include "gl/GrGLConfig.h"
13
14 #include "GrGpu.h"
15 #include "gl/GrGLGpu.h"
16
gl_gpu_create(GrBackendContext backendContext,GrContext * context)17 static GrGpu* gl_gpu_create(GrBackendContext backendContext, GrContext* context) {
18 const GrGLInterface* glInterface = NULL;
19 SkAutoTUnref<const GrGLInterface> glInterfaceUnref;
20
21 glInterface = reinterpret_cast<const GrGLInterface*>(backendContext);
22 if (NULL == glInterface) {
23 glInterface = GrGLDefaultInterface();
24 // By calling GrGLDefaultInterface we've taken a ref on the
25 // returned object. We only want to hold that ref until after
26 // the GrGpu is constructed and has taken ownership.
27 glInterfaceUnref.reset(glInterface);
28 }
29 if (NULL == glInterface) {
30 #ifdef SK_DEBUG
31 SkDebugf("No GL interface provided!\n");
32 #endif
33 return NULL;
34 }
35 GrGLContext ctx(glInterface);
36 if (ctx.isInitialized()) {
37 return SkNEW_ARGS(GrGLGpu, (ctx, context));
38 }
39 return NULL;
40 }
41
42 static const int kMaxNumBackends = 4;
43 static CreateGpuProc gGpuFactories[kMaxNumBackends] = {gl_gpu_create, NULL, NULL, NULL};
44
GrGpuFactoryRegistrar(int i,CreateGpuProc proc)45 GrGpuFactoryRegistrar::GrGpuFactoryRegistrar(int i, CreateGpuProc proc) {
46 gGpuFactories[i] = proc;
47 }
48
Create(GrBackend backend,GrBackendContext backendContext,GrContext * context)49 GrGpu* GrGpu::Create(GrBackend backend, GrBackendContext backendContext, GrContext* context) {
50 SkASSERT((int)backend < kMaxNumBackends);
51 if (!gGpuFactories[backend]) {
52 return NULL;
53 }
54 return (gGpuFactories[backend])(backendContext, context);
55 }
56