1 | /* |
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 | |
8 | #include "src/gpu/GrTextureProducer.h" |
9 | |
10 | #include "include/gpu/GrRecordingContext.h" |
11 | #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" |
18 | #include "src/gpu/GrTextureProxy.h" |
19 | #include "src/gpu/SkGr.h" |
20 | #include "src/gpu/effects/GrBicubicEffect.h" |
21 | #include "src/gpu/effects/GrTextureEffect.h" |
22 | |
23 | std::unique_ptr<GrFragmentProcessor> GrTextureProducer::createFragmentProcessorForView( |
24 | GrSurfaceProxyView view, |
25 | const SkMatrix& textureMatrix, |
26 | const SkRect* subset, |
27 | const SkRect* domain, |
28 | GrSamplerState samplerState) { |
29 | if (!view) { |
30 | return nullptr; |
31 | } |
32 | SkRect tempSubset; |
33 | |
34 | if (!subset && !view.proxy()->isFullyLazy() && !view.proxy()->isFunctionallyExact()) { |
35 | tempSubset = view.proxy()->getBoundsRect(); |
36 | subset = &tempSubset; |
37 | } |
38 | |
39 | const auto& caps = *fContext->priv().caps(); |
40 | if (subset) { |
41 | if (domain) { |
42 | return GrTextureEffect::MakeSubset(std::move(view), this->alphaType(), textureMatrix, |
43 | samplerState, *subset, *domain, caps); |
44 | } else { |
45 | return GrTextureEffect::MakeSubset(std::move(view), this->alphaType(), textureMatrix, |
46 | samplerState, *subset, caps); |
47 | } |
48 | } else { |
49 | return GrTextureEffect::Make(std::move(view), this->alphaType(), textureMatrix, |
50 | samplerState, caps); |
51 | } |
52 | } |
53 | |
54 | std::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); |
78 | } else { |
79 | return GrBicubicEffect::MakeSubset(std::move(view), this->alphaType(), textureMatrix, |
80 | wrapX, wrapY, *subset, kKernel, kDir, caps); |
81 | } |
82 | } else { |
83 | return GrBicubicEffect::Make(std::move(view), this->alphaType(), textureMatrix, wrapX, |
84 | wrapY, kKernel, kDir, caps); |
85 | } |
86 | } |
87 | |
88 | GrSurfaceProxyView GrTextureProducer::view(GrMipmapped mipMapped) { |
89 | const GrCaps* caps = this->context()->priv().caps(); |
90 | // Sanitize the MIP map request. |
91 | if (mipMapped == GrMipmapped::kYes) { |
92 | if ((this->width() == 1 && this->height() == 1) || !caps->mipmapSupport()) { |
93 | mipMapped = GrMipmapped::kNo; |
94 | } |
95 | } |
96 | 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. |
99 | SkASSERT(!result || mipMapped == GrMipmapped::kNo || |
100 | result.asTextureProxy()->mipmapped() == GrMipmapped::kYes || |
101 | !caps->isFormatCopyable(result.proxy()->backendFormat())); |
102 | return result; |
103 | } |
104 | |