blob: bc79b2dbe1a3ea71c895a33a2886d6b91b57c899 [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
egdanielc19cdc22015-05-10 08:45:18 -070011GrXferProcessor::GrXferProcessor()
12 : fWillReadDstColor(false), fReadsCoverage(true), fDstCopyTextureOffset() {
bsalomon50785a32015-02-06 07:02:37 -080013}
14
15GrXferProcessor::GrXferProcessor(const GrDeviceCoordTexture* dstCopy, bool willReadDstColor)
16 : fWillReadDstColor(willReadDstColor)
egdanielc19cdc22015-05-10 08:45:18 -070017 , fReadsCoverage(true)
bsalomon50785a32015-02-06 07:02:37 -080018 , fDstCopyTextureOffset() {
19 if (dstCopy && dstCopy->texture()) {
20 fDstCopy.reset(dstCopy->texture());
21 fDstCopyTextureOffset = dstCopy->offset();
22 this->addTextureAccess(&fDstCopy);
egdaniel060a52c2015-04-07 07:31:11 -070023 this->setWillReadFragmentPosition();
bsalomon50785a32015-02-06 07:02:37 -080024 }
25}
26
egdanielc19cdc22015-05-10 08:45:18 -070027GrXferProcessor::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
jvanverthcfc18862015-04-28 08:48:20 -070044void GrXferProcessor::getGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const {
bsalomon50785a32015-02-06 07:02:37 -080045 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
cdalton9954bc32015-04-29 14:17:00 -070054bool 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 }
cdalton8917d622015-05-06 13:40:21 -070064 return this->onWillNeedXferBarrier(rt, caps, outBarrierType);
cdalton9954bc32015-04-29 14:17:00 -070065}
66
bsalomon50785a32015-02-06 07:02:37 -080067///////////////////////////////////////////////////////////////////////////////
68
69GrXferProcessor* GrXPFactory::createXferProcessor(const GrProcOptInfo& colorPOI,
70 const GrProcOptInfo& coveragePOI,
71 const GrDeviceCoordTexture* dstCopy,
72 const GrDrawTargetCaps& caps) const {
73#ifdef SK_DEBUG
egdaniel3ad65702015-02-17 11:15:47 -080074 if (this->willReadDstColor(caps, colorPOI, coveragePOI)) {
jvanverthe9c0fc62015-04-29 11:18:05 -070075 if (!caps.shaderCaps()->dstReadInShaderSupport()) {
bsalomon50785a32015-02-06 07:02:37 -080076 SkASSERT(dstCopy && dstCopy->texture());
77 } else {
78 SkASSERT(!dstCopy || !dstCopy->texture());
79 }
80 } else {
81 SkASSERT(!dstCopy || !dstCopy->texture());
bsalomon50785a32015-02-06 07:02:37 -080082 }
83#endif
egdaniel3ad65702015-02-17 11:15:47 -080084 return this->onCreateXferProcessor(caps, colorPOI, coveragePOI, dstCopy);
bsalomon50785a32015-02-06 07:02:37 -080085}
86
egdaniele36914c2015-02-13 09:00:33 -080087bool GrXPFactory::willNeedDstCopy(const GrDrawTargetCaps& caps, const GrProcOptInfo& colorPOI,
88 const GrProcOptInfo& coveragePOI) const {
jvanverthe9c0fc62015-04-29 11:18:05 -070089 return (this->willReadDstColor(caps, colorPOI, coveragePOI)
90 && !caps.shaderCaps()->dstReadInShaderSupport());
bsalomon50785a32015-02-06 07:02:37 -080091}
92