blob: 237485a9e2798072c9339bb227477fb86181bbe2 [file] [log] [blame]
bsalomon@google.com047696c2012-09-11 13:29:29 +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#ifndef GrTextureAccess_DEFINED
9#define GrTextureAccess_DEFINED
10
bsalomonf96ba022014-09-17 08:05:40 -070011#include "GrGpuResourceRef.h"
bsalomonc4923342014-09-16 13:54:53 -070012#include "GrTexture.h"
bsalomonafa95e22015-10-12 10:39:46 -070013#include "GrTextureParams.h"
bsalomon@google.com6d003d12012-09-11 15:45:20 +000014#include "SkRefCnt.h"
bsalomon@google.com1ce49fc2012-09-18 14:14:49 +000015#include "SkShader.h"
bsalomon@google.com047696c2012-09-11 13:29:29 +000016
bsalomoncdee0092016-01-08 13:20:12 -080017/**
18 * Used to represent a texture that is required by a GrProcessor. It holds a GrTexture along with
19 * an associated GrTextureParams
bsalomon@google.com047696c2012-09-11 13:29:29 +000020 */
bsalomon2a9ca782014-09-05 14:27:43 -070021class GrTextureAccess : public SkNoncopyable {
bsalomon@google.com047696c2012-09-11 13:29:29 +000022public:
bsalomon@google.com6d003d12012-09-11 15:45:20 +000023 /**
bsalomoncdee0092016-01-08 13:20:12 -080024 * Must be initialized before adding to a GrProcessor's texture access list.
bsalomon@google.com6d003d12012-09-11 15:45:20 +000025 */
26 GrTextureAccess();
bsalomon@google.com047696c2012-09-11 13:29:29 +000027
bsalomon@google.com1ce49fc2012-09-18 14:14:49 +000028 GrTextureAccess(GrTexture*, const GrTextureParams&);
bsalomoncdee0092016-01-08 13:20:12 -080029
bsalomon@google.com1ce49fc2012-09-18 14:14:49 +000030 explicit GrTextureAccess(GrTexture*,
humper@google.comb86add12013-07-25 18:49:07 +000031 GrTextureParams::FilterMode = GrTextureParams::kNone_FilterMode,
cdalton9c3f1432016-03-11 10:07:37 -080032 SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode,
cdalton5f2d8e22016-03-11 13:34:32 -080033 GrShaderFlags visibility = kFragment_GrShaderFlag,
34 GrSLPrecision = kDefault_GrSLPrecision);
bsalomon@google.com1ce49fc2012-09-18 14:14:49 +000035
cdalton9c3f1432016-03-11 10:07:37 -080036 void reset(GrTexture*, const GrTextureParams&,
cdalton5f2d8e22016-03-11 13:34:32 -080037 GrShaderFlags visibility = kFragment_GrShaderFlag,
38 GrSLPrecision = kDefault_GrSLPrecision);
bsalomon@google.com1ce49fc2012-09-18 14:14:49 +000039 void reset(GrTexture*,
humper@google.comb86add12013-07-25 18:49:07 +000040 GrTextureParams::FilterMode = GrTextureParams::kNone_FilterMode,
cdalton9c3f1432016-03-11 10:07:37 -080041 SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode,
cdalton5f2d8e22016-03-11 13:34:32 -080042 GrShaderFlags visibility = kFragment_GrShaderFlag,
43 GrSLPrecision = kDefault_GrSLPrecision);
bsalomon@google.com047696c2012-09-11 13:29:29 +000044
bsalomoncdee0092016-01-08 13:20:12 -080045 bool operator==(const GrTextureAccess& that) const {
cdalton9c3f1432016-03-11 10:07:37 -080046 return this->getTexture() == that.getTexture() &&
47 fParams == that.fParams &&
cdalton5f2d8e22016-03-11 13:34:32 -080048 fVisibility == that.fVisibility &&
49 fPrecision == that.fPrecision;
bsalomon@google.com1ce49fc2012-09-18 14:14:49 +000050 }
51
bsalomoncdee0092016-01-08 13:20:12 -080052 bool operator!=(const GrTextureAccess& other) const { return !(*this == other); }
bsalomon@google.com6d003d12012-09-11 15:45:20 +000053
bsalomonc4923342014-09-16 13:54:53 -070054 GrTexture* getTexture() const { return fTexture.get(); }
cdalton9c3f1432016-03-11 10:07:37 -080055 GrShaderFlags getVisibility() const { return fVisibility; }
cdalton5f2d8e22016-03-11 13:34:32 -080056 GrSLPrecision getPrecision() const { return fPrecision; }
bsalomon2a9ca782014-09-05 14:27:43 -070057
58 /**
joshualittb0a8a372014-09-23 09:50:21 -070059 * For internal use by GrProcessor.
bsalomon2a9ca782014-09-05 14:27:43 -070060 */
bsalomonf96ba022014-09-17 08:05:40 -070061 const GrGpuResourceRef* getProgramTexture() const { return &fTexture; }
bsalomon@google.com6d003d12012-09-11 15:45:20 +000062
bsalomon@google.com1ce49fc2012-09-18 14:14:49 +000063 const GrTextureParams& getParams() const { return fParams; }
64
bsalomon@google.com047696c2012-09-11 13:29:29 +000065private:
bsalomon@google.com1ce49fc2012-09-18 14:14:49 +000066
bsalomonf96ba022014-09-17 08:05:40 -070067 typedef GrTGpuResourceRef<GrTexture> ProgramTexture;
bsalomonc4923342014-09-16 13:54:53 -070068
69 ProgramTexture fTexture;
bsalomon2a9ca782014-09-05 14:27:43 -070070 GrTextureParams fParams;
cdalton9c3f1432016-03-11 10:07:37 -080071 GrShaderFlags fVisibility;
cdalton5f2d8e22016-03-11 13:34:32 -080072 GrSLPrecision fPrecision;
bsalomon@google.com1ce49fc2012-09-18 14:14:49 +000073
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000074 typedef SkNoncopyable INHERITED;
bsalomon@google.com047696c2012-09-11 13:29:29 +000075};
76
77#endif