blob: 9e10231dda835001b2ff11da8f7114e231fa0403 [file] [log] [blame]
scroggo478652e2015-03-25 07:11:02 -07001/*
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.org787227d2014-03-26 21:26:15 +00008#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
23namespace DM {
24
25static const bool kGPUDisabled = false;
26
27static inline SkSurface* NewGpuSurface(GrContextFactory* grFactory,
28 GrContextFactory::GLContextType type,
kkinnunen80549fc2014-06-30 06:36:31 -070029 GrGLStandard gpuAPI,
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000030 SkImageInfo info,
jvanverth4736e142014-11-07 07:12:46 -080031 int samples,
bsalomonafcd7cd2015-08-31 12:39:41 -070032 bool useDIText) {
33 uint32_t flags = useDIText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : 0;
jvanverth4736e142014-11-07 07:12:46 -080034 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
bsalomonafe30052015-01-16 07:32:33 -080035 return SkSurface::NewRenderTarget(grFactory->get(type, gpuAPI), SkSurface::kNo_Budgeted,
36 info, samples, &props);
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000037}
38
39} // namespace DM
40
41#else// !SK_SUPPORT_GPU
42
43// Ganesh is not available. Fake it.
44
kkinnunen80549fc2014-06-30 06:36:31 -070045enum GrGLStandard {
46 kNone_GrGLStandard,
47 kGL_GrGLStandard,
48 kGLES_GrGLStandard
49};
mtklein2ecf86e2014-11-06 08:06:39 -080050static const int kGrGLStandardCnt = 3;
kkinnunen80549fc2014-06-30 06:36:31 -070051
mtkleinb9eb4ac2015-02-02 18:26:03 -080052class GrContext {
53public:
54 void dumpCacheStats(SkString*) const {}
55 void dumpGpuStats(SkString*) const {}
56};
57
bsalomon4ee6bd82015-05-27 13:23:23 -070058struct GrContextOptions {};
59
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000060class GrContextFactory {
61public:
bsalomon4ee6bd82015-05-27 13:23:23 -070062 GrContextFactory() {};
63 explicit GrContextFactory(const GrContextOptions&) {}
64
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000065 typedef int GLContextType;
66
hendrikw885bf092015-08-27 10:38:39 -070067 static const GLContextType kANGLE_GLContextType = 0,
hendrikweddbefb2015-09-11 13:07:29 -070068 kANGLE_GL_GLContextType = 0,
hendrikw885bf092015-08-27 10:38:39 -070069 kCommandBuffer_GLContextType = 0,
70 kDebug_GLContextType = 0,
71 kMESA_GLContextType = 0,
72 kNVPR_GLContextType = 0,
73 kNative_GLContextType = 0,
74 kNull_GLContextType = 0;
mtklein2ecf86e2014-11-06 08:06:39 -080075 static const int kGLContextTypeCnt = 1;
mtklein1e319f72014-07-15 08:27:06 -070076 void destroyContexts() {}
bsalomon2354f842014-07-28 13:48:36 -070077
78 void abandonContexts() {}
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000079};
80
81namespace DM {
82
83static const bool kGPUDisabled = true;
84
85static inline SkSurface* NewGpuSurface(GrContextFactory*,
86 GrContextFactory::GLContextType,
kkinnunen80549fc2014-06-30 06:36:31 -070087 GrGLStandard,
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000088 SkImageInfo,
jvanverth4736e142014-11-07 07:12:46 -080089 int,
90 bool) {
halcanary96fcdcc2015-08-27 07:41:13 -070091 return nullptr;
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000092}
93
94} // namespace DM
95
96#endif//SK_SUPPORT_GPU
97
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000098#endif//DMGpuSupport_DEFINED