1a8e686eb6cadb74039d3b624ece0d3ccb0684dccbsalomon@google.com
2a8e686eb6cadb74039d3b624ece0d3ccb0684dccbsalomon@google.com/*
3a8e686eb6cadb74039d3b624ece0d3ccb0684dccbsalomon@google.com * Copyright 2011 Google Inc.
4a8e686eb6cadb74039d3b624ece0d3ccb0684dccbsalomon@google.com *
5a8e686eb6cadb74039d3b624ece0d3ccb0684dccbsalomon@google.com * Use of this source code is governed by a BSD-style license that can be
6a8e686eb6cadb74039d3b624ece0d3ccb0684dccbsalomon@google.com * found in the LICENSE file.
7a8e686eb6cadb74039d3b624ece0d3ccb0684dccbsalomon@google.com */
8a8e686eb6cadb74039d3b624ece0d3ccb0684dccbsalomon@google.com
9d472620458e2383e6dd949f4e1aaf61160717ffebsalomon@google.com// This is a GPU-backend specific test. It relies on static intializers to work
10cf8fb1f6f03fc77f9927564f9ef9abeeeec508d2bsalomon@google.com
112a48c3adb7cf4fc754f99a41352210b4a99edf04bsalomon@google.com#include "SkTypes.h"
122a48c3adb7cf4fc754f99a41352210b4a99edf04bsalomon@google.com
132a48c3adb7cf4fc754f99a41352210b4a99edf04bsalomon@google.com#if SK_SUPPORT_GPU && SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
142a48c3adb7cf4fc754f99a41352210b4a99edf04bsalomon@google.com
15396e61fe440590744345e0c56970b26ab464591dbsalomon@google.com#include "GrBackendEffectFactory.h"
1667b915de99e6b89d476907930ac8c27afb64d10ebsalomon@google.com#include "GrContextFactory.h"
17c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com#include "GrDrawEffect.h"
18a04e8e842450e606dd938ddae17857849bd504d4bsalomon@google.com#include "effects/GrConfigConversionEffect.h"
198f6884aab8aecd7657cf3f9cdbc682f0deca29c5tfarina@chromium.org#include "gl/GrGpuGL.h"
20a1bf0fffff821d9c11809c89bd98d4ced480421absalomon@google.com
212db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com#include "SkChecksum.h"
22223137f49d1a4e805f5c1b1c20b7fd68719ac54btfarina@chromium.org#include "SkRandom.h"
23c3841b927ba32237a540949c408f78ad7682aa60bsalomon@google.com#include "Test.h"
24c3841b927ba32237a540949c408f78ad7682aa60bsalomon@google.com
25e0e7cfe44bb9d66d76120a79e5275c294bacaa22commit-bot@chromium.orgvoid GrGLProgramDesc::setRandom(SkRandom* random,
2631ec7985f2b52a0cab4aa714a613b918cf663c08bsalomon@google.com                                const GrGpuGL* gpu,
272db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com                                const GrRenderTarget* dstRenderTarget,
282db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com                                const GrTexture* dstCopyTexture,
292db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com                                const GrEffectStage* stages[],
302db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com                                int numColorStages,
312db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com                                int numCoverageStages,
32054ae99d93711c26e40682a0e3a03a47ea605c53jvanverth@google.com                                int currAttribIndex) {
332db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com    int numEffects = numColorStages + numCoverageStages;
342db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com    size_t keyLength = KeyLength(numEffects);
352db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com    fKey.reset(keyLength);
362db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com    *this->atOffset<uint32_t, kLengthOffset>() = static_cast<uint32_t>(keyLength);
372db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com    memset(this->header(), 0, kHeaderSize);
38054ae99d93711c26e40682a0e3a03a47ea605c53jvanverth@google.com
392db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com    KeyHeader* header = this->header();
402db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com    header->fEmitsPointSize = random->nextBool();
412db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com
422db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com    header->fPositionAttributeIndex = 0;
43054ae99d93711c26e40682a0e3a03a47ea605c53jvanverth@google.com
4405a2ee052c9ef4c781b7b590b00b3d2da3b3449askia.committer@gmail.com    // if the effects have used up all off the available attributes,
45054ae99d93711c26e40682a0e3a03a47ea605c53jvanverth@google.com    // don't try to use color or coverage attributes as input
46054ae99d93711c26e40682a0e3a03a47ea605c53jvanverth@google.com    do {
47949eef0af2f5b47000e637347801cf2970092a38commit-bot@chromium.org        header->fColorInput = static_cast<GrGLProgramDesc::ColorInput>(
48949eef0af2f5b47000e637347801cf2970092a38commit-bot@chromium.org                                  random->nextULessThan(kColorInputCnt));
4905a2ee052c9ef4c781b7b590b00b3d2da3b3449askia.committer@gmail.com    } while (GrDrawState::kMaxVertexAttribCnt <= currAttribIndex &&
502db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com             kAttribute_ColorInput == header->fColorInput);
512db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com    header->fColorAttributeIndex = (header->fColorInput == kAttribute_ColorInput) ?
522db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com                                        currAttribIndex++ :
532db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com                                        -1;
54054ae99d93711c26e40682a0e3a03a47ea605c53jvanverth@google.com
55054ae99d93711c26e40682a0e3a03a47ea605c53jvanverth@google.com    do {
56949eef0af2f5b47000e637347801cf2970092a38commit-bot@chromium.org        header->fCoverageInput = static_cast<GrGLProgramDesc::ColorInput>(
57949eef0af2f5b47000e637347801cf2970092a38commit-bot@chromium.org                                     random->nextULessThan(kColorInputCnt));
58054ae99d93711c26e40682a0e3a03a47ea605c53jvanverth@google.com    } while (GrDrawState::kMaxVertexAttribCnt <= currAttribIndex  &&
592db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com             kAttribute_ColorInput == header->fCoverageInput);
602db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com    header->fCoverageAttributeIndex = (header->fCoverageInput == kAttribute_ColorInput) ?
612db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com                                        currAttribIndex++ :
622db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com                                        -1;
6391207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com
6491207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com#if GR_GL_EXPERIMENTAL_GS
652db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com    header->fExperimentalGS = gpu->caps()->geometryShaderSupport() && random->nextBool();
6691207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com#endif
6791207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com
68054ae99d93711c26e40682a0e3a03a47ea605c53jvanverth@google.com    bool useLocalCoords = random->nextBool() && currAttribIndex < GrDrawState::kMaxVertexAttribCnt;
692db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com    header->fLocalCoordAttributeIndex = useLocalCoords ? currAttribIndex++ : -1;
702db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com
712db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com    header->fColorEffectCnt = numColorStages;
722db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com    header->fCoverageEffectCnt = numCoverageStages;
73c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com
74b79d865f03456b67273b568fa5046b8ba01e365absalomon@google.com    bool dstRead = false;
752db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com    bool fragPos = false;
766b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    bool vertexCode = false;
772db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com    int numStages = numColorStages + numCoverageStages;
782db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com    for (int s = 0; s < numStages; ++s) {
792db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com        const GrBackendEffectFactory& factory = (*stages[s]->getEffect())->getFactory();
802db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com        GrDrawEffect drawEffect(*stages[s], useLocalCoords);
812db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com        this->effectKeys()[s] = factory.glEffectKey(drawEffect, gpu->glCaps());
822db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com        if ((*stages[s]->getEffect())->willReadDstColor()) {
832db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com            dstRead = true;
842db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com        }
852db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com        if ((*stages[s]->getEffect())->willReadFragmentPosition()) {
862db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com            fragPos = true;
8791207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com        }
886b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org        if ((*stages[s]->getEffect())->hasVertexCode()) {
896b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org            vertexCode = true;
906b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org        }
9191207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com    }
929b855c7c95ce9fff7a447e4a6bdf8a469c1f3097jvanverth@google.com
93b79d865f03456b67273b568fa5046b8ba01e365absalomon@google.com    if (dstRead) {
942db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com        header->fDstReadKey = GrGLShaderBuilder::KeyForDstRead(dstCopyTexture, gpu->glCaps());
952db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com    } else {
962db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com        header->fDstReadKey = 0;
972db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com    }
982db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com    if (fragPos) {
992db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com        header->fFragPosKey = GrGLShaderBuilder::KeyForFragmentPosition(dstRenderTarget,
1002db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com                                                                         gpu->glCaps());
1012db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com    } else {
1022db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com        header->fFragPosKey = 0;
103b79d865f03456b67273b568fa5046b8ba01e365absalomon@google.com    }
1045920ac276877b36624e07baf97c7768e80a07f98bsalomon@google.com
1056b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org    header->fHasVertexCode = vertexCode ||
1066b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org                             useLocalCoords ||
1076b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org                             kAttribute_ColorInput == header->fColorInput ||
1086b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org                             kAttribute_ColorInput == header->fCoverageInput;
1096b30e457409f37c91c301cd82040e733e2930286commit-bot@chromium.org
1105920ac276877b36624e07baf97c7768e80a07f98bsalomon@google.com    CoverageOutput coverageOutput;
1115920ac276877b36624e07baf97c7768e80a07f98bsalomon@google.com    bool illegalCoverageOutput;
1125920ac276877b36624e07baf97c7768e80a07f98bsalomon@google.com    do {
1135920ac276877b36624e07baf97c7768e80a07f98bsalomon@google.com        coverageOutput = static_cast<CoverageOutput>(random->nextULessThan(kCoverageOutputCnt));
1145920ac276877b36624e07baf97c7768e80a07f98bsalomon@google.com        illegalCoverageOutput = (!gpu->caps()->dualSourceBlendingSupport() &&
1155920ac276877b36624e07baf97c7768e80a07f98bsalomon@google.com                                 CoverageOutputUsesSecondaryOutput(coverageOutput)) ||
11672993ab54276f8202d49b1e132e01c2a584d1dbebsalomon@google.com                                (!dstRead && kCombineWithDst_CoverageOutput == coverageOutput);
1175920ac276877b36624e07baf97c7768e80a07f98bsalomon@google.com    } while (illegalCoverageOutput);
1185920ac276877b36624e07baf97c7768e80a07f98bsalomon@google.com
1192db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com    header->fCoverageOutput = coverageOutput;
1202db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com
1212db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com    *this->checksum() = 0;
1222db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com    *this->checksum() = SkChecksum::Compute(reinterpret_cast<uint32_t*>(fKey.get()), keyLength);
1232db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com    fInitialized = true;
12491207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com}
12591207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com
126042a2861b2aa7a7a9fff12503a4b297d6ee1d335bsalomon@google.combool GrGpuGL::programUnitTest(int maxStages) {
127042a2861b2aa7a7a9fff12503a4b297d6ee1d335bsalomon@google.com
128d472620458e2383e6dd949f4e1aaf61160717ffebsalomon@google.com    GrTextureDesc dummyDesc;
1292db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com    dummyDesc.fFlags = kRenderTarget_GrTextureFlagBit;
130fec0bc3fc13481f5bcb341ab2d2d695911f39bd4bsalomon@google.com    dummyDesc.fConfig = kSkia8888_GrPixelConfig;
131d472620458e2383e6dd949f4e1aaf61160717ffebsalomon@google.com    dummyDesc.fWidth = 34;
132d472620458e2383e6dd949f4e1aaf61160717ffebsalomon@google.com    dummyDesc.fHeight = 18;
133d472620458e2383e6dd949f4e1aaf61160717ffebsalomon@google.com    SkAutoTUnref<GrTexture> dummyTexture1(this->createTexture(dummyDesc, NULL, 0));
1342db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com    dummyDesc.fFlags = kNone_GrTextureFlags;
135d472620458e2383e6dd949f4e1aaf61160717ffebsalomon@google.com    dummyDesc.fConfig = kAlpha_8_GrPixelConfig;
136d472620458e2383e6dd949f4e1aaf61160717ffebsalomon@google.com    dummyDesc.fWidth = 16;
137d472620458e2383e6dd949f4e1aaf61160717ffebsalomon@google.com    dummyDesc.fHeight = 22;
138d472620458e2383e6dd949f4e1aaf61160717ffebsalomon@google.com    SkAutoTUnref<GrTexture> dummyTexture2(this->createTexture(dummyDesc, NULL, 0));
139d472620458e2383e6dd949f4e1aaf61160717ffebsalomon@google.com
140c3841b927ba32237a540949c408f78ad7682aa60bsalomon@google.com    static const int NUM_TESTS = 512;
141c3841b927ba32237a540949c408f78ad7682aa60bsalomon@google.com
142e0e7cfe44bb9d66d76120a79e5275c294bacaa22commit-bot@chromium.org    SkRandom random;
143c3841b927ba32237a540949c408f78ad7682aa60bsalomon@google.com    for (int t = 0; t < NUM_TESTS; ++t) {
144c3841b927ba32237a540949c408f78ad7682aa60bsalomon@google.com
145c3841b927ba32237a540949c408f78ad7682aa60bsalomon@google.com#if 0
146c3841b927ba32237a540949c408f78ad7682aa60bsalomon@google.com        GrPrintf("\nTest Program %d\n-------------\n", t);
147c3841b927ba32237a540949c408f78ad7682aa60bsalomon@google.com        static const int stop = -1;
148c3841b927ba32237a540949c408f78ad7682aa60bsalomon@google.com        if (t == stop) {
149c3841b927ba32237a540949c408f78ad7682aa60bsalomon@google.com            int breakpointhere = 9;
150c3841b927ba32237a540949c408f78ad7682aa60bsalomon@google.com        }
151c3841b927ba32237a540949c408f78ad7682aa60bsalomon@google.com#endif
152c3841b927ba32237a540949c408f78ad7682aa60bsalomon@google.com
15331ec7985f2b52a0cab4aa714a613b918cf663c08bsalomon@google.com        GrGLProgramDesc pdesc;
154c3841b927ba32237a540949c408f78ad7682aa60bsalomon@google.com
155054ae99d93711c26e40682a0e3a03a47ea605c53jvanverth@google.com        int currAttribIndex = 1;  // we need to always leave room for position
1568e919add406c5d20918a7f0ca811317312e6ce67commit-bot@chromium.org        int currTextureCoordSet = 0;
1574324c3ba707a567d45628b80073c2e44d2d0e4e4commit-bot@chromium.org        int attribIndices[2] = { 0, 0 };
158b79d865f03456b67273b568fa5046b8ba01e365absalomon@google.com        GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()};
1592db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com
1602db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com        int numStages = random.nextULessThan(maxStages + 1);
1612db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com        int numColorStages = random.nextULessThan(numStages + 1);
1622db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com        int numCoverageStages = numStages - numColorStages;
1632db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com
1642db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com        SkAutoSTMalloc<8, const GrEffectStage*> stages(numStages);
1652db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com
1668e919add406c5d20918a7f0ca811317312e6ce67commit-bot@chromium.org        bool useFixedFunctionTexturing = this->shouldUseFixedFunctionTexturing();
1678e919add406c5d20918a7f0ca811317312e6ce67commit-bot@chromium.org
1688e919add406c5d20918a7f0ca811317312e6ce67commit-bot@chromium.org        for (int s = 0; s < numStages;) {
1692db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com            SkAutoTUnref<const GrEffectRef> effect(GrEffectTestFactory::CreateStage(
1702db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com                                                                            &random,
1712db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com                                                                            this->getContext(),
1722db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com                                                                            *this->caps(),
1732db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com                                                                            dummyTextures));
17465ee5f424cb4dabd453268902c00086605d77c1dcommit-bot@chromium.org            SkASSERT(effect);
1752db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com            int numAttribs = (*effect)->numVertexAttribs();
1762db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com
1772db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com            // If adding this effect would exceed the max attrib count then generate a
1782db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com            // new random effect.
1792db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com            if (currAttribIndex + numAttribs > GrDrawState::kMaxVertexAttribCnt) {
1802db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com                continue;
1812db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com            }
1828e919add406c5d20918a7f0ca811317312e6ce67commit-bot@chromium.org
1838e919add406c5d20918a7f0ca811317312e6ce67commit-bot@chromium.org
1848e919add406c5d20918a7f0ca811317312e6ce67commit-bot@chromium.org            // If adding this effect would exceed the max texture coord set count then generate a
1858e919add406c5d20918a7f0ca811317312e6ce67commit-bot@chromium.org            // new random effect.
1868e919add406c5d20918a7f0ca811317312e6ce67commit-bot@chromium.org            if (useFixedFunctionTexturing && !(*effect)->hasVertexCode()) {
1878e919add406c5d20918a7f0ca811317312e6ce67commit-bot@chromium.org                int numTransforms = (*effect)->numTransforms();
1888e919add406c5d20918a7f0ca811317312e6ce67commit-bot@chromium.org                if (currTextureCoordSet + numTransforms > this->glCaps().maxFixedFunctionTextureCoords()) {
1898e919add406c5d20918a7f0ca811317312e6ce67commit-bot@chromium.org                    continue;
1908e919add406c5d20918a7f0ca811317312e6ce67commit-bot@chromium.org                }
1918e919add406c5d20918a7f0ca811317312e6ce67commit-bot@chromium.org                currTextureCoordSet += numTransforms;
1928e919add406c5d20918a7f0ca811317312e6ce67commit-bot@chromium.org            }
1938e919add406c5d20918a7f0ca811317312e6ce67commit-bot@chromium.org
1948e919add406c5d20918a7f0ca811317312e6ce67commit-bot@chromium.org            useFixedFunctionTexturing = useFixedFunctionTexturing && !(*effect)->hasVertexCode();
1958e919add406c5d20918a7f0ca811317312e6ce67commit-bot@chromium.org
1962db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com            for (int i = 0; i < numAttribs; ++i) {
1972db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com                attribIndices[i] = currAttribIndex++;
198c3841b927ba32237a540949c408f78ad7682aa60bsalomon@google.com            }
1992d3b49201302f3f82e405a750724eae8ef82e5a0commit-bot@chromium.org            GrEffectStage* stage = SkNEW_ARGS(GrEffectStage,
2002d3b49201302f3f82e405a750724eae8ef82e5a0commit-bot@chromium.org                                              (effect.get(), attribIndices[0], attribIndices[1]));
2012db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com            stages[s] = stage;
2028e919add406c5d20918a7f0ca811317312e6ce67commit-bot@chromium.org            ++s;
203c3841b927ba32237a540949c408f78ad7682aa60bsalomon@google.com        }
204b79d865f03456b67273b568fa5046b8ba01e365absalomon@google.com        const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dummyTextures[1];
2052db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com        pdesc.setRandom(&random,
2062db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com                        this,
2072db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com                        dummyTextures[0]->asRenderTarget(),
2082db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com                        dstTexture,
2092db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com                        stages.get(),
2102db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com                        numColorStages,
2112db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com                        numCoverageStages,
2122db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com                        currAttribIndex);
21305a2ee052c9ef4c781b7b590b00b3d2da3b3449askia.committer@gmail.com
2149188a15f846ae79892c332aed2a72ee38116bdc6commit-bot@chromium.org        SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this,
215c3841b927ba32237a540949c408f78ad7682aa60bsalomon@google.com                                                              pdesc,
2162c84aa35988c661b3e5513c8ba9b3959832ff288bsalomon@google.com                                                              stages,
2172c84aa35988c661b3e5513c8ba9b3959832ff288bsalomon@google.com                                                              stages + numColorStages));
2182db3ded335fdb6697623bece61cabc307a414770bsalomon@google.com        for (int s = 0; s < numStages; ++s) {
219504976ef6f1b969c2ac13ff1140ea1067f085ffabsalomon@google.com            SkDELETE(stages[s]);
220504976ef6f1b969c2ac13ff1140ea1067f085ffabsalomon@google.com        }
221c3841b927ba32237a540949c408f78ad7682aa60bsalomon@google.com        if (NULL == program.get()) {
222c3841b927ba32237a540949c408f78ad7682aa60bsalomon@google.com            return false;
223c3841b927ba32237a540949c408f78ad7682aa60bsalomon@google.com        }
224c3841b927ba32237a540949c408f78ad7682aa60bsalomon@google.com    }
225c3841b927ba32237a540949c408f78ad7682aa60bsalomon@google.com    return true;
226c3841b927ba32237a540949c408f78ad7682aa60bsalomon@google.com}
227a8e686eb6cadb74039d3b624ece0d3ccb0684dccbsalomon@google.com
2284ee16bfaedb14aff8cf102f1f0722ff2529a9699tfarina@chromium.orgDEF_GPUTEST(GLPrograms, reporter, factory) {
22967b915de99e6b89d476907930ac8c27afb64d10ebsalomon@google.com    for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
23067b915de99e6b89d476907930ac8c27afb64d10ebsalomon@google.com        GrContext* context = factory->get(static_cast<GrContextFactory::GLContextType>(type));
23167b915de99e6b89d476907930ac8c27afb64d10ebsalomon@google.com        if (NULL != context) {
232042a2861b2aa7a7a9fff12503a4b297d6ee1d335bsalomon@google.com            GrGpuGL* gpu = static_cast<GrGpuGL*>(context->getGpu());
233eb6879f50a5564eeb981ec5616b55bf685eb76fcbsalomon@google.com            int maxStages = 6;
234042a2861b2aa7a7a9fff12503a4b297d6ee1d335bsalomon@google.com#if SK_ANGLE
235042a2861b2aa7a7a9fff12503a4b297d6ee1d335bsalomon@google.com            // Some long shaders run out of temporary registers in the D3D compiler on ANGLE.
236042a2861b2aa7a7a9fff12503a4b297d6ee1d335bsalomon@google.com            if (type == GrContextFactory::kANGLE_GLContextType) {
237042a2861b2aa7a7a9fff12503a4b297d6ee1d335bsalomon@google.com                maxStages = 3;
238042a2861b2aa7a7a9fff12503a4b297d6ee1d335bsalomon@google.com            }
239042a2861b2aa7a7a9fff12503a4b297d6ee1d335bsalomon@google.com#endif
240042a2861b2aa7a7a9fff12503a4b297d6ee1d335bsalomon@google.com            REPORTER_ASSERT(reporter, gpu->programUnitTest(maxStages));
24167b915de99e6b89d476907930ac8c27afb64d10ebsalomon@google.com        }
24267b915de99e6b89d476907930ac8c27afb64d10ebsalomon@google.com    }
243a8e686eb6cadb74039d3b624ece0d3ccb0684dccbsalomon@google.com}
244a8e686eb6cadb74039d3b624ece0d3ccb0684dccbsalomon@google.com
245d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com// This is evil evil evil. The linker may throw away whole translation units as dead code if it
24667e78c9e47c38a51816412a24a10f4fe2db142a3bsalomon@google.com// thinks none of the functions are called. It will do this even if there are static initializers
247a1bf0fffff821d9c11809c89bd98d4ced480421absalomon@google.com// in the unit that could pass pointers to functions from the unit out to other translation units!
248a1bf0fffff821d9c11809c89bd98d4ced480421absalomon@google.com// We force some of the effects that would otherwise be discarded to link here.
249a1bf0fffff821d9c11809c89bd98d4ced480421absalomon@google.com
25040eb3c100095c8573ddfdc553794b3182d7b18d1commit-bot@chromium.org#include "SkAlphaThresholdFilter.h"
2518f6884aab8aecd7657cf3f9cdbc682f0deca29c5tfarina@chromium.org#include "SkColorMatrixFilter.h"
252a1bf0fffff821d9c11809c89bd98d4ced480421absalomon@google.com#include "SkLightingImageFilter.h"
25382aa7482cbf55ce6d42c692550cadee5e23146e4bsalomon@google.com#include "SkMagnifierImageFilter.h"
254a1bf0fffff821d9c11809c89bd98d4ced480421absalomon@google.com
255a1bf0fffff821d9c11809c89bd98d4ced480421absalomon@google.comvoid forceLinking();
256a1bf0fffff821d9c11809c89bd98d4ced480421absalomon@google.com
257a1bf0fffff821d9c11809c89bd98d4ced480421absalomon@google.comvoid forceLinking() {
258a1bf0fffff821d9c11809c89bd98d4ced480421absalomon@google.com    SkLightingImageFilter::CreateDistantLitDiffuse(SkPoint3(0,0,0), 0, 0, 0);
2599109e188c77abfd2832767530d33fdec35290a84commit-bot@chromium.org    SkAlphaThresholdFilter::Create(SkRegion(), .5f, .5f);
260cac5fd597f6e2495f50aaa6bcbe3dadc56f0b977commit-bot@chromium.org    SkAutoTUnref<SkMagnifierImageFilter> mag(SkMagnifierImageFilter::Create(
261cac5fd597f6e2495f50aaa6bcbe3dadc56f0b977commit-bot@chromium.org        SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar1));
262adc6536fe5baff2216fb76ecda6cc81c61109d5cbsalomon@google.com    GrConfigConversionEffect::Create(NULL,
263adc6536fe5baff2216fb76ecda6cc81c61109d5cbsalomon@google.com                                     false,
264adc6536fe5baff2216fb76ecda6cc81c61109d5cbsalomon@google.com                                     GrConfigConversionEffect::kNone_PMConversion,
265adc6536fe5baff2216fb76ecda6cc81c61109d5cbsalomon@google.com                                     SkMatrix::I());
26667e78c9e47c38a51816412a24a10f4fe2db142a3bsalomon@google.com    SkScalar matrix[20];
267727a352f7412753d2a3e4d30eab6500a1a4de135commit-bot@chromium.org    SkAutoTUnref<SkColorMatrixFilter> cmf(SkColorMatrixFilter::Create(matrix));
268a1bf0fffff821d9c11809c89bd98d4ced480421absalomon@google.com}
269a1bf0fffff821d9c11809c89bd98d4ced480421absalomon@google.com
270cf8fb1f6f03fc77f9927564f9ef9abeeeec508d2bsalomon@google.com#endif
271