blob: 38c07b7a5368e26f2d242a387732967efc6a9e98 [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
twiz@google.com59a190b2011-03-14 21:23:01 +00002 Copyright 2011 Google Inc.
reed@google.comac10a2d2010-12-22 21:39:39 +00003
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
reed@google.comac10a2d2010-12-22 21:39:39 +000017#include "GrTypes.h"
18
19// must be before GrGLConfig.h
20#if GR_WIN32_BUILD
21// #include "GrGpuD3D9.h"
22#endif
23
24#include "GrGLConfig.h"
25
reed@google.comac10a2d2010-12-22 21:39:39 +000026#include "GrGpu.h"
junov@google.comf93e7172011-03-31 21:26:24 +000027#include "GrGpuGLFixed.h"
28#include "GrGpuGLShaders.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000029
bsalomon@google.com05ef5102011-05-02 21:14:59 +000030GrGpu* GrGpu::Create(GrEngine engine, GrPlatform3DContext context3D) {
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000031
bsalomon@google.com05ef5102011-05-02 21:14:59 +000032 if (kOpenGL_Shaders_GrEngine == engine ||
33 kOpenGL_Fixed_GrEngine == engine) {
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000034 // If no GL bindings have been installed, fall-back to calling the
35 // GL functions that have been linked with the executable.
36 if (!GrGLGetGLInterface()) {
37 GrGLSetDefaultGLInterface();
38 // If there is no platform-default then just fail.
39 if (!GrGLGetGLInterface()) {
40 return NULL;
41 }
42 }
bsalomon@google.combf2a4692011-05-04 12:35:39 +000043 if (!GrGLGetGLInterface()->validate(engine)) {
44#if GR_DEBUG
45 GrPrintf("Failed GL interface validation!");
46#endif
47 return NULL;
48 }
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000049 }
twiz@google.com59a190b2011-03-14 21:23:01 +000050
reed@google.comac10a2d2010-12-22 21:39:39 +000051 GrGpu* gpu = NULL;
52
53 switch (engine) {
bsalomon@google.com05ef5102011-05-02 21:14:59 +000054 case kOpenGL_Shaders_GrEngine:
bsalomon@google.com1da0e5e2011-05-09 13:28:55 +000055 GrAssert(NULL == (void*)context3D);
junov@google.comf93e7172011-03-31 21:26:24 +000056 {
bsalomon@google.com2ba4abb2011-05-05 12:39:20 +000057#if 0 // old code path, will be removed soon
junov@google.comf93e7172011-03-31 21:26:24 +000058 gpu = new GrGpuGLShaders2;
bsalomon@google.com2ba4abb2011-05-05 12:39:20 +000059#else
60 gpu = new GrGpuGLShaders;
junov@google.comf93e7172011-03-31 21:26:24 +000061#endif
62 }
reed@google.comac10a2d2010-12-22 21:39:39 +000063 break;
bsalomon@google.com05ef5102011-05-02 21:14:59 +000064 case kOpenGL_Fixed_GrEngine:
bsalomon@google.com1da0e5e2011-05-09 13:28:55 +000065 GrAssert(NULL == (void*)context3D);
reed@google.comac10a2d2010-12-22 21:39:39 +000066 gpu = new GrGpuGLFixed;
reed@google.comac10a2d2010-12-22 21:39:39 +000067 break;
bsalomon@google.com05ef5102011-05-02 21:14:59 +000068 case kDirect3D9_GrEngine:
bsalomon@google.com1da0e5e2011-05-09 13:28:55 +000069 GrAssert(NULL != (void*)context3D);
reed@google.comac10a2d2010-12-22 21:39:39 +000070#if GR_WIN32_BUILD
71// gpu = new GrGpuD3D9((IDirect3DDevice9*)context3D);
72#endif
73 break;
74 default:
75 GrAssert(!"unknown engine");
76 break;
77 }
78
79 return gpu;
80}