blob: de73479e4100e4fdfe1951767127549aa398fb18 [file] [log] [blame]
Brian Osmane8e54582016-11-28 10:06:27 -05001/*
2 * Copyright 2016 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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/GrTextureMaker.h"
Brian Osmane8e54582016-11-28 10:06:27 -05009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/private/GrRecordingContext.h"
11#include "src/gpu/GrColorSpaceXform.h"
12#include "src/gpu/GrGpu.h"
13#include "src/gpu/GrProxyProvider.h"
14#include "src/gpu/GrRecordingContextPriv.h"
Brian Salomonadc9bbb2020-02-20 20:10:31 -050015#include "src/gpu/SkGr.h"
Brian Osmane8e54582016-11-28 10:06:27 -050016
Greg Danielcc104db2020-02-03 14:17:08 -050017GrSurfaceProxyView GrTextureMaker::onRefTextureProxyViewForParams(GrSamplerState params,
Brian Salomonc8d092a2020-02-24 10:14:21 -050018 bool willBeMipped) {
Robert Phillips9338c602019-02-19 12:52:29 -050019 if (this->width() > this->context()->priv().caps()->maxTextureSize() ||
20 this->height() > this->context()->priv().caps()->maxTextureSize()) {
Greg Danielcc104db2020-02-03 14:17:08 -050021 return {};
Brian Osman875f7852018-04-12 13:29:08 -040022 }
Brian Salomonf5391302020-02-28 10:25:47 -050023 return this->refOriginalTextureProxyView(willBeMipped);
Brian Osmane8e54582016-11-28 10:06:27 -050024}
25
Brian Salomonaff329b2017-08-11 09:40:37 -040026std::unique_ptr<GrFragmentProcessor> GrTextureMaker::createFragmentProcessor(
27 const SkMatrix& textureMatrix,
28 const SkRect& constraintRect,
29 FilterConstraint filterConstraint,
30 bool coordsLimitedToConstraintRect,
Brian Osman05c8f462018-10-22 17:13:36 -040031 const GrSamplerState::Filter* filterOrNullForBicubic) {
Brian Salomon2bbdcc42017-09-07 12:36:34 -040032 const GrSamplerState::Filter* fmForDetermineDomain = filterOrNullForBicubic;
33 if (filterOrNullForBicubic && GrSamplerState::Filter::kMipMap == *filterOrNullForBicubic &&
Brian Osmane8e54582016-11-28 10:06:27 -050034 kYes_FilterConstraint == filterConstraint) {
Michael Ludwigddeed372019-02-20 16:50:10 -050035 // TODO: Here we should force a copy restricted to the constraintRect since MIP maps will
Brian Osmane8e54582016-11-28 10:06:27 -050036 // read outside the constraint rect. However, as in the adjuster case, we aren't currently
37 // doing that.
38 // We instead we compute the domain as though were bilerping which is only correct if we
39 // only sample level 0.
Brian Salomon2bbdcc42017-09-07 12:36:34 -040040 static const GrSamplerState::Filter kBilerp = GrSamplerState::Filter::kBilerp;
Brian Osmane8e54582016-11-28 10:06:27 -050041 fmForDetermineDomain = &kBilerp;
42 }
43
Brian Salomonc8d092a2020-02-24 10:14:21 -050044 GrSurfaceProxyView view = this->viewForParams(filterOrNullForBicubic);
45 if (!view) {
Brian Osmane8e54582016-11-28 10:06:27 -050046 return nullptr;
47 }
Michael Ludwigddeed372019-02-20 16:50:10 -050048
Brian Osmane8e54582016-11-28 10:06:27 -050049 SkRect domain;
50 DomainMode domainMode =
Brian Salomon4df00922017-09-07 16:34:11 +000051 DetermineDomainMode(constraintRect, filterConstraint, coordsLimitedToConstraintRect,
Greg Danielcc104db2020-02-03 14:17:08 -050052 view.proxy(), fmForDetermineDomain, &domain);
Brian Osmane8e54582016-11-28 10:06:27 -050053 SkASSERT(kTightCopy_DomainMode != domainMode);
Michael Ludwigddeed372019-02-20 16:50:10 -050054 return this->createFragmentProcessorForDomainAndFilter(
Brian Salomonc8d092a2020-02-24 10:14:21 -050055 std::move(view), textureMatrix, domainMode, domain, filterOrNullForBicubic);
Brian Osmane8e54582016-11-28 10:06:27 -050056}