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