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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/gpu/GrGpuFactory.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "GrTypes.h" 10 #include "GrGpuFactory.h"
11 11
12 #include "gl/GrGLConfig.h" 12 #include "gl/GrGLConfig.h"
13 13
14 #include "GrGpu.h" 14 #include "GrGpu.h"
15 #include "gl/GrGLGpu.h" 15 #include "gl/GrGLGpu.h"
16 16
17 GrGpu* GrGpu::Create(GrBackend backend, GrBackendContext backendContext, GrConte xt* context) { 17 static GrGpu* gl_gpu_create(GrBackendContext backendContext, GrContext* context) {
18
19 const GrGLInterface* glInterface = NULL; 18 const GrGLInterface* glInterface = NULL;
20 SkAutoTUnref<const GrGLInterface> glInterfaceUnref; 19 SkAutoTUnref<const GrGLInterface> glInterfaceUnref;
21 20
22 if (kOpenGL_GrBackend == backend) { 21 glInterface = reinterpret_cast<const GrGLInterface*>(backendContext);
23 glInterface = reinterpret_cast<const GrGLInterface*>(backendContext); 22 if (NULL == glInterface) {
24 if (NULL == glInterface) { 23 glInterface = GrGLDefaultInterface();
25 glInterface = GrGLDefaultInterface(); 24 // By calling GrGLDefaultInterface we've taken a ref on the
26 // By calling GrGLDefaultInterface we've taken a ref on the 25 // returned object. We only want to hold that ref until after
27 // returned object. We only want to hold that ref until after 26 // the GrGpu is constructed and has taken ownership.
28 // the GrGpu is constructed and has taken ownership. 27 glInterfaceUnref.reset(glInterface);
29 glInterfaceUnref.reset(glInterface); 28 }
30 } 29 if (NULL == glInterface) {
31 if (NULL == glInterface) {
32 #ifdef SK_DEBUG 30 #ifdef SK_DEBUG
33 SkDebugf("No GL interface provided!\n"); 31 SkDebugf("No GL interface provided!\n");
34 #endif 32 #endif
35 return NULL; 33 return NULL;
36 } 34 }
37 GrGLContext ctx(glInterface); 35 GrGLContext ctx(glInterface);
38 if (ctx.isInitialized()) { 36 if (ctx.isInitialized()) {
39 return SkNEW_ARGS(GrGLGpu, (ctx, context)); 37 return SkNEW_ARGS(GrGLGpu, (ctx, context));
40 }
41 } 38 }
42 return NULL; 39 return NULL;
43 } 40 }
41
42 static const int kMaxNumBackends = 4;
43 static CreateGpuProc gGpuFactories[kMaxNumBackends] = {gl_gpu_create, NULL, NULL , NULL};
44
45 GrGpuFactoryRegistrar::GrGpuFactoryRegistrar(int i, CreateGpuProc proc) {
46 gGpuFactories[i] = proc;
47 }
48
49 GrGpu* GrGpu::Create(GrBackend backend, GrBackendContext backendContext, GrConte xt* context) {
50 SkASSERT((int)backend < kMaxNumBackends);
51 if (!gGpuFactories[backend]) {
52 return NULL;
53 }
54 return (gGpuFactories[backend])(backendContext, context);
55 }
OLDNEW
« 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