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 | |
| 25 | void GrXferProcessor::getGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuilder* b) const { |
| 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 | |
| 35 | /////////////////////////////////////////////////////////////////////////////// |
| 36 | |
| 37 | GrXferProcessor* GrXPFactory::createXferProcessor(const GrProcOptInfo& colorPOI, |
| 38 | const GrProcOptInfo& coveragePOI, |
| 39 | const GrDeviceCoordTexture* dstCopy, |
| 40 | const GrDrawTargetCaps& caps) const { |
| 41 | #ifdef SK_DEBUG |
egdaniel | 3ad6570 | 2015-02-17 11:15:47 -0800 | [diff] [blame] | 42 | if (this->willReadDstColor(caps, colorPOI, coveragePOI)) { |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 43 | if (!caps.dstReadInShaderSupport()) { |
| 44 | SkASSERT(dstCopy && dstCopy->texture()); |
| 45 | } else { |
| 46 | SkASSERT(!dstCopy || !dstCopy->texture()); |
| 47 | } |
| 48 | } else { |
| 49 | SkASSERT(!dstCopy || !dstCopy->texture()); |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 50 | } |
| 51 | #endif |
egdaniel | 3ad6570 | 2015-02-17 11:15:47 -0800 | [diff] [blame] | 52 | return this->onCreateXferProcessor(caps, colorPOI, coveragePOI, dstCopy); |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 53 | } |
| 54 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 55 | bool GrXPFactory::willNeedDstCopy(const GrDrawTargetCaps& caps, const GrProcOptInfo& colorPOI, |
| 56 | const GrProcOptInfo& coveragePOI) const { |
egdaniel | 3ad6570 | 2015-02-17 11:15:47 -0800 | [diff] [blame] | 57 | return (this->willReadDstColor(caps, colorPOI, coveragePOI) && !caps.dstReadInShaderSupport()); |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 58 | } |
| 59 | |