blob: 2a1d6d6cb04e4a4677d948783815b6ab635962f7 [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
Brian Salomonb8f098d2020-01-07 11:15:44 -05008#include "src/gpu/GrTextureProducer.h"
9
Robert Phillipsb7bfbc22020-07-01 12:55:01 -040010#include "include/gpu/GrRecordingContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/core/SkMipMap.h"
12#include "src/core/SkRectPriv.h"
13#include "src/gpu/GrClip.h"
14#include "src/gpu/GrContextPriv.h"
15#include "src/gpu/GrProxyProvider.h"
16#include "src/gpu/GrRecordingContextPriv.h"
17#include "src/gpu/GrRenderTargetContext.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040018#include "src/gpu/GrTextureProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050019#include "src/gpu/SkGr.h"
20#include "src/gpu/effects/GrBicubicEffect.h"
Brian Salomonb8f098d2020-01-07 11:15:44 -050021#include "src/gpu/effects/GrTextureEffect.h"
Brian Osmane8e54582016-11-28 10:06:27 -050022
Brian Salomon777e1462020-02-28 21:10:31 -050023std::unique_ptr<GrFragmentProcessor> GrTextureProducer::createFragmentProcessorForSubsetAndFilter(
Greg Danielcc104db2020-02-03 14:17:08 -050024 GrSurfaceProxyView view,
Brian Salomonaff329b2017-08-11 09:40:37 -040025 const SkMatrix& textureMatrix,
Brian Salomonf990b6a2020-07-13 10:44:22 -040026 bool coordsLimitedToConstraintRect,
27 FilterConstraint filterConstraint,
28 const SkRect& constraintRect,
Brian Salomon777e1462020-02-28 21:10:31 -050029 GrSamplerState::WrapMode wrapX,
30 GrSamplerState::WrapMode wrapY,
Brian Salomon2bbdcc42017-09-07 12:36:34 -040031 const GrSamplerState::Filter* filterOrNullForBicubic) {
Brian Salomonf990b6a2020-07-13 10:44:22 -040032 SkRect tempSubset;
33
34 const SkRect* subset = nullptr;
35 if (filterConstraint == kYes_FilterConstraint) {
36 subset = &constraintRect;
37 } else if (!view.proxy()->isFullyLazy() && !view.proxy()->isFunctionallyExact()) {
38 tempSubset = view.proxy()->getBoundsRect();
39 subset = &tempSubset;
40 }
41
Brian Salomonca6b2f42020-01-24 11:31:21 -050042 const auto& caps = *fContext->priv().caps();
Robert Phillipsb66b42f2017-03-14 08:53:02 -040043 if (filterOrNullForBicubic) {
Brian Salomon777e1462020-02-28 21:10:31 -050044 GrSamplerState samplerState(wrapX, wrapY, *filterOrNullForBicubic);
Brian Salomonf990b6a2020-07-13 10:44:22 -040045 if (subset) {
46 if (coordsLimitedToConstraintRect) {
47 return GrTextureEffect::MakeSubset(std::move(view), this->alphaType(),
48 textureMatrix, samplerState, *subset,
49 constraintRect, caps);
50 } else {
51 return GrTextureEffect::MakeSubset(std::move(view), this->alphaType(),
52 textureMatrix, samplerState, *subset, caps);
53 }
54 } else {
55 return GrTextureEffect::Make(std::move(view), this->alphaType(), textureMatrix,
56 samplerState, caps);
Robert Phillipsb66b42f2017-03-14 08:53:02 -040057 }
58 } else {
Brian Salomon1af72d12020-06-25 10:47:26 -040059 static constexpr auto kDir = GrBicubicEffect::Direction::kXY;
60 static constexpr auto kKernel = GrBicubicEffect::Kernel::kMitchell;
Brian Salomonf990b6a2020-07-13 10:44:22 -040061 if (subset) {
62 if (coordsLimitedToConstraintRect) {
63 return GrBicubicEffect::MakeSubset(std::move(view), this->alphaType(),
64 textureMatrix, wrapX, wrapY, *subset,
65 constraintRect, kKernel, kDir, caps);
66 } else {
67 return GrBicubicEffect::MakeSubset(std::move(view), this->alphaType(),
68 textureMatrix, wrapX, wrapY, *subset, kKernel,
69 kDir, caps);
70 }
Robert Phillipsb66b42f2017-03-14 08:53:02 -040071 } else {
Brian Salomonf990b6a2020-07-13 10:44:22 -040072 return GrBicubicEffect::Make(std::move(view), this->alphaType(), textureMatrix, wrapX,
73 wrapY, kKernel, kDir, caps);
Robert Phillipsb66b42f2017-03-14 08:53:02 -040074 }
75 }
76}
Brian Salomon2a943df2018-05-04 13:43:19 -040077
Brian Salomonecbb0fb2020-02-28 18:07:32 -050078GrSurfaceProxyView GrTextureProducer::view(GrMipMapped mipMapped) {
79 const GrCaps* caps = this->context()->priv().caps();
80 // Sanitize the MIP map request.
81 if (mipMapped == GrMipMapped::kYes) {
82 if ((this->width() == 1 && this->height() == 1) || !caps->mipMapSupport()) {
83 mipMapped = GrMipMapped::kNo;
Michael Ludwigddeed372019-02-20 16:50:10 -050084 }
85 }
Brian Salomonecbb0fb2020-02-28 18:07:32 -050086 auto result = this->onView(mipMapped);
87 // Check to make sure if we requested MIPs that the returned texture has MIP maps or the format
88 // is not copyable.
89 SkASSERT(!result || mipMapped == GrMipMapped::kNo ||
90 result.asTextureProxy()->mipMapped() == GrMipMapped::kYes ||
Greg Danielcc104db2020-02-03 14:17:08 -050091 !caps->isFormatCopyable(result.proxy()->backendFormat()));
Brian Salomon2a943df2018-05-04 13:43:19 -040092 return result;
93}
Greg Daniel5f4b09d2018-06-12 16:39:59 -040094
Brian Salomonecbb0fb2020-02-28 18:07:32 -050095GrSurfaceProxyView GrTextureProducer::view(GrSamplerState::Filter filter) {
96 auto mipMapped = filter == GrSamplerState::Filter::kMipMap ? GrMipMapped::kYes
97 : GrMipMapped::kNo;
98 return this->view(mipMapped);
Greg Daniel5f4b09d2018-06-12 16:39:59 -040099}