blob: 904b898c14c34358eef11844ead59926a18726e1 [file] [log] [blame]
bsalomon@google.com68b58c92013-01-17 16:50:08 +00001/*
2 * Copyright 2012 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 "GrSimpleTextureEffect.h"
egdaniel605dd0f2014-11-12 08:35:25 -08009#include "GrInvariantOutput.h"
egdaniel605dd0f2014-11-12 08:35:25 -080010#include "GrTexture.h"
egdaniel64c47282015-11-13 06:54:19 -080011#include "glsl/GrGLSLFragmentProcessor.h"
egdaniel2d721d32015-11-11 13:06:05 -080012#include "glsl/GrGLSLFragmentShaderBuilder.h"
bsalomon@google.com68b58c92013-01-17 16:50:08 +000013
egdaniel64c47282015-11-13 06:54:19 -080014class GrGLSimpleTextureEffect : public GrGLSLFragmentProcessor {
bsalomon@google.com68b58c92013-01-17 16:50:08 +000015public:
robertphillips9cdb9922016-02-03 12:25:40 -080016 void emitCode(EmitArgs& args) override {
cdalton85285412016-02-18 12:37:07 -080017 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
robertphillipsbf536af2016-02-04 06:11:53 -080018 fragBuilder->codeAppendf("%s = ", args.fOutputColor);
egdaniel4ca2e602015-11-18 08:01:26 -080019 fragBuilder->appendTextureLookupAndModulate(args.fInputColor,
wangyix7c157a92015-07-22 15:08:53 -070020 args.fSamplers[0],
21 args.fCoords[0].c_str(),
22 args.fCoords[0].getType());
robertphillipsbf536af2016-02-04 06:11:53 -080023 fragBuilder->codeAppend(";");
bsalomon@google.com68b58c92013-01-17 16:50:08 +000024 }
25
bsalomon@google.com68b58c92013-01-17 16:50:08 +000026private:
egdaniel64c47282015-11-13 06:54:19 -080027 typedef GrGLSLFragmentProcessor INHERITED;
bsalomon@google.com68b58c92013-01-17 16:50:08 +000028};
29
30///////////////////////////////////////////////////////////////////////////////
31
egdaniel605dd0f2014-11-12 08:35:25 -080032void GrSimpleTextureEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const {
egdaniel1a8ecdf2014-10-03 06:24:12 -070033 this->updateInvariantOutputForModulation(inout);
bsalomon@google.com68b58c92013-01-17 16:50:08 +000034}
35
egdaniel57d3b032015-11-13 11:57:27 -080036void GrSimpleTextureEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps,
37 GrProcessorKeyBuilder* b) const {
joshualitteb2a6762014-12-04 11:35:33 -080038 GrGLSimpleTextureEffect::GenKey(*this, caps, b);
39}
40
egdaniel57d3b032015-11-13 11:57:27 -080041GrGLSLFragmentProcessor* GrSimpleTextureEffect::onCreateGLSLInstance() const {
robertphillips9cdb9922016-02-03 12:25:40 -080042 return new GrGLSimpleTextureEffect;
bsalomon@google.com68b58c92013-01-17 16:50:08 +000043}
44
45///////////////////////////////////////////////////////////////////////////////
46
joshualittb0a8a372014-09-23 09:50:21 -070047GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSimpleTextureEffect);
bsalomon@google.com68b58c92013-01-17 16:50:08 +000048
bsalomonc21b09e2015-08-28 18:46:56 -070049const GrFragmentProcessor* GrSimpleTextureEffect::TestCreate(GrProcessorTestData* d) {
joshualitt0067ff52015-07-08 14:26:19 -070050 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx :
51 GrProcessorUnitTest::kAlphaTextureIdx;
bsalomon@google.comc7818882013-03-20 19:19:53 +000052 static const SkShader::TileMode kTileModes[] = {
53 SkShader::kClamp_TileMode,
54 SkShader::kRepeat_TileMode,
55 SkShader::kMirror_TileMode,
56 };
57 SkShader::TileMode tileModes[] = {
joshualitt0067ff52015-07-08 14:26:19 -070058 kTileModes[d->fRandom->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
59 kTileModes[d->fRandom->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
bsalomon@google.comc7818882013-03-20 19:19:53 +000060 };
joshualitt0067ff52015-07-08 14:26:19 -070061 GrTextureParams params(tileModes, d->fRandom->nextBool() ? GrTextureParams::kBilerp_FilterMode :
62 GrTextureParams::kNone_FilterMode);
bsalomon@google.comc7818882013-03-20 19:19:53 +000063
bsalomon@google.com77af6802013-10-02 13:04:56 +000064 static const GrCoordSet kCoordSets[] = {
65 kLocal_GrCoordSet,
bsalomon309d4d52014-12-18 10:17:44 -080066 kDevice_GrCoordSet
bsalomon@google.comc7818882013-03-20 19:19:53 +000067 };
joshualitt0067ff52015-07-08 14:26:19 -070068 GrCoordSet coordSet = kCoordSets[d->fRandom->nextULessThan(SK_ARRAY_COUNT(kCoordSets))];
bsalomon@google.comc7818882013-03-20 19:19:53 +000069
joshualitt0067ff52015-07-08 14:26:19 -070070 const SkMatrix& matrix = GrTest::TestMatrix(d->fRandom);
bsalomon4a339522015-10-06 08:40:50 -070071 return GrSimpleTextureEffect::Create(d->fTextures[texIdx], matrix, coordSet);
bsalomon@google.com68b58c92013-01-17 16:50:08 +000072}