aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrXferProcessor.cpp
blob: 87d5fe65ac7b4345469daf664afc2b8d6c6e56b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "GrXferProcessor.h"
#include "gl/GrGLCaps.h"

GrXferProcessor::GrXferProcessor() : fWillReadDstColor(false), fDstCopyTextureOffset() {
}

GrXferProcessor::GrXferProcessor(const GrDeviceCoordTexture* dstCopy, bool willReadDstColor)
    : fWillReadDstColor(willReadDstColor)
    , fDstCopyTextureOffset() {
    if (dstCopy && dstCopy->texture()) {
        fDstCopy.reset(dstCopy->texture());
        fDstCopyTextureOffset = dstCopy->offset();
        SkASSERT(kTopLeft_GrSurfaceOrigin == fDstCopy.getTexture()->origin());
        this->addTextureAccess(&fDstCopy);
    }
}

void GrXferProcessor::getGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuilder* b) const {
    uint32_t key = this->willReadDstColor() ? 0x1 : 0x0;
    b->add32(key);
    this->onGetGLProcessorKey(caps, b);
}

///////////////////////////////////////////////////////////////////////////////

GrXferProcessor* GrXPFactory::createXferProcessor(const GrProcOptInfo& colorPOI,
                                                  const GrProcOptInfo& coveragePOI,
                                                  const GrDeviceCoordTexture* dstCopy,
                                                  const GrDrawTargetCaps& caps) const {
#ifdef SK_DEBUG
    if (this->willReadDstColor()) {
        if (!caps.dstReadInShaderSupport()) {
            SkASSERT(dstCopy && dstCopy->texture());
        } else {
            SkASSERT(!dstCopy || !dstCopy->texture()); 
        }
    } else {
        SkASSERT(!dstCopy || !dstCopy->texture()); 

    }
#endif
    return this->onCreateXferProcessor(colorPOI, coveragePOI, dstCopy);
}

bool GrXPFactory::willNeedDstCopy(const GrDrawTargetCaps& caps) const {
    return (this->willReadDstColor() && !caps.dstReadInShaderSupport());
}