blob: 74adf98236706662fe04c1582e14276913c007c4 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.comac10a2d2010-12-22 21:39:39 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * 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.comac10a2d2010-12-22 21:39:39 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
egdaniel384181c2015-03-26 09:09:41 -070010#include "GrGpuFactory.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000011
tomhudson@google.com6bf38b52012-02-14 15:11:59 +000012#include "gl/GrGLConfig.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000013
reed@google.comac10a2d2010-12-22 21:39:39 +000014#include "GrGpu.h"
jvanverth39edf762014-12-22 11:44:19 -080015#include "gl/GrGLGpu.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000016
egdaniel384181c2015-03-26 09:09:41 -070017static GrGpu* gl_gpu_create(GrBackendContext backendContext, GrContext* context) {
epoger@google.com17b78942011-08-26 14:40:38 +000018 const GrGLInterface* glInterface = NULL;
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000019 SkAutoTUnref<const GrGLInterface> glInterfaceUnref;
bsalomon@google.com0b77d682011-08-19 13:28:54 +000020
egdaniel384181c2015-03-26 09:09:41 -070021 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.org515dcd32013-08-28 14:17:03 +000030#ifdef SK_DEBUG
egdaniel384181c2015-03-26 09:09:41 -070031 SkDebugf("No GL interface provided!\n");
bsalomon@google.com0b77d682011-08-19 13:28:54 +000032#endif
egdaniel384181c2015-03-26 09:09:41 -070033 return NULL;
34 }
35 GrGLContext ctx(glInterface);
36 if (ctx.isInitialized()) {
37 return SkNEW_ARGS(GrGLGpu, (ctx, context));
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000038 }
bsalomon@google.com89ec61e2012-02-10 20:05:18 +000039 return NULL;
reed@google.comac10a2d2010-12-22 21:39:39 +000040}
egdaniel384181c2015-03-26 09:09:41 -070041
42static const int kMaxNumBackends = 4;
43static CreateGpuProc gGpuFactories[kMaxNumBackends] = {gl_gpu_create, NULL, NULL, NULL};
44
45GrGpuFactoryRegistrar::GrGpuFactoryRegistrar(int i, CreateGpuProc proc) {
46 gGpuFactories[i] = proc;
47}
48
49GrGpu* 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}