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 | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 56 | ~MockGpu() SK_OVERRIDE {} |
| 57 | bool canWriteTexturePixels(const GrTexture*, GrPixelConfig srcConfig) const SK_OVERRIDE { |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 58 | return true; |
| 59 | } |
| 60 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 61 | bool readPixelsWillPayForYFlip(GrRenderTarget* renderTarget, |
| 62 | int left, int top, |
| 63 | int width, int height, |
| 64 | GrPixelConfig config, |
| 65 | size_t rowBytes) const SK_OVERRIDE { return false; } |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame^] | 66 | void buildProgramDesc(GrProgramDesc*,const GrPrimitiveProcessor&, |
| 67 | const GrOptDrawState&, |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 68 | const GrProgramDesc::DescInfo&, |
| 69 | GrGpu::DrawType, |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame^] | 70 | const GrBatchTracker&) const SK_OVERRIDE {} |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 71 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 72 | void discard(GrRenderTarget*) SK_OVERRIDE {} |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 73 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 74 | 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 | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 79 | bool copySurface(GrSurface* dst, |
| 80 | GrSurface* src, |
| 81 | const SkIRect& srcRect, |
| 82 | const SkIPoint& dstPoint) SK_OVERRIDE { return false; }; |
| 83 | |
| 84 | bool initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) SK_OVERRIDE { |
| 85 | return false; |
| 86 | } |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 87 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 88 | private: |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 89 | void onResetContext(uint32_t resetBits) SK_OVERRIDE {} |
| 90 | |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 91 | GrTexture* onCreateTexture(const GrSurfaceDesc& desc, bool budgeted, const void* srcData, |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 92 | size_t rowBytes) SK_OVERRIDE { |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 93 | return NULL; |
| 94 | } |
| 95 | |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 96 | GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, bool budgeted, |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 97 | const void* srcData) SK_OVERRIDE { |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 98 | return NULL; |
| 99 | } |
| 100 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 101 | GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&) SK_OVERRIDE { return NULL; } |
| 102 | |
| 103 | GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) SK_OVERRIDE { |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 104 | return NULL; |
| 105 | } |
| 106 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 107 | GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) SK_OVERRIDE { return NULL; } |
| 108 | |
| 109 | GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) SK_OVERRIDE { return NULL; } |
| 110 | |
| 111 | void onClear(GrRenderTarget*, const SkIRect* rect, GrColor color, |
| 112 | bool canIgnoreRect) SK_OVERRIDE {} |
| 113 | |
| 114 | void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool insideClip) SK_OVERRIDE {} |
| 115 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame^] | 116 | void onDraw(const DrawArgs&, const GrDrawTarget::DrawInfo&) SK_OVERRIDE {} |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 117 | |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 118 | void onStencilPath(const GrPath* path, const StencilPathState& state) SK_OVERRIDE {} |
bsalomon | d95263c | 2014-12-16 13:05:12 -0800 | [diff] [blame] | 119 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame^] | 120 | void onDrawPath(const DrawArgs&, const GrPath*, const GrStencilSettings&) SK_OVERRIDE {} |
bsalomon | d95263c | 2014-12-16 13:05:12 -0800 | [diff] [blame] | 121 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame^] | 122 | void onDrawPaths(const DrawArgs&, |
bsalomon | d95263c | 2014-12-16 13:05:12 -0800 | [diff] [blame] | 123 | const GrPathRange*, |
| 124 | const void* indices, |
| 125 | GrDrawTarget::PathIndexType, |
| 126 | const float transformValues[], |
| 127 | GrDrawTarget::PathTransformType, |
| 128 | int count, |
| 129 | const GrStencilSettings&) SK_OVERRIDE {} |
| 130 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 131 | bool onReadPixels(GrRenderTarget* target, |
| 132 | int left, int top, int width, int height, |
| 133 | GrPixelConfig, |
| 134 | void* buffer, |
| 135 | size_t rowBytes) SK_OVERRIDE { |
| 136 | return false; |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 137 | } |
| 138 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 139 | bool onWriteTexturePixels(GrTexture* texture, |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 140 | int left, int top, int width, int height, |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 141 | GrPixelConfig config, const void* buffer, |
| 142 | size_t rowBytes) SK_OVERRIDE { |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 143 | return false; |
| 144 | } |
| 145 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 146 | void onResolveRenderTarget(GrRenderTarget* target) SK_OVERRIDE { return; } |
| 147 | |
| 148 | bool createStencilBufferForRenderTarget(GrRenderTarget*, int width, int height) SK_OVERRIDE { |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 149 | return false; |
| 150 | } |
| 151 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 152 | bool attachStencilBufferToRenderTarget(GrStencilBuffer*, GrRenderTarget*) SK_OVERRIDE { |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 153 | return false; |
| 154 | } |
| 155 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 156 | void clearStencil(GrRenderTarget* target) SK_OVERRIDE {} |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 157 | |
bsalomon | d95263c | 2014-12-16 13:05:12 -0800 | [diff] [blame] | 158 | void didAddGpuTraceMarker() SK_OVERRIDE {} |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 159 | |
bsalomon | d95263c | 2014-12-16 13:05:12 -0800 | [diff] [blame] | 160 | void didRemoveGpuTraceMarker() SK_OVERRIDE {} |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 161 | |
| 162 | typedef GrGpu INHERITED; |
| 163 | }; |
| 164 | |
| 165 | GrContext* GrContext::CreateMockContext() { |
| 166 | GrContext* context = SkNEW_ARGS(GrContext, (Options())); |
| 167 | |
| 168 | context->initMockContext(); |
| 169 | return context; |
| 170 | } |
| 171 | |
| 172 | void GrContext::initMockContext() { |
| 173 | SkASSERT(NULL == fGpu); |
| 174 | fGpu = SkNEW_ARGS(MockGpu, (this)); |
| 175 | SkASSERT(fGpu); |
| 176 | this->initCommon(); |
| 177 | |
| 178 | // We delete these because we want to test the cache starting with zero resources. Also, none of |
| 179 | // these objects are required for any of tests that use this context. TODO: make stop allocating |
| 180 | // resources in the buffer pools. |
| 181 | SkDELETE(fDrawBuffer); |
| 182 | SkDELETE(fDrawBufferVBAllocPool); |
| 183 | SkDELETE(fDrawBufferIBAllocPool); |
| 184 | |
| 185 | fDrawBuffer = NULL; |
| 186 | fDrawBufferVBAllocPool = NULL; |
| 187 | fDrawBufferIBAllocPool = NULL; |
| 188 | } |