blob: 42ac1531c13ae76291d1873c4c634fd55392aea9 [file] [log] [blame]
bsalomon50785a32015-02-06 07:02:37 -08001/*
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
11GrXferProcessor::GrXferProcessor() : fWillReadDstColor(false), fDstCopyTextureOffset() {
12}
13
14GrXferProcessor::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);
egdaniel060a52c2015-04-07 07:31:11 -070021 this->setWillReadFragmentPosition();
bsalomon50785a32015-02-06 07:02:37 -080022 }
23}
24
jvanverthcfc18862015-04-28 08:48:20 -070025void GrXferProcessor::getGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const {
bsalomon50785a32015-02-06 07:02:37 -080026 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
cdalton9954bc32015-04-29 14:17:00 -070035bool 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
bsalomon50785a32015-02-06 07:02:37 -080048///////////////////////////////////////////////////////////////////////////////
49
50GrXferProcessor* GrXPFactory::createXferProcessor(const GrProcOptInfo& colorPOI,
51 const GrProcOptInfo& coveragePOI,
52 const GrDeviceCoordTexture* dstCopy,
53 const GrDrawTargetCaps& caps) const {
54#ifdef SK_DEBUG
egdaniel3ad65702015-02-17 11:15:47 -080055 if (this->willReadDstColor(caps, colorPOI, coveragePOI)) {
jvanverthe9c0fc62015-04-29 11:18:05 -070056 if (!caps.shaderCaps()->dstReadInShaderSupport()) {
bsalomon50785a32015-02-06 07:02:37 -080057 SkASSERT(dstCopy && dstCopy->texture());
58 } else {
59 SkASSERT(!dstCopy || !dstCopy->texture());
60 }
61 } else {
62 SkASSERT(!dstCopy || !dstCopy->texture());
bsalomon50785a32015-02-06 07:02:37 -080063 }
64#endif
egdaniel3ad65702015-02-17 11:15:47 -080065 return this->onCreateXferProcessor(caps, colorPOI, coveragePOI, dstCopy);
bsalomon50785a32015-02-06 07:02:37 -080066}
67
egdaniele36914c2015-02-13 09:00:33 -080068bool GrXPFactory::willNeedDstCopy(const GrDrawTargetCaps& caps, const GrProcOptInfo& colorPOI,
69 const GrProcOptInfo& coveragePOI) const {
jvanverthe9c0fc62015-04-29 11:18:05 -070070 return (this->willReadDstColor(caps, colorPOI, coveragePOI)
71 && !caps.shaderCaps()->dstReadInShaderSupport());
bsalomon50785a32015-02-06 07:02:37 -080072}
73