blob: c954c7a121a60cf3e7192fb74a136946f6116f5c [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 "GrGpuGLShaders.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000021
bsalomon@google.com05ef5102011-05-02 21:14:59 +000022GrGpu* GrGpu::Create(GrEngine engine, GrPlatform3DContext context3D) {
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000023
epoger@google.com17b78942011-08-26 14:40:38 +000024 const GrGLInterface* glInterface = NULL;
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000025 SkAutoTUnref<const GrGLInterface> glInterfaceUnref;
bsalomon@google.com0b77d682011-08-19 13:28:54 +000026
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000027 if (kOpenGL_Shaders_GrEngine == engine) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000028 glInterface = reinterpret_cast<const GrGLInterface*>(context3D);
29 if (NULL == glInterface) {
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000030 glInterface = GrGLDefaultInterface();
31 // By calling GrGLDefaultInterface we've taken a ref on the
32 // returned object. We only want to hold that ref until after
33 // the GrGpu is constructed and has taken ownership.
34 glInterfaceUnref.reset(glInterface);
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000035 }
bsalomon@google.com0b77d682011-08-19 13:28:54 +000036 if (NULL == glInterface) {
37#if GR_DEBUG
bsalomon@google.com6150c202011-10-07 19:55:03 +000038 GrPrintf("No GL interface provided!\n");
bsalomon@google.com0b77d682011-08-19 13:28:54 +000039#endif
40 return NULL;
41 }
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000042 if (!glInterface->validate()) {
bsalomon@google.combf2a4692011-05-04 12:35:39 +000043#if GR_DEBUG
bsalomon@google.com6150c202011-10-07 19:55:03 +000044 GrPrintf("Failed GL interface validation!\n");
bsalomon@google.combf2a4692011-05-04 12:35:39 +000045#endif
46 return NULL;
47 }
bsalomon@google.com1dcf5062011-11-14 19:29:53 +000048
49 return new GrGpuGLShaders(glInterface);
50 } else {
51 return NULL;
bsalomon@google.comf987d1b2011-04-04 17:13:52 +000052 }
reed@google.comac10a2d2010-12-22 21:39:39 +000053}