blob: e1205cd74c305d437a7c7da1d8826491bb875713 [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
reed@google.comac10a2d2010-12-22 21:39:39 +000010#include "GrTypes.h"
11
12// must be before GrGLConfig.h
13#if GR_WIN32_BUILD
14// #include "GrGpuD3D9.h"
15#endif
16
17#include "GrGLConfig.h"
18
reed@google.comac10a2d2010-12-22 21:39:39 +000019#include "GrGpu.h"
junov@google.comf93e7172011-03-31 21:26:24 +000020#include "GrGpuGLFixed.h"
21#include "GrGpuGLShaders.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000022
bsalomon@google.com05ef5102011-05-02 21:14:59 +000023GrGpu* GrGpu::Create(GrEngine engine, GrPlatform3DContext context3D) {
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000024
bsalomon@google.com05ef5102011-05-02 21:14:59 +000025 if (kOpenGL_Shaders_GrEngine == engine ||
26 kOpenGL_Fixed_GrEngine == engine) {
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000027 // If no GL bindings have been installed, fall-back to calling the
28 // GL functions that have been linked with the executable.
29 if (!GrGLGetGLInterface()) {
30 GrGLSetDefaultGLInterface();
31 // If there is no platform-default then just fail.
32 if (!GrGLGetGLInterface()) {
33 return NULL;
34 }
35 }
bsalomon@google.combf2a4692011-05-04 12:35:39 +000036 if (!GrGLGetGLInterface()->validate(engine)) {
37#if GR_DEBUG
38 GrPrintf("Failed GL interface validation!");
39#endif
40 return NULL;
41 }
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000042 }
twiz@google.com59a190b2011-03-14 21:23:01 +000043
reed@google.comac10a2d2010-12-22 21:39:39 +000044 GrGpu* gpu = NULL;
45
46 switch (engine) {
bsalomon@google.com05ef5102011-05-02 21:14:59 +000047 case kOpenGL_Shaders_GrEngine:
bsalomon@google.com1da0e5e2011-05-09 13:28:55 +000048 GrAssert(NULL == (void*)context3D);
junov@google.comf93e7172011-03-31 21:26:24 +000049 {
bsalomon@google.com2ba4abb2011-05-05 12:39:20 +000050#if 0 // old code path, will be removed soon
junov@google.comf93e7172011-03-31 21:26:24 +000051 gpu = new GrGpuGLShaders2;
bsalomon@google.com2ba4abb2011-05-05 12:39:20 +000052#else
53 gpu = new GrGpuGLShaders;
junov@google.comf93e7172011-03-31 21:26:24 +000054#endif
55 }
reed@google.comac10a2d2010-12-22 21:39:39 +000056 break;
bsalomon@google.com05ef5102011-05-02 21:14:59 +000057 case kOpenGL_Fixed_GrEngine:
bsalomon@google.com1da0e5e2011-05-09 13:28:55 +000058 GrAssert(NULL == (void*)context3D);
reed@google.comac10a2d2010-12-22 21:39:39 +000059 gpu = new GrGpuGLFixed;
reed@google.comac10a2d2010-12-22 21:39:39 +000060 break;
bsalomon@google.com05ef5102011-05-02 21:14:59 +000061 case kDirect3D9_GrEngine:
bsalomon@google.com1da0e5e2011-05-09 13:28:55 +000062 GrAssert(NULL != (void*)context3D);
reed@google.comac10a2d2010-12-22 21:39:39 +000063#if GR_WIN32_BUILD
64// gpu = new GrGpuD3D9((IDirect3DDevice9*)context3D);
65#endif
66 break;
67 default:
68 GrAssert(!"unknown engine");
69 break;
70 }
71
72 return gpu;
73}