GrXferProcessor.cpp revision 7adb35559430303a25be37f21af56c0df6c62f2b
1/*
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        SkASSERT(kTopLeft_GrSurfaceOrigin == fDstCopy.getTexture()->origin());
21        this->addTextureAccess(&fDstCopy);
22    }
23}
24
25void GrXferProcessor::getGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuilder* b) const {
26    uint32_t key = this->willReadDstColor() ? 0x1 : 0x0;
27    b->add32(key);
28    this->onGetGLProcessorKey(caps, b);
29}
30
31///////////////////////////////////////////////////////////////////////////////
32
33GrXferProcessor* GrXPFactory::createXferProcessor(const GrProcOptInfo& colorPOI,
34                                                  const GrProcOptInfo& coveragePOI,
35                                                  const GrDeviceCoordTexture* dstCopy,
36                                                  const GrDrawTargetCaps& caps) const {
37#ifdef SK_DEBUG
38    if (this->willReadDstColor()) {
39        if (!caps.dstReadInShaderSupport()) {
40            SkASSERT(dstCopy && dstCopy->texture());
41        } else {
42            SkASSERT(!dstCopy || !dstCopy->texture());
43        }
44    } else {
45        SkASSERT(!dstCopy || !dstCopy->texture());
46
47    }
48#endif
49    return this->onCreateXferProcessor(colorPOI, coveragePOI, dstCopy);
50}
51
52bool GrXPFactory::willNeedDstCopy(const GrDrawTargetCaps& caps) const {
53    return (this->willReadDstColor() && !caps.dstReadInShaderSupport());
54}
55
56