blob: 1ea51d2621ef837765e89b86afb8676f98aa55a1 [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
bsalomon6dea83f2015-12-03 12:58:06 -080016// This should be safe to include even in no-gpu builds. Include by relative path so it
17// can be found in non-gpu builds.
18#include "../include/gpu/GrContextOptions.h"
19
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000020#if SK_SUPPORT_GPU
21
22// Ganesh is available. Yippee!
23
24# include "GrContext.h"
25# include "GrContextFactory.h"
26
27namespace DM {
28
29static const bool kGPUDisabled = false;
30
bsalomon3724e572016-03-30 18:56:19 -070031static inline sk_sp<SkSurface> NewGpuSurface(
32 sk_gpu_test::GrContextFactory* grFactory,
bsalomon85b4b532016-04-05 11:06:27 -070033 sk_gpu_test::GrContextFactory::ContextType type,
34 sk_gpu_test::GrContextFactory::ContextOptions options,
bsalomon3724e572016-03-30 18:56:19 -070035 SkImageInfo info,
36 int samples,
37 bool useDIText) {
bsalomonafcd7cd2015-08-31 12:39:41 -070038 uint32_t flags = useDIText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : 0;
jvanverth4736e142014-11-07 07:12:46 -080039 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
reede8f30622016-03-23 18:59:25 -070040 return SkSurface::MakeRenderTarget(grFactory->get(type, options), SkBudgeted::kNo,
41 info, samples, &props);
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000042}
43
44} // namespace DM
45
46#else// !SK_SUPPORT_GPU
47
48// Ganesh is not available. Fake it.
49
kkinnunen80549fc2014-06-30 06:36:31 -070050enum GrGLStandard {
51 kNone_GrGLStandard,
52 kGL_GrGLStandard,
53 kGLES_GrGLStandard
54};
mtklein2ecf86e2014-11-06 08:06:39 -080055static const int kGrGLStandardCnt = 3;
kkinnunen80549fc2014-06-30 06:36:31 -070056
mtkleinb9eb4ac2015-02-02 18:26:03 -080057class GrContext {
58public:
59 void dumpCacheStats(SkString*) const {}
60 void dumpGpuStats(SkString*) const {}
61};
62
bsalomon3724e572016-03-30 18:56:19 -070063namespace sk_gpu_test {
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000064class GrContextFactory {
65public:
bsalomon4ee6bd82015-05-27 13:23:23 -070066 GrContextFactory() {};
67 explicit GrContextFactory(const GrContextOptions&) {}
68
bsalomon85b4b532016-04-05 11:06:27 -070069 typedef int ContextType;
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000070
bsalomon85b4b532016-04-05 11:06:27 -070071 static const ContextType kANGLE_ContextType = 0,
72 kANGLE_GL_ContextType = 0,
73 kCommandBuffer_ContextType = 0,
74 kDebugGL_ContextType = 0,
75 kMESA_ContextType = 0,
76 kNVPR_ContextType = 0,
77 kNativeGL_ContextType = 0,
78 kGL_ContextType = 0,
79 kGLES_ContextType = 0,
bsalomondc0fcd42016-04-11 14:21:33 -070080 kNullGL_ContextType = 0,
81 kVulkan_ContextType = 0;
bsalomon85b4b532016-04-05 11:06:27 -070082 static const int kContextTypeCnt = 1;
83 enum ContextOptions {
84 kNone_ContextOptions = 0,
85 kEnableNVPR_ContextOptions = 0x1,
kkinnunen5219fd92015-12-10 06:28:13 -080086 };
mtklein1e319f72014-07-15 08:27:06 -070087 void destroyContexts() {}
bsalomon2354f842014-07-28 13:48:36 -070088
89 void abandonContexts() {}
bsalomon6e2aad42016-04-01 11:54:31 -070090
91 void releaseResourcesAndAbandonContexts() {}
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000092};
bsalomon3724e572016-03-30 18:56:19 -070093} // namespace sk_gpu_test
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000094
95namespace DM {
96
97static const bool kGPUDisabled = true;
98
bsalomon3724e572016-03-30 18:56:19 -070099static inline SkSurface* NewGpuSurface(sk_gpu_test::GrContextFactory*,
bsalomon85b4b532016-04-05 11:06:27 -0700100 sk_gpu_test::GrContextFactory::ContextType,
101 sk_gpu_test::GrContextFactory::ContextOptions,
commit-bot@chromium.org787227d2014-03-26 21:26:15 +0000102 SkImageInfo,
jvanverth4736e142014-11-07 07:12:46 -0800103 int,
104 bool) {
halcanary96fcdcc2015-08-27 07:41:13 -0700105 return nullptr;
commit-bot@chromium.org787227d2014-03-26 21:26:15 +0000106}
107
108} // namespace DM
109
110#endif//SK_SUPPORT_GPU
111
commit-bot@chromium.org787227d2014-03-26 21:26:15 +0000112#endif//DMGpuSupport_DEFINED