OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "GrGpuFactory.h" | 10 #include "GrGpuFactory.h" |
11 | 11 |
| 12 #include "GrGpu.h" |
12 #include "gl/GrGLConfig.h" | 13 #include "gl/GrGLConfig.h" |
13 | |
14 #include "GrGpu.h" | |
15 #include "gl/GrGLGpu.h" | 14 #include "gl/GrGLGpu.h" |
16 | 15 |
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; | 16 static const int kMaxNumBackends = 4; |
43 static CreateGpuProc gGpuFactories[kMaxNumBackends] = {gl_gpu_create, NULL, NULL
, NULL}; | 17 static CreateGpuProc gGpuFactories[kMaxNumBackends] = {GrGLGpu::Create, NULL, NU
LL, NULL}; |
44 | 18 |
45 GrGpuFactoryRegistrar::GrGpuFactoryRegistrar(int i, CreateGpuProc proc) { | 19 GrGpuFactoryRegistrar::GrGpuFactoryRegistrar(int i, CreateGpuProc proc) { |
46 gGpuFactories[i] = proc; | 20 gGpuFactories[i] = proc; |
47 } | 21 } |
48 | 22 |
49 GrGpu* GrGpu::Create(GrBackend backend, GrBackendContext backendContext, GrConte
xt* context) { | 23 GrGpu* GrGpu::Create(GrBackend backend, GrBackendContext backendContext, GrConte
xt* context) { |
50 SkASSERT((int)backend < kMaxNumBackends); | 24 SkASSERT((int)backend < kMaxNumBackends); |
51 if (!gGpuFactories[backend]) { | 25 if (!gGpuFactories[backend]) { |
52 return NULL; | 26 return NULL; |
53 } | 27 } |
54 return (gGpuFactories[backend])(backendContext, context); | 28 return (gGpuFactories[backend])(backendContext, context); |
55 } | 29 } |
OLD | NEW |