scroggo | 478652e | 2015-03-25 07:11:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 8 | #ifndef DMGpuSupport_DEFINED |
| 9 | #define DMGpuSupport_DEFINED |
| 10 | |
| 11 | // Provides Ganesh to DM, |
| 12 | // or if it's not available, fakes it enough so most code doesn't have to know that. |
| 13 | |
| 14 | #include "SkSurface.h" |
| 15 | |
| 16 | #if SK_SUPPORT_GPU |
| 17 | |
| 18 | // Ganesh is available. Yippee! |
| 19 | |
| 20 | # include "GrContext.h" |
| 21 | # include "GrContextFactory.h" |
| 22 | |
| 23 | namespace DM { |
| 24 | |
| 25 | static const bool kGPUDisabled = false; |
| 26 | |
| 27 | static inline SkSurface* NewGpuSurface(GrContextFactory* grFactory, |
| 28 | GrContextFactory::GLContextType type, |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 29 | GrGLStandard gpuAPI, |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 30 | SkImageInfo info, |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 31 | int samples, |
| 32 | bool useDFText) { |
| 33 | uint32_t flags = useDFText ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0; |
| 34 | SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 35 | return SkSurface::NewRenderTarget(grFactory->get(type, gpuAPI), SkSurface::kNo_Budgeted, |
| 36 | info, samples, &props); |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | } // namespace DM |
| 40 | |
| 41 | #else// !SK_SUPPORT_GPU |
| 42 | |
| 43 | // Ganesh is not available. Fake it. |
| 44 | |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 45 | enum GrGLStandard { |
| 46 | kNone_GrGLStandard, |
| 47 | kGL_GrGLStandard, |
| 48 | kGLES_GrGLStandard |
| 49 | }; |
mtklein | 2ecf86e | 2014-11-06 08:06:39 -0800 | [diff] [blame] | 50 | static const int kGrGLStandardCnt = 3; |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 51 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 52 | class GrContext { |
| 53 | public: |
| 54 | void dumpCacheStats(SkString*) const {} |
| 55 | void dumpGpuStats(SkString*) const {} |
| 56 | }; |
| 57 | |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 58 | class GrContextFactory { |
| 59 | public: |
| 60 | typedef int GLContextType; |
| 61 | |
| 62 | static const GLContextType kANGLE_GLContextType = 0, |
| 63 | kDebug_GLContextType = 0, |
| 64 | kMESA_GLContextType = 0, |
| 65 | kNVPR_GLContextType = 0, |
| 66 | kNative_GLContextType = 0, |
| 67 | kNull_GLContextType = 0; |
mtklein | 2ecf86e | 2014-11-06 08:06:39 -0800 | [diff] [blame] | 68 | static const int kGLContextTypeCnt = 1; |
mtklein | 1e319f7 | 2014-07-15 08:27:06 -0700 | [diff] [blame] | 69 | void destroyContexts() {} |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 70 | |
| 71 | void abandonContexts() {} |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | namespace DM { |
| 75 | |
| 76 | static const bool kGPUDisabled = true; |
| 77 | |
| 78 | static inline SkSurface* NewGpuSurface(GrContextFactory*, |
| 79 | GrContextFactory::GLContextType, |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 80 | GrGLStandard, |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 81 | SkImageInfo, |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 82 | int, |
| 83 | bool) { |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 84 | return NULL; |
| 85 | } |
| 86 | |
| 87 | } // namespace DM |
| 88 | |
| 89 | #endif//SK_SUPPORT_GPU |
| 90 | |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 91 | #endif//DMGpuSupport_DEFINED |