blob: de08ef0ee69c4f5c0a110ab17f1130b2a720fd62 [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
35///////////////////////////////////////////////////////////////////////////////
36
37GrXferProcessor* GrXPFactory::createXferProcessor(const GrProcOptInfo& colorPOI,
38 const GrProcOptInfo& coveragePOI,
39 const GrDeviceCoordTexture* dstCopy,
40 const GrDrawTargetCaps& caps) const {
41#ifdef SK_DEBUG
egdaniel3ad65702015-02-17 11:15:47 -080042 if (this->willReadDstColor(caps, colorPOI, coveragePOI)) {
jvanverthe9c0fc62015-04-29 11:18:05 -070043 if (!caps.shaderCaps()->dstReadInShaderSupport()) {
bsalomon50785a32015-02-06 07:02:37 -080044 SkASSERT(dstCopy && dstCopy->texture());
45 } else {
46 SkASSERT(!dstCopy || !dstCopy->texture());
47 }
48 } else {
49 SkASSERT(!dstCopy || !dstCopy->texture());
bsalomon50785a32015-02-06 07:02:37 -080050 }
51#endif
egdaniel3ad65702015-02-17 11:15:47 -080052 return this->onCreateXferProcessor(caps, colorPOI, coveragePOI, dstCopy);
bsalomon50785a32015-02-06 07:02:37 -080053}
54
egdaniele36914c2015-02-13 09:00:33 -080055bool GrXPFactory::willNeedDstCopy(const GrDrawTargetCaps& caps, const GrProcOptInfo& colorPOI,
56 const GrProcOptInfo& coveragePOI) const {
jvanverthe9c0fc62015-04-29 11:18:05 -070057 return (this->willReadDstColor(caps, colorPOI, coveragePOI)
58 && !caps.shaderCaps()->dstReadInShaderSupport());
bsalomon50785a32015-02-06 07:02:37 -080059}
60