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