blob: 476394f8009ae208a459e01415b5b746295a65ff [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
25void 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
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)) {
bsalomon50785a32015-02-06 07:02:37 -080043 if (!caps.dstReadInShaderSupport()) {
44 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 {
egdaniel3ad65702015-02-17 11:15:47 -080057 return (this->willReadDstColor(caps, colorPOI, coveragePOI) && !caps.dstReadInShaderSupport());
bsalomon50785a32015-02-06 07:02:37 -080058}
59