blob: 071e67cecba43fa2272049ed13b6fdfc63d23e02 [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
epoger@google.com17b78942011-08-26 14:40:38 +000025 const GrGLInterface* glInterface = NULL;
bsalomon@google.com0b77d682011-08-19 13:28:54 +000026
bsalomon@google.com05ef5102011-05-02 21:14:59 +000027 if (kOpenGL_Shaders_GrEngine == engine ||
28 kOpenGL_Fixed_GrEngine == engine) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000029 glInterface = reinterpret_cast<const GrGLInterface*>(context3D);
30 if (NULL == glInterface) {
31 glInterface = GrGLGetDefaultGLInterface();
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000032 }
bsalomon@google.com0b77d682011-08-19 13:28:54 +000033 if (NULL == glInterface) {
34#if GR_DEBUG
35 GrPrintf("No GL interface provided!");
36#endif
37 return NULL;
38 }
39 if (!glInterface->validate(engine)) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +000040#if GR_DEBUG
41 GrPrintf("Failed GL interface validation!");
42#endif
43 return NULL;
44 }
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000045 }
twiz@google.com59a190b2011-03-14 21:23:01 +000046
reed@google.comac10a2d2010-12-22 21:39:39 +000047 GrGpu* gpu = NULL;
48
49 switch (engine) {
bsalomon@google.com05ef5102011-05-02 21:14:59 +000050 case kOpenGL_Shaders_GrEngine:
bsalomon@google.com0b77d682011-08-19 13:28:54 +000051 GrAssert(NULL != glInterface);
52 gpu = new GrGpuGLShaders(glInterface);
reed@google.comac10a2d2010-12-22 21:39:39 +000053 break;
bsalomon@google.com05ef5102011-05-02 21:14:59 +000054 case kOpenGL_Fixed_GrEngine:
bsalomon@google.com0b77d682011-08-19 13:28:54 +000055 GrAssert(NULL != glInterface);
56 gpu = new GrGpuGLFixed(glInterface);
reed@google.comac10a2d2010-12-22 21:39:39 +000057 break;
58 default:
59 GrAssert(!"unknown engine");
60 break;
61 }
62
63 return gpu;
64}