blob: 345099a050fa8ca0888a8f3e4327b2fb94e86b5e [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 Reed13711eb2020-07-14 17:16:32 -040011#include "src/core/SkMipmap.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#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 Salomon0ea33072020-07-14 10:43:42 -040023std::unique_ptr<GrFragmentProcessor> GrTextureProducer::createFragmentProcessorForView(
Greg Danielcc104db2020-02-03 14:17:08 -050024 GrSurfaceProxyView view,
Brian Salomonaff329b2017-08-11 09:40:37 -040025 const SkMatrix& textureMatrix,
Brian Salomon0ea33072020-07-14 10:43:42 -040026 const SkRect* subset,
27 const SkRect* domain,
28 GrSamplerState samplerState) {
29 if (!view) {
30 return nullptr;
31 }
Brian Salomonf990b6a2020-07-13 10:44:22 -040032 SkRect tempSubset;
33
Brian Salomon0ea33072020-07-14 10:43:42 -040034 if (!subset && !view.proxy()->isFullyLazy() && !view.proxy()->isFunctionallyExact()) {
Brian Salomonf990b6a2020-07-13 10:44:22 -040035 tempSubset = view.proxy()->getBoundsRect();
36 subset = &tempSubset;
37 }
38
Brian Salomonca6b2f42020-01-24 11:31:21 -050039 const auto& caps = *fContext->priv().caps();
Brian Salomon0ea33072020-07-14 10:43:42 -040040 if (subset) {
41 if (domain) {
42 return GrTextureEffect::MakeSubset(std::move(view), this->alphaType(), textureMatrix,
43 samplerState, *subset, *domain, caps);
Brian Salomonf990b6a2020-07-13 10:44:22 -040044 } else {
Brian Salomon0ea33072020-07-14 10:43:42 -040045 return GrTextureEffect::MakeSubset(std::move(view), this->alphaType(), textureMatrix,
46 samplerState, *subset, caps);
Robert Phillipsb66b42f2017-03-14 08:53:02 -040047 }
48 } else {
Brian Salomon0ea33072020-07-14 10:43:42 -040049 return GrTextureEffect::Make(std::move(view), this->alphaType(), textureMatrix,
50 samplerState, caps);
51 }
52}
53
54std::unique_ptr<GrFragmentProcessor> GrTextureProducer::createBicubicFragmentProcessorForView(
55 GrSurfaceProxyView view,
56 const SkMatrix& textureMatrix,
57 const SkRect* subset,
58 const SkRect* domain,
59 GrSamplerState::WrapMode wrapX,
60 GrSamplerState::WrapMode wrapY) {
61 if (!view) {
62 return nullptr;
63 }
64 SkRect tempSubset;
65
66 if (!subset && !view.proxy()->isFullyLazy() && !view.proxy()->isFunctionallyExact()) {
67 tempSubset = view.proxy()->getBoundsRect();
68 subset = &tempSubset;
69 }
70
71 const auto& caps = *fContext->priv().caps();
72 static constexpr auto kDir = GrBicubicEffect::Direction::kXY;
73 static constexpr auto kKernel = GrBicubicEffect::Kernel::kMitchell;
74 if (subset) {
75 if (domain) {
76 return GrBicubicEffect::MakeSubset(std::move(view), this->alphaType(), textureMatrix,
77 wrapX, wrapY, *subset, *domain, kKernel, kDir, caps);
Robert Phillipsb66b42f2017-03-14 08:53:02 -040078 } else {
Brian Salomon0ea33072020-07-14 10:43:42 -040079 return GrBicubicEffect::MakeSubset(std::move(view), this->alphaType(), textureMatrix,
80 wrapX, wrapY, *subset, kKernel, kDir, caps);
Robert Phillipsb66b42f2017-03-14 08:53:02 -040081 }
Brian Salomon0ea33072020-07-14 10:43:42 -040082 } else {
83 return GrBicubicEffect::Make(std::move(view), this->alphaType(), textureMatrix, wrapX,
84 wrapY, kKernel, kDir, caps);
Robert Phillipsb66b42f2017-03-14 08:53:02 -040085 }
86}
Brian Salomon2a943df2018-05-04 13:43:19 -040087
Brian Salomon7e67dca2020-07-21 09:27:25 -040088GrSurfaceProxyView GrTextureProducer::view(GrMipmapped mipMapped) {
Brian Salomonecbb0fb2020-02-28 18:07:32 -050089 const GrCaps* caps = this->context()->priv().caps();
90 // Sanitize the MIP map request.
Brian Salomon7e67dca2020-07-21 09:27:25 -040091 if (mipMapped == GrMipmapped::kYes) {
Brian Salomon69100f02020-07-21 10:49:25 -040092 if ((this->width() == 1 && this->height() == 1) || !caps->mipmapSupport()) {
Brian Salomon7e67dca2020-07-21 09:27:25 -040093 mipMapped = GrMipmapped::kNo;
Michael Ludwigddeed372019-02-20 16:50:10 -050094 }
95 }
Brian Salomonecbb0fb2020-02-28 18:07:32 -050096 auto result = this->onView(mipMapped);
97 // Check to make sure if we requested MIPs that the returned texture has MIP maps or the format
98 // is not copyable.
Brian Salomon7e67dca2020-07-21 09:27:25 -040099 SkASSERT(!result || mipMapped == GrMipmapped::kNo ||
Brian Salomon8c82a872020-07-21 12:09:58 -0400100 result.asTextureProxy()->mipmapped() == GrMipmapped::kYes ||
Greg Danielcc104db2020-02-03 14:17:08 -0500101 !caps->isFormatCopyable(result.proxy()->backendFormat()));
Brian Salomon2a943df2018-05-04 13:43:19 -0400102 return result;
103}