commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2013 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. |
| 7 | */ |
| 8 | |
| 9 | #include "GrTest.h" |
| 10 | |
joshualitt | 50408ad | 2014-11-03 12:31:14 -0800 | [diff] [blame] | 11 | #include "GrInOrderDrawBuffer.h" |
bsalomon | ac49acd | 2014-11-14 06:47:39 -0800 | [diff] [blame] | 12 | #include "GrResourceCache.h" |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 13 | |
| 14 | void GrTestTarget::init(GrContext* ctx, GrDrawTarget* target) { |
| 15 | SkASSERT(!fContext); |
| 16 | |
| 17 | fContext.reset(SkRef(ctx)); |
| 18 | fDrawTarget.reset(SkRef(target)); |
| 19 | |
| 20 | SkNEW_IN_TLAZY(&fASR, GrDrawTarget::AutoStateRestore, (target, GrDrawTarget::kReset_ASRInit)); |
| 21 | SkNEW_IN_TLAZY(&fACR, GrDrawTarget::AutoClipRestore, (target)); |
| 22 | SkNEW_IN_TLAZY(&fAGP, GrDrawTarget::AutoGeometryPush, (target)); |
| 23 | } |
| 24 | |
| 25 | void GrContext::getTestTarget(GrTestTarget* tar) { |
| 26 | this->flush(); |
| 27 | // We could create a proxy GrDrawTarget that passes through to fGpu until ~GrTextTarget() and |
| 28 | // then disconnects. This would help prevent test writers from mixing using the returned |
| 29 | // GrDrawTarget and regular drawing. We could also assert or fail in GrContext drawing methods |
| 30 | // until ~GrTestTarget(). |
joshualitt | 50408ad | 2014-11-03 12:31:14 -0800 | [diff] [blame] | 31 | tar->init(this, fDrawBuffer); |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | /////////////////////////////////////////////////////////////////////////////// |
| 35 | |
| 36 | void GrContext::setMaxTextureSizeOverride(int maxTextureSizeOverride) { |
| 37 | fMaxTextureSizeOverride = maxTextureSizeOverride; |
| 38 | } |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 39 | |
| 40 | void GrContext::purgeAllUnlockedResources() { |
bsalomon | ac49acd | 2014-11-14 06:47:39 -0800 | [diff] [blame] | 41 | fResourceCache->purgeAllUnlocked(); |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 42 | } |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 43 | |
| 44 | /////////////////////////////////////////////////////////////////////////////// |
| 45 | // Code for the mock context. It's built on a mock GrGpu class that does nothing. |
| 46 | //// |
| 47 | |
| 48 | #include "GrBufferAllocPool.h" |
| 49 | #include "GrInOrderDrawBuffer.h" |
| 50 | #include "GrGpu.h" |
| 51 | |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame] | 52 | class GrOptDrawState; |
| 53 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 54 | class MockGpu : public GrGpu { |
| 55 | public: |
| 56 | MockGpu(GrContext* context) : INHERITED(context) { fCaps.reset(SkNEW(GrDrawTargetCaps)); } |
| 57 | virtual ~MockGpu() { } |
| 58 | virtual bool canWriteTexturePixels(const GrTexture*, |
| 59 | GrPixelConfig srcConfig) const SK_OVERRIDE { |
| 60 | return true; |
| 61 | } |
| 62 | |
| 63 | virtual bool readPixelsWillPayForYFlip(GrRenderTarget* renderTarget, |
| 64 | int left, int top, |
| 65 | int width, int height, |
| 66 | GrPixelConfig config, |
| 67 | size_t rowBytes) const SK_OVERRIDE { return false; } |
| 68 | virtual void buildProgramDesc(const GrOptDrawState&, |
| 69 | const GrProgramDesc::DescInfo&, |
| 70 | GrGpu::DrawType, |
| 71 | const GrDeviceCoordTexture* dstCopy, |
| 72 | GrProgramDesc* desc) SK_OVERRIDE { } |
| 73 | |
| 74 | virtual void discard(GrRenderTarget*) SK_OVERRIDE { } |
| 75 | |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 76 | virtual bool canCopySurface(GrSurface* dst, |
| 77 | GrSurface* src, |
| 78 | const SkIRect& srcRect, |
| 79 | const SkIPoint& dstPoint) SK_OVERRIDE { return false; }; |
| 80 | |
| 81 | virtual bool copySurface(GrSurface* dst, |
| 82 | GrSurface* src, |
| 83 | const SkIRect& srcRect, |
| 84 | const SkIPoint& dstPoint) SK_OVERRIDE { return false; }; |
| 85 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 86 | private: |
| 87 | virtual void onResetContext(uint32_t resetBits) { }; |
| 88 | virtual GrTexture* onCreateTexture(const GrSurfaceDesc& desc, |
| 89 | const void* srcData, |
| 90 | size_t rowBytes) SK_OVERRIDE { |
| 91 | return NULL; |
| 92 | } |
| 93 | |
| 94 | virtual GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, |
| 95 | const void* srcData) SK_OVERRIDE { |
| 96 | return NULL; |
| 97 | } |
| 98 | |
| 99 | virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&) SK_OVERRIDE { |
| 100 | return NULL; |
| 101 | } |
| 102 | |
| 103 | virtual GrRenderTarget* onWrapBackendRenderTarget( |
| 104 | const GrBackendRenderTargetDesc&) SK_OVERRIDE { |
| 105 | return NULL; |
| 106 | } |
| 107 | |
| 108 | virtual GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) SK_OVERRIDE { |
| 109 | return NULL; |
| 110 | } |
| 111 | |
| 112 | virtual GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) SK_OVERRIDE { |
| 113 | return NULL; |
| 114 | } |
| 115 | |
joshualitt | 4b68ec0 | 2014-11-07 14:11:45 -0800 | [diff] [blame] | 116 | virtual void onClear(GrRenderTarget*, const SkIRect* rect, GrColor color, |
| 117 | bool canIgnoreRect) SK_OVERRIDE { } |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 118 | |
| 119 | virtual void onClearStencilClip(GrRenderTarget*, |
| 120 | const SkIRect& rect, |
| 121 | bool insideClip) SK_OVERRIDE { } |
| 122 | |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame] | 123 | virtual void onDraw(const GrOptDrawState&, const GrDrawTarget::DrawInfo&) SK_OVERRIDE { } |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 124 | virtual bool onReadPixels(GrRenderTarget* target, |
| 125 | int left, int top, int width, int height, |
| 126 | GrPixelConfig, |
| 127 | void* buffer, |
| 128 | size_t rowBytes) SK_OVERRIDE { |
| 129 | return false; |
| 130 | } |
| 131 | |
| 132 | virtual bool onWriteTexturePixels(GrTexture* texture, |
| 133 | int left, int top, int width, int height, |
| 134 | GrPixelConfig config, const void* buffer, |
| 135 | size_t rowBytes) SK_OVERRIDE { |
| 136 | return false; |
| 137 | } |
| 138 | |
| 139 | virtual void onResolveRenderTarget(GrRenderTarget* target) SK_OVERRIDE { |
| 140 | return; |
| 141 | } |
| 142 | |
| 143 | virtual bool createStencilBufferForRenderTarget(GrRenderTarget*, int width, |
| 144 | int height) SK_OVERRIDE { |
| 145 | return false; |
| 146 | } |
| 147 | |
| 148 | virtual bool attachStencilBufferToRenderTarget(GrStencilBuffer*, GrRenderTarget*) SK_OVERRIDE { |
| 149 | return false; |
| 150 | } |
| 151 | |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame] | 152 | virtual bool flushGraphicsState(const GrOptDrawState&, |
| 153 | DrawType, |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 154 | const GrClipMaskManager::ScissorState&, |
| 155 | const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE { |
| 156 | return false; |
| 157 | } |
| 158 | |
| 159 | virtual void clearStencil(GrRenderTarget* target) SK_OVERRIDE { } |
| 160 | |
| 161 | virtual void didAddGpuTraceMarker() SK_OVERRIDE { } |
| 162 | virtual void didRemoveGpuTraceMarker() SK_OVERRIDE { } |
| 163 | |
| 164 | typedef GrGpu INHERITED; |
| 165 | }; |
| 166 | |
| 167 | GrContext* GrContext::CreateMockContext() { |
| 168 | GrContext* context = SkNEW_ARGS(GrContext, (Options())); |
| 169 | |
| 170 | context->initMockContext(); |
| 171 | return context; |
| 172 | } |
| 173 | |
| 174 | void GrContext::initMockContext() { |
| 175 | SkASSERT(NULL == fGpu); |
| 176 | fGpu = SkNEW_ARGS(MockGpu, (this)); |
| 177 | SkASSERT(fGpu); |
| 178 | this->initCommon(); |
| 179 | |
| 180 | // We delete these because we want to test the cache starting with zero resources. Also, none of |
| 181 | // these objects are required for any of tests that use this context. TODO: make stop allocating |
| 182 | // resources in the buffer pools. |
| 183 | SkDELETE(fDrawBuffer); |
| 184 | SkDELETE(fDrawBufferVBAllocPool); |
| 185 | SkDELETE(fDrawBufferIBAllocPool); |
| 186 | |
| 187 | fDrawBuffer = NULL; |
| 188 | fDrawBufferVBAllocPool = NULL; |
| 189 | fDrawBufferIBAllocPool = NULL; |
| 190 | } |