epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
egdaniel | 384181c | 2015-03-26 09:09:41 -0700 | [diff] [blame] | 10 | #include "GrGpuFactory.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 11 | |
tomhudson@google.com | 6bf38b5 | 2012-02-14 15:11:59 +0000 | [diff] [blame] | 12 | #include "gl/GrGLConfig.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 13 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 14 | #include "GrGpu.h" |
jvanverth | 39edf76 | 2014-12-22 11:44:19 -0800 | [diff] [blame] | 15 | #include "gl/GrGLGpu.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 16 | |
egdaniel | 384181c | 2015-03-26 09:09:41 -0700 | [diff] [blame] | 17 | static GrGpu* gl_gpu_create(GrBackendContext backendContext, GrContext* context) { |
epoger@google.com | 17b7894 | 2011-08-26 14:40:38 +0000 | [diff] [blame] | 18 | const GrGLInterface* glInterface = NULL; |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 19 | SkAutoTUnref<const GrGLInterface> glInterfaceUnref; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 20 | |
egdaniel | 384181c | 2015-03-26 09:09:41 -0700 | [diff] [blame] | 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) { |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 30 | #ifdef SK_DEBUG |
egdaniel | 384181c | 2015-03-26 09:09:41 -0700 | [diff] [blame] | 31 | SkDebugf("No GL interface provided!\n"); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 32 | #endif |
egdaniel | 384181c | 2015-03-26 09:09:41 -0700 | [diff] [blame] | 33 | return NULL; |
| 34 | } |
| 35 | GrGLContext ctx(glInterface); |
| 36 | if (ctx.isInitialized()) { |
| 37 | return SkNEW_ARGS(GrGLGpu, (ctx, context)); |
bsalomon@google.com | f987d1b | 2011-04-04 17:13:52 +0000 | [diff] [blame] | 38 | } |
bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 39 | return NULL; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 40 | } |
egdaniel | 384181c | 2015-03-26 09:09:41 -0700 | [diff] [blame] | 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, GrContext* context) { |
| 50 | SkASSERT((int)backend < kMaxNumBackends); |
| 51 | if (!gGpuFactories[backend]) { |
| 52 | return NULL; |
| 53 | } |
| 54 | return (gGpuFactories[backend])(backendContext, context); |
| 55 | } |