aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrGpuFactory.cpp
blob: 74adf98236706662fe04c1582e14276913c007c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

/*
 * Copyright 2011 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */


#include "GrGpuFactory.h"

#include "gl/GrGLConfig.h"

#include "GrGpu.h"
#include "gl/GrGLGpu.h"

static GrGpu* gl_gpu_create(GrBackendContext backendContext, GrContext* context) {
    const GrGLInterface* glInterface = NULL;
    SkAutoTUnref<const GrGLInterface> glInterfaceUnref;

    glInterface = reinterpret_cast<const GrGLInterface*>(backendContext);
    if (NULL == glInterface) {
        glInterface = GrGLDefaultInterface();
        // By calling GrGLDefaultInterface we've taken a ref on the
        // returned object. We only want to hold that ref until after
        // the GrGpu is constructed and has taken ownership.
        glInterfaceUnref.reset(glInterface);
    }
    if (NULL == glInterface) {
#ifdef SK_DEBUG
        SkDebugf("No GL interface provided!\n");
#endif
        return NULL;
    }
    GrGLContext ctx(glInterface);
    if (ctx.isInitialized()) {
        return SkNEW_ARGS(GrGLGpu, (ctx, context));
    }
    return NULL;
}

static const int kMaxNumBackends = 4;
static CreateGpuProc gGpuFactories[kMaxNumBackends] = {gl_gpu_create, NULL, NULL, NULL};

GrGpuFactoryRegistrar::GrGpuFactoryRegistrar(int i, CreateGpuProc proc) {
    gGpuFactories[i] = proc;
}

GrGpu* GrGpu::Create(GrBackend backend, GrBackendContext backendContext, GrContext* context) {
    SkASSERT((int)backend < kMaxNumBackends);
    if (!gGpuFactories[backend]) {
        return NULL;
    }
    return (gGpuFactories[backend])(backendContext, context);
}