|
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 "GrTypes.h" |
|
11 |
|
12 #include "gl/GrGLConfig.h" |
|
13 |
|
14 #include "GrGpu.h" |
|
15 #include "gl/GrGpuGL.h" |
|
16 |
|
17 GrGpu* GrGpu::Create(GrBackend backend, GrBackendContext backendContext, GrContext* context) { |
|
18 |
|
19 const GrGLInterface* glInterface = NULL; |
|
20 SkAutoTUnref<const GrGLInterface> glInterfaceUnref; |
|
21 |
|
22 if (kOpenGL_GrBackend == backend) { |
|
23 glInterface = reinterpret_cast<const GrGLInterface*>(backendContext); |
|
24 if (NULL == glInterface) { |
|
25 glInterface = GrGLDefaultInterface(); |
|
26 // By calling GrGLDefaultInterface we've taken a ref on the |
|
27 // returned object. We only want to hold that ref until after |
|
28 // the GrGpu is constructed and has taken ownership. |
|
29 glInterfaceUnref.reset(glInterface); |
|
30 } |
|
31 if (NULL == glInterface) { |
|
32 #ifdef SK_DEBUG |
|
33 GrPrintf("No GL interface provided!\n"); |
|
34 #endif |
|
35 return NULL; |
|
36 } |
|
37 GrGLContext ctx(glInterface); |
|
38 if (ctx.isInitialized()) { |
|
39 return SkNEW_ARGS(GrGpuGL, (ctx, context)); |
|
40 } |
|
41 } |
|
42 return NULL; |
|
43 } |