bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | |
| 8 | #include "GrXferProcessor.h" |
| 9 | #include "gl/GrGLCaps.h" |
| 10 | |
egdaniel | c19cdc2 | 2015-05-10 08:45:18 -0700 | [diff] [blame^] | 11 | GrXferProcessor::GrXferProcessor() |
| 12 | : fWillReadDstColor(false), fReadsCoverage(true), fDstCopyTextureOffset() { |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 13 | } |
| 14 | |
| 15 | GrXferProcessor::GrXferProcessor(const GrDeviceCoordTexture* dstCopy, bool willReadDstColor) |
| 16 | : fWillReadDstColor(willReadDstColor) |
egdaniel | c19cdc2 | 2015-05-10 08:45:18 -0700 | [diff] [blame^] | 17 | , fReadsCoverage(true) |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 18 | , fDstCopyTextureOffset() { |
| 19 | if (dstCopy && dstCopy->texture()) { |
| 20 | fDstCopy.reset(dstCopy->texture()); |
| 21 | fDstCopyTextureOffset = dstCopy->offset(); |
| 22 | this->addTextureAccess(&fDstCopy); |
egdaniel | 060a52c | 2015-04-07 07:31:11 -0700 | [diff] [blame] | 23 | this->setWillReadFragmentPosition(); |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 24 | } |
| 25 | } |
| 26 | |
egdaniel | c19cdc2 | 2015-05-10 08:45:18 -0700 | [diff] [blame^] | 27 | GrXferProcessor::OptFlags GrXferProcessor::getOptimizations(const GrProcOptInfo& colorPOI, |
| 28 | const GrProcOptInfo& coveragePOI, |
| 29 | bool doesStencilWrite, |
| 30 | GrColor* overrideColor, |
| 31 | const GrDrawTargetCaps& caps) { |
| 32 | GrXferProcessor::OptFlags flags = this->onGetOptimizations(colorPOI, |
| 33 | coveragePOI, |
| 34 | doesStencilWrite, |
| 35 | overrideColor, |
| 36 | caps); |
| 37 | |
| 38 | if (flags & GrXferProcessor::kIgnoreCoverage_OptFlag) { |
| 39 | fReadsCoverage = false; |
| 40 | } |
| 41 | return flags; |
| 42 | } |
| 43 | |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 44 | void GrXferProcessor::getGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const { |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 45 | uint32_t key = this->willReadDstColor() ? 0x1 : 0x0; |
| 46 | if (this->getDstCopyTexture() && |
| 47 | kTopLeft_GrSurfaceOrigin == this->getDstCopyTexture()->origin()) { |
| 48 | key |= 0x2; |
| 49 | } |
| 50 | b->add32(key); |
| 51 | this->onGetGLProcessorKey(caps, b); |
| 52 | } |
| 53 | |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 54 | bool GrXferProcessor::willNeedXferBarrier(const GrRenderTarget* rt, |
| 55 | const GrDrawTargetCaps& caps, |
| 56 | GrXferBarrierType* outBarrierType) const { |
| 57 | if (static_cast<const GrSurface*>(rt) == this->getDstCopyTexture()) { |
| 58 | // Texture barriers are required when a shader reads and renders to the same texture. |
| 59 | SkASSERT(rt); |
| 60 | SkASSERT(caps.textureBarrierSupport()); |
| 61 | *outBarrierType = kTexture_GrXferBarrierType; |
| 62 | return true; |
| 63 | } |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 64 | return this->onWillNeedXferBarrier(rt, caps, outBarrierType); |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 65 | } |
| 66 | |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 67 | /////////////////////////////////////////////////////////////////////////////// |
| 68 | |
| 69 | GrXferProcessor* GrXPFactory::createXferProcessor(const GrProcOptInfo& colorPOI, |
| 70 | const GrProcOptInfo& coveragePOI, |
| 71 | const GrDeviceCoordTexture* dstCopy, |
| 72 | const GrDrawTargetCaps& caps) const { |
| 73 | #ifdef SK_DEBUG |
egdaniel | 3ad6570 | 2015-02-17 11:15:47 -0800 | [diff] [blame] | 74 | if (this->willReadDstColor(caps, colorPOI, coveragePOI)) { |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 75 | if (!caps.shaderCaps()->dstReadInShaderSupport()) { |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 76 | SkASSERT(dstCopy && dstCopy->texture()); |
| 77 | } else { |
| 78 | SkASSERT(!dstCopy || !dstCopy->texture()); |
| 79 | } |
| 80 | } else { |
| 81 | SkASSERT(!dstCopy || !dstCopy->texture()); |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 82 | } |
| 83 | #endif |
egdaniel | 3ad6570 | 2015-02-17 11:15:47 -0800 | [diff] [blame] | 84 | return this->onCreateXferProcessor(caps, colorPOI, coveragePOI, dstCopy); |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 85 | } |
| 86 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 87 | bool GrXPFactory::willNeedDstCopy(const GrDrawTargetCaps& caps, const GrProcOptInfo& colorPOI, |
| 88 | const GrProcOptInfo& coveragePOI) const { |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 89 | return (this->willReadDstColor(caps, colorPOI, coveragePOI) |
| 90 | && !caps.shaderCaps()->dstReadInShaderSupport()); |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 91 | } |
| 92 | |