aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2017-06-23 10:58:19 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-06-23 15:42:15 +0000
commit91a3e52552c15751aea09b7a8a896e4edd09d42e (patch)
treed615cde3a2207d435bc6b1ae750688fa671957a7
parenta46969229d6b028f513995303001b659b4dcdc1d (diff)
Move mock gpu and caps, add Gr prefix, and create via GrContext::Create
Change-Id: I02427839f78372e337ed717b071c6baaa8ba4450 Reviewed-on: https://skia-review.googlesource.com/20622 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
-rw-r--r--bench/GrResourceCacheBench.cpp4
-rw-r--r--gn/gpu.gni3
-rw-r--r--include/gpu/GrContext.h8
-rw-r--r--include/gpu/GrTypes.h1
-rw-r--r--src/gpu/GrContext.cpp16
-rw-r--r--src/gpu/GrGpuFactory.cpp29
-rw-r--r--src/gpu/mock/GrMockGpu.h154
-rw-r--r--tests/ResourceCacheTest.cpp2
-rw-r--r--tools/gpu/GrTest.cpp161
9 files changed, 178 insertions, 200 deletions
diff --git a/bench/GrResourceCacheBench.cpp b/bench/GrResourceCacheBench.cpp
index 903c773f33..9c9ca3551a 100644
--- a/bench/GrResourceCacheBench.cpp
+++ b/bench/GrResourceCacheBench.cpp
@@ -69,7 +69,7 @@ protected:
}
void onDraw(int loops, SkCanvas* canvas) override {
- sk_sp<GrContext> context(GrContext::CreateMockContext());
+ sk_sp<GrContext> context(GrContext::Create(kMock_GrBackend, (GrBackendContext) nullptr));
if (nullptr == context) {
return;
}
@@ -115,7 +115,7 @@ protected:
}
void onDelayedSetup() override {
- fContext.reset(GrContext::CreateMockContext());
+ fContext.reset(GrContext::Create(kMock_GrBackend, (GrBackendContext) nullptr));
if (!fContext) {
return;
}
diff --git a/gn/gpu.gni b/gn/gpu.gni
index 67e516a586..e4ffe2f75f 100644
--- a/gn/gpu.gni
+++ b/gn/gpu.gni
@@ -458,6 +458,9 @@ skia_gpu_sources = [
"$_src/gpu/glsl/GrGLSLXferProcessor.cpp",
"$_src/gpu/glsl/GrGLSLXferProcessor.h",
+ # Mock
+ "$_src/gpu/mock/GrMockGpu.h",
+
# Sk files
"$_src/gpu/SkGpuDevice.cpp",
"$_src/gpu/SkGpuDevice.h",
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index d107fc6fd6..64c1746078 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -52,11 +52,6 @@ public:
static GrContext* Create(GrBackend, GrBackendContext, const GrContextOptions& options);
static GrContext* Create(GrBackend, GrBackendContext);
- /**
- * Only defined in test apps.
- */
- static GrContext* CreateMockContext();
-
virtual ~GrContext();
sk_sp<GrContextThreadSafeProxy> threadSafeProxy();
@@ -334,9 +329,6 @@ private:
GrContext(); // init must be called after the constructor.
bool init(GrBackend, GrBackendContext, const GrContextOptions& options);
- void initMockContext();
- void initCommon(const GrContextOptions&);
-
/**
* These functions create premul <-> unpremul effects. If the second argument is 'true', they
* use the specialized round-trip effects from GrConfigConversionEffect, otherwise they
diff --git a/include/gpu/GrTypes.h b/include/gpu/GrTypes.h
index 60cccdfd69..a14a8eade1 100644
--- a/include/gpu/GrTypes.h
+++ b/include/gpu/GrTypes.h
@@ -187,6 +187,7 @@ static inline size_t GrSizeAlignDown(size_t x, uint32_t alignment) {
enum GrBackend {
kOpenGL_GrBackend,
kVulkan_GrBackend,
+ kMock_GrBackend,
kLast_GrBackend = kVulkan_GrBackend
};
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index b0d40f6668..405668d4c4 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -53,14 +53,12 @@ GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext)
GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext,
const GrContextOptions& options) {
- GrContext* context = new GrContext;
+ sk_sp<GrContext> context(new GrContext);
- if (context->init(backend, backendContext, options)) {
- return context;
- } else {
- context->unref();
+ if (!context->init(backend, backendContext, options)) {
return nullptr;
}
+ return context.release();
}
static int32_t gNextID = 1;
@@ -91,12 +89,6 @@ bool GrContext::init(GrBackend backend, GrBackendContext backendContext,
if (!fGpu) {
return false;
}
- this->initCommon(options);
- return true;
-}
-
-void GrContext::initCommon(const GrContextOptions& options) {
- ASSERT_SINGLE_OWNER
fCaps = SkRef(fGpu->caps());
fResourceCache = new GrResourceCache(fCaps, fUniqueID);
@@ -113,6 +105,8 @@ void GrContext::initCommon(const GrContextOptions& options) {
fAtlasGlyphCache = new GrAtlasGlyphCache(this, options.fGlyphCacheTextureMaximumBytes);
fTextBlobCache.reset(new GrTextBlobCache(TextBlobCacheOverBudgetCB, this));
+
+ return true;
}
GrContext::~GrContext() {
diff --git a/src/gpu/GrGpuFactory.cpp b/src/gpu/GrGpuFactory.cpp
index c6134b65a2..1fc19c144a 100644
--- a/src/gpu/GrGpuFactory.cpp
+++ b/src/gpu/GrGpuFactory.cpp
@@ -7,31 +7,26 @@
#include "GrGpuFactory.h"
-
-#include "GrGpu.h"
-#include "gl/GrGLConfig.h"
#include "gl/GrGLGpu.h"
+#include "mock/GrMockGpu.h"
#ifdef SK_VULKAN
#include "vk/GrVkGpu.h"
#endif
-static CreateGpuProc gGpuFactories[kBackendCount] = { GrGLGpu::Create, nullptr };
-
-#ifdef SK_VULKAN
-GrGpuFactoryRegistrar gVkGpuFactoryProc(kVulkan_GrBackend, GrVkGpu::Create);
-#endif
-
-GrGpuFactoryRegistrar::GrGpuFactoryRegistrar(int i, CreateGpuProc proc) {
- gGpuFactories[i] = proc;
-}
-
GrGpu* GrGpu::Create(GrBackend backend,
GrBackendContext backendContext,
const GrContextOptions& options,
GrContext* context) {
- SkASSERT((int)backend < kBackendCount);
- if (!gGpuFactories[backend]) {
- return nullptr;
+ switch (backend) {
+ case kOpenGL_GrBackend:
+ return GrGLGpu::Create(backendContext, options, context);
+#ifdef SK_VULKAN
+ case kVulkan_GrBackend:
+ return GrVkGpu::Create(backendContext, options, context);
+#endif
+ case kMock_GrBackend:
+ return GrMockGpu::Create(backendContext, options, context);
+ default:
+ return nullptr;
}
- return (gGpuFactories[backend])(backendContext, options, context);
}
diff --git a/src/gpu/mock/GrMockGpu.h b/src/gpu/mock/GrMockGpu.h
new file mode 100644
index 0000000000..eb0a74a7f3
--- /dev/null
+++ b/src/gpu/mock/GrMockGpu.h
@@ -0,0 +1,154 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "GrGpu.h"
+#include "GrSemaphore.h"
+
+class GrPipeline;
+
+class GrMockCaps : public GrCaps {
+public:
+ explicit GrMockCaps(const GrContextOptions& options) : INHERITED(options) {
+ fBufferMapThreshold = SK_MaxS32;
+ }
+ bool isConfigTexturable(GrPixelConfig) const override { return false; }
+ bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override { return false; }
+ bool canConfigBeImageStorage(GrPixelConfig) const override { return false; }
+ bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
+ bool* rectsMustMatch, bool* disallowSubrect) const override {
+ return false;
+ }
+
+private:
+ typedef GrCaps INHERITED;
+};
+
+class GrMockGpu : public GrGpu {
+public:
+ static GrGpu* Create(GrBackendContext backendContext, const GrContextOptions& options,
+ GrContext* context) {
+ SkASSERT((void*)backendContext == nullptr);
+ return new GrMockGpu(context, options);
+ }
+
+ ~GrMockGpu() override {}
+
+ bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, size_t rowBytes,
+ GrPixelConfig readConfig, DrawPreference*,
+ ReadPixelTempDrawInfo*) override { return false; }
+
+ bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height,
+ GrPixelConfig srcConfig, DrawPreference*,
+ WritePixelTempDrawInfo*) override { return false; }
+
+ bool onCopySurface(GrSurface* dst,
+ GrSurface* src,
+ const SkIRect& srcRect,
+ const SkIPoint& dstPoint) override { return false; }
+
+ void onQueryMultisampleSpecs(GrRenderTarget* rt, const GrStencilSettings&,
+ int* effectiveSampleCnt, SamplePattern*) override {
+ *effectiveSampleCnt = rt->numStencilSamples();
+ }
+
+ GrGpuCommandBuffer* createCommandBuffer(const GrGpuCommandBuffer::LoadAndStoreInfo&,
+ const GrGpuCommandBuffer::LoadAndStoreInfo&) override {
+ return nullptr;
+ }
+
+ GrFence SK_WARN_UNUSED_RESULT insertFence() override { return 0; }
+ bool waitFence(GrFence, uint64_t) override { return true; }
+ void deleteFence(GrFence) const override {}
+
+ sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned) override {
+ return nullptr;
+ }
+ sk_sp<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore& semaphore,
+ GrWrapOwnership ownership) override { return nullptr; }
+ void insertSemaphore(sk_sp<GrSemaphore> semaphore, bool flush) override {}
+ void waitSemaphore(sk_sp<GrSemaphore> semaphore) override {}
+ sk_sp<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override { return nullptr; }
+
+private:
+ GrMockGpu(GrContext* context, const GrContextOptions& options) : INHERITED(context) {
+ fCaps.reset(new GrMockCaps(options));
+ }
+
+ void onResetContext(uint32_t resetBits) override {}
+
+ void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
+
+ sk_sp<GrTexture> onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
+ const SkTArray<GrMipLevel>& texels) override {
+ return nullptr;
+ }
+
+ sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&,
+ GrSurfaceOrigin,
+ GrBackendTextureFlags,
+ int sampleCnt,
+ GrWrapOwnership) override {
+ return nullptr;
+ }
+
+ sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&,
+ GrSurfaceOrigin) override {
+ return nullptr;
+ }
+
+ sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
+ GrSurfaceOrigin,
+ int sampleCnt) override {
+ return nullptr;
+ }
+
+ GrBuffer* onCreateBuffer(size_t, GrBufferType, GrAccessPattern, const void*) override {
+ return nullptr;
+ }
+
+ gr_instanced::InstancedRendering* onCreateInstancedRendering() override { return nullptr; }
+
+ bool onReadPixels(GrSurface* surface,
+ int left, int top, int width, int height,
+ GrPixelConfig,
+ void* buffer,
+ size_t rowBytes) override {
+ return false;
+ }
+
+ bool onWritePixels(GrSurface* surface,
+ int left, int top, int width, int height,
+ GrPixelConfig config, const SkTArray<GrMipLevel>& texels) override {
+ return false;
+ }
+
+ bool onTransferPixels(GrTexture* texture,
+ int left, int top, int width, int height,
+ GrPixelConfig config, GrBuffer* transferBuffer,
+ size_t offset, size_t rowBytes) override {
+ return false;
+ }
+
+ void onResolveRenderTarget(GrRenderTarget* target) override { return; }
+
+ GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*,
+ int width,
+ int height) override {
+ return nullptr;
+ }
+
+ void clearStencil(GrRenderTarget* target) override {}
+
+ GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h,
+ GrPixelConfig config, bool isRT) override {
+ return 0;
+ }
+ bool isTestingOnlyBackendTexture(GrBackendObject ) const override { return false; }
+ void deleteTestingOnlyBackendTexture(GrBackendObject, bool abandonTexture) override {}
+
+ typedef GrGpu INHERITED;
+};
diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp
index 2429fbdf09..334298a444 100644
--- a/tests/ResourceCacheTest.cpp
+++ b/tests/ResourceCacheTest.cpp
@@ -359,7 +359,7 @@ int TestResource::fNumAlive = 0;
class Mock {
public:
Mock(int maxCnt, size_t maxBytes) {
- fContext.reset(GrContext::CreateMockContext());
+ fContext.reset(GrContext::Create(kMock_GrBackend, (GrBackendContext) nullptr));
SkASSERT(fContext);
fContext->setResourceCacheLimits(maxCnt, maxBytes);
GrResourceCache* cache = fContext->getResourceCache();
diff --git a/tools/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp
index 301ba6709b..6d55fd1379 100644
--- a/tools/gpu/GrTest.cpp
+++ b/tools/gpu/GrTest.cpp
@@ -289,167 +289,6 @@ GrRenderTargetFlags GrRenderTargetProxy::testingOnly_getFlags() const {
return fRenderTargetFlags;
}
-///////////////////////////////////////////////////////////////////////////////
-// Code for the mock context. It's built on a mock GrGpu class that does nothing.
-////
-
-#include "GrGpu.h"
-
-class GrPipeline;
-
-class MockCaps : public GrCaps {
-public:
- explicit MockCaps(const GrContextOptions& options) : INHERITED(options) {}
- bool isConfigTexturable(GrPixelConfig) const override { return false; }
- bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override { return false; }
- bool canConfigBeImageStorage(GrPixelConfig) const override { return false; }
- bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
- bool* rectsMustMatch, bool* disallowSubrect) const override {
- return false;
- }
-
-private:
- typedef GrCaps INHERITED;
-};
-
-class MockGpu : public GrGpu {
-public:
- MockGpu(GrContext* context, const GrContextOptions& options) : INHERITED(context) {
- fCaps.reset(new MockCaps(options));
- }
- ~MockGpu() override {}
-
- bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, size_t rowBytes,
- GrPixelConfig readConfig, DrawPreference*,
- ReadPixelTempDrawInfo*) override { return false; }
-
- bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height,
- GrPixelConfig srcConfig, DrawPreference*,
- WritePixelTempDrawInfo*) override { return false; }
-
- bool onCopySurface(GrSurface* dst,
- GrSurface* src,
- const SkIRect& srcRect,
- const SkIPoint& dstPoint) override { return false; }
-
- void onQueryMultisampleSpecs(GrRenderTarget* rt, const GrStencilSettings&,
- int* effectiveSampleCnt, SamplePattern*) override {
- *effectiveSampleCnt = rt->numStencilSamples();
- }
-
- GrGpuCommandBuffer* createCommandBuffer(const GrGpuCommandBuffer::LoadAndStoreInfo&,
- const GrGpuCommandBuffer::LoadAndStoreInfo&) override {
- return nullptr;
- }
-
- GrFence SK_WARN_UNUSED_RESULT insertFence() override { return 0; }
- bool waitFence(GrFence, uint64_t) override { return true; }
- void deleteFence(GrFence) const override {}
-
- sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned) override { return nullptr; }
- sk_sp<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore& semaphore,
- GrWrapOwnership ownership) override { return nullptr; }
- void insertSemaphore(sk_sp<GrSemaphore> semaphore, bool flush) override {}
- void waitSemaphore(sk_sp<GrSemaphore> semaphore) override {}
- sk_sp<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override { return nullptr; }
-
-private:
- void onResetContext(uint32_t resetBits) override {}
-
- void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
-
- sk_sp<GrTexture> onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
- const SkTArray<GrMipLevel>& texels) override {
- return nullptr;
- }
-
- sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&,
- GrSurfaceOrigin,
- GrBackendTextureFlags,
- int sampleCnt,
- GrWrapOwnership) override {
- return nullptr;
- }
-
- sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&,
- GrSurfaceOrigin) override {
- return nullptr;
- }
-
- sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
- GrSurfaceOrigin,
- int sampleCnt) override {
- return nullptr;
- }
-
- GrBuffer* onCreateBuffer(size_t, GrBufferType, GrAccessPattern, const void*) override {
- return nullptr;
- }
-
- gr_instanced::InstancedRendering* onCreateInstancedRendering() override { return nullptr; }
-
- bool onReadPixels(GrSurface* surface,
- int left, int top, int width, int height,
- GrPixelConfig,
- void* buffer,
- size_t rowBytes) override {
- return false;
- }
-
- bool onWritePixels(GrSurface* surface,
- int left, int top, int width, int height,
- GrPixelConfig config, const SkTArray<GrMipLevel>& texels) override {
- return false;
- }
-
- bool onTransferPixels(GrTexture* texture,
- int left, int top, int width, int height,
- GrPixelConfig config, GrBuffer* transferBuffer,
- size_t offset, size_t rowBytes) override {
- return false;
- }
-
- void onResolveRenderTarget(GrRenderTarget* target) override { return; }
-
- GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*,
- int width,
- int height) override {
- return nullptr;
- }
-
- void clearStencil(GrRenderTarget* target) override {}
-
- GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h,
- GrPixelConfig config, bool isRT) override {
- return 0;
- }
- bool isTestingOnlyBackendTexture(GrBackendObject ) const override { return false; }
- void deleteTestingOnlyBackendTexture(GrBackendObject, bool abandonTexture) override {}
-
- typedef GrGpu INHERITED;
-};
-
-GrContext* GrContext::CreateMockContext() {
- GrContext* context = new GrContext;
-
- context->initMockContext();
- return context;
-}
-
-void GrContext::initMockContext() {
- GrContextOptions options;
- options.fBufferMapThreshold = 0;
- SkASSERT(nullptr == fGpu);
- fGpu = new MockGpu(this, options);
- SkASSERT(fGpu);
- this->initCommon(options);
-
- // We delete these because we want to test the cache starting with zero resources. Also, none of
- // these objects are required for any of tests that use this context. TODO: make stop allocating
- // resources in the buffer pools.
- fDrawingManager->abandon();
-}
-
//////////////////////////////////////////////////////////////////////////////
void GrContextPriv::testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject* cb) {