• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     Copyright 2011 Google Inc.
3 
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 
17 #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 
26 #include "GrGpu.h"
27 #include "GrGpuGLFixed.h"
28 #include "GrGpuGLShaders.h"
29 
Create(GrEngine engine,GrPlatform3DContext context3D)30 GrGpu* GrGpu::Create(GrEngine engine, GrPlatform3DContext context3D) {
31 
32     if (kOpenGL_Shaders_GrEngine == engine ||
33         kOpenGL_Fixed_GrEngine == engine) {
34         // 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         }
43         if (!GrGLGetGLInterface()->validate(engine)) {
44 #if GR_DEBUG
45             GrPrintf("Failed GL interface validation!");
46 #endif
47             return NULL;
48         }
49     }
50 
51     GrGpu* gpu = NULL;
52 
53     switch (engine) {
54         case kOpenGL_Shaders_GrEngine:
55             GrAssert(NULL == (void*)context3D);
56             {
57 #if 0 // old code path, will be removed soon
58                 gpu = new GrGpuGLShaders2;
59 #else
60                 gpu = new GrGpuGLShaders;
61 #endif
62             }
63             break;
64         case kOpenGL_Fixed_GrEngine:
65             GrAssert(NULL == (void*)context3D);
66             gpu = new GrGpuGLFixed;
67             break;
68         case kDirect3D9_GrEngine:
69             GrAssert(NULL != (void*)context3D);
70 #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 }
81