epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * 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.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 10 | #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.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 19 | #include "GrGpu.h" |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 20 | #include "GrGpuGLShaders.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 21 | |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 22 | GrGpu* GrGpu::Create(GrEngine engine, GrPlatform3DContext context3D) { |
bsalomon@google.com | f987d1b | 2011-04-04 17:13:52 +0000 | [diff] [blame] | 23 | |
epoger@google.com | 17b7894 | 2011-08-26 14:40:38 +0000 | [diff] [blame] | 24 | const GrGLInterface* glInterface = NULL; |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 25 | SkAutoTUnref<const GrGLInterface> glInterfaceUnref; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 26 | |
bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame^] | 27 | if (kOpenGL_Shaders_GrEngine == engine) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 28 | glInterface = reinterpret_cast<const GrGLInterface*>(context3D); |
| 29 | if (NULL == glInterface) { |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 30 | 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.com | f987d1b | 2011-04-04 17:13:52 +0000 | [diff] [blame] | 35 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 36 | if (NULL == glInterface) { |
| 37 | #if GR_DEBUG |
bsalomon@google.com | 6150c20 | 2011-10-07 19:55:03 +0000 | [diff] [blame] | 38 | GrPrintf("No GL interface provided!\n"); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 39 | #endif |
| 40 | return NULL; |
| 41 | } |
bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame^] | 42 | if (!glInterface->validate()) { |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 43 | #if GR_DEBUG |
bsalomon@google.com | 6150c20 | 2011-10-07 19:55:03 +0000 | [diff] [blame] | 44 | GrPrintf("Failed GL interface validation!\n"); |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 45 | #endif |
| 46 | return NULL; |
| 47 | } |
bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame^] | 48 | |
| 49 | return new GrGpuGLShaders(glInterface); |
| 50 | } else { |
| 51 | return NULL; |
bsalomon@google.com | f987d1b | 2011-04-04 17:13:52 +0000 | [diff] [blame] | 52 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 53 | } |