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 "GrGpuGLFixed.h" |
| 21 | #include "GrGpuGLShaders.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 22 | |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 23 | GrGpu* GrGpu::Create(GrEngine engine, GrPlatform3DContext context3D) { |
bsalomon@google.com | f987d1b | 2011-04-04 17:13:52 +0000 | [diff] [blame] | 24 | |
epoger@google.com | 17b7894 | 2011-08-26 14:40:38 +0000 | [diff] [blame] | 25 | const GrGLInterface* glInterface = NULL; |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 26 | SkAutoTUnref<const GrGLInterface> glInterfaceUnref; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 27 | |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 28 | if (kOpenGL_Shaders_GrEngine == engine || |
| 29 | kOpenGL_Fixed_GrEngine == engine) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 30 | glInterface = reinterpret_cast<const GrGLInterface*>(context3D); |
| 31 | if (NULL == glInterface) { |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 32 | 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.com | f987d1b | 2011-04-04 17:13:52 +0000 | [diff] [blame] | 37 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 38 | if (NULL == glInterface) { |
| 39 | #if GR_DEBUG |
bsalomon@google.com | 6150c20 | 2011-10-07 19:55:03 +0000 | [diff] [blame] | 40 | GrPrintf("No GL interface provided!\n"); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 41 | #endif |
| 42 | return NULL; |
| 43 | } |
| 44 | if (!glInterface->validate(engine)) { |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 45 | #if GR_DEBUG |
bsalomon@google.com | 6150c20 | 2011-10-07 19:55:03 +0000 | [diff] [blame] | 46 | GrPrintf("Failed GL interface validation!\n"); |
bsalomon@google.com | bf2a469 | 2011-05-04 12:35:39 +0000 | [diff] [blame] | 47 | #endif |
| 48 | return NULL; |
| 49 | } |
bsalomon@google.com | f987d1b | 2011-04-04 17:13:52 +0000 | [diff] [blame] | 50 | } |
twiz@google.com | 59a190b | 2011-03-14 21:23:01 +0000 | [diff] [blame] | 51 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 52 | GrGpu* gpu = NULL; |
| 53 | |
| 54 | switch (engine) { |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 55 | case kOpenGL_Shaders_GrEngine: |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 56 | GrAssert(NULL != glInterface); |
| 57 | gpu = new GrGpuGLShaders(glInterface); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 58 | break; |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 59 | case kOpenGL_Fixed_GrEngine: |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 60 | GrAssert(NULL != glInterface); |
| 61 | gpu = new GrGpuGLFixed(glInterface); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 62 | break; |
| 63 | default: |
| 64 | GrAssert(!"unknown engine"); |
| 65 | break; |
| 66 | } |
| 67 | |
| 68 | return gpu; |
| 69 | } |