blob: 7db8b91582bcdaa5efa3aad4268689d307502ab2 [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
Robert Phillipsb7bfbc22020-07-01 12:55:01 -040010#include "include/gpu/GrRecordingContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#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
Brian Salomonecbb0fb2020-02-28 18:07:32 -050017GrSurfaceProxyView GrTextureMaker::onView(GrMipMapped mipMapped) {
Robert Phillips9338c602019-02-19 12:52:29 -050018 if (this->width() > this->context()->priv().caps()->maxTextureSize() ||
19 this->height() > this->context()->priv().caps()->maxTextureSize()) {
Greg Danielcc104db2020-02-03 14:17:08 -050020 return {};
Brian Osman875f7852018-04-12 13:29:08 -040021 }
Brian Salomonecbb0fb2020-02-28 18:07:32 -050022 return this->refOriginalTextureProxyView(mipMapped);
Brian Osmane8e54582016-11-28 10:06:27 -050023}
24
Brian Salomonaff329b2017-08-11 09:40:37 -040025std::unique_ptr<GrFragmentProcessor> GrTextureMaker::createFragmentProcessor(
26 const SkMatrix& textureMatrix,
27 const SkRect& constraintRect,
28 FilterConstraint filterConstraint,
29 bool coordsLimitedToConstraintRect,
Brian Salomon777e1462020-02-28 21:10:31 -050030 GrSamplerState::WrapMode wrapX,
31 GrSamplerState::WrapMode wrapY,
Brian Osman05c8f462018-10-22 17:13:36 -040032 const GrSamplerState::Filter* filterOrNullForBicubic) {
Brian Salomon2bbdcc42017-09-07 12:36:34 -040033 const GrSamplerState::Filter* fmForDetermineDomain = filterOrNullForBicubic;
34 if (filterOrNullForBicubic && GrSamplerState::Filter::kMipMap == *filterOrNullForBicubic &&
Brian Osmane8e54582016-11-28 10:06:27 -050035 kYes_FilterConstraint == filterConstraint) {
Michael Ludwigddeed372019-02-20 16:50:10 -050036 // TODO: Here we should force a copy restricted to the constraintRect since MIP maps will
Brian Osmane8e54582016-11-28 10:06:27 -050037 // read outside the constraint rect. However, as in the adjuster case, we aren't currently
38 // doing that.
39 // We instead we compute the domain as though were bilerping which is only correct if we
40 // only sample level 0.
Brian Salomon2bbdcc42017-09-07 12:36:34 -040041 static const GrSamplerState::Filter kBilerp = GrSamplerState::Filter::kBilerp;
Brian Osmane8e54582016-11-28 10:06:27 -050042 fmForDetermineDomain = &kBilerp;
43 }
44
Brian Salomonecbb0fb2020-02-28 18:07:32 -050045 GrSurfaceProxyView view;
46 if (filterOrNullForBicubic) {
47 view = this->view(*filterOrNullForBicubic);
48 } else {
49 view = this->view(GrMipMapped::kNo);
50 }
Brian Salomonc8d092a2020-02-24 10:14:21 -050051 if (!view) {
Brian Osmane8e54582016-11-28 10:06:27 -050052 return nullptr;
53 }
Michael Ludwigddeed372019-02-20 16:50:10 -050054
Brian Osmane8e54582016-11-28 10:06:27 -050055 SkRect domain;
56 DomainMode domainMode =
Brian Salomon4df00922017-09-07 16:34:11 +000057 DetermineDomainMode(constraintRect, filterConstraint, coordsLimitedToConstraintRect,
Greg Danielcc104db2020-02-03 14:17:08 -050058 view.proxy(), fmForDetermineDomain, &domain);
Brian Osmane8e54582016-11-28 10:06:27 -050059 SkASSERT(kTightCopy_DomainMode != domainMode);
Brian Salomon777e1462020-02-28 21:10:31 -050060 return this->createFragmentProcessorForSubsetAndFilter(std::move(view), textureMatrix,
61 domainMode, domain, wrapX, wrapY,
62 filterOrNullForBicubic);
Brian Osmane8e54582016-11-28 10:06:27 -050063}