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