blob: 9498da21c389a6f658f9626bd0cc51a001a873dc [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.com6fb736f2011-09-16 18:51:57 +000026 SkAutoTUnref<const GrGLInterface> glInterfaceUnref;
bsalomon@google.com0b77d682011-08-19 13:28:54 +000027
bsalomon@google.com05ef5102011-05-02 21:14:59 +000028 if (kOpenGL_Shaders_GrEngine == engine ||
29 kOpenGL_Fixed_GrEngine == engine) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000030 glInterface = reinterpret_cast<const GrGLInterface*>(context3D);
31 if (NULL == glInterface) {
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000032 glInterface = GrGLDefaultInterface();
33 // By calling GrGLDefaultInterface we've taken a ref on the
34 // returned object. We only want to hold that ref until after
35 // the GrGpu is constructed and has taken ownership.
36 glInterfaceUnref.reset(glInterface);
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000037 }
bsalomon@google.com0b77d682011-08-19 13:28:54 +000038 if (NULL == glInterface) {
39#if GR_DEBUG
bsalomon@google.com6150c202011-10-07 19:55:03 +000040 GrPrintf("No GL interface provided!\n");
bsalomon@google.com0b77d682011-08-19 13:28:54 +000041#endif
42 return NULL;
43 }
44 if (!glInterface->validate(engine)) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +000045#if GR_DEBUG
bsalomon@google.com6150c202011-10-07 19:55:03 +000046 GrPrintf("Failed GL interface validation!\n");
bsalomon@google.combf2a4692011-05-04 12:35:39 +000047#endif
48 return NULL;
49 }
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000050 }
twiz@google.com59a190b2011-03-14 21:23:01 +000051
reed@google.comac10a2d2010-12-22 21:39:39 +000052 GrGpu* gpu = NULL;
53
54 switch (engine) {
bsalomon@google.com05ef5102011-05-02 21:14:59 +000055 case kOpenGL_Shaders_GrEngine:
bsalomon@google.com0b77d682011-08-19 13:28:54 +000056 GrAssert(NULL != glInterface);
57 gpu = new GrGpuGLShaders(glInterface);
reed@google.comac10a2d2010-12-22 21:39:39 +000058 break;
bsalomon@google.com05ef5102011-05-02 21:14:59 +000059 case kOpenGL_Fixed_GrEngine:
bsalomon@google.com0b77d682011-08-19 13:28:54 +000060 GrAssert(NULL != glInterface);
61 gpu = new GrGpuGLFixed(glInterface);
reed@google.comac10a2d2010-12-22 21:39:39 +000062 break;
63 default:
64 GrAssert(!"unknown engine");
65 break;
66 }
67
68 return gpu;
69}