Brian Salomon | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 8 | #include "include/core/SkColor.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 9 | #include "include/gpu/GrBackendSurface.h" |
Robert Phillips | b7bfbc2 | 2020-07-01 12:55:01 -0400 | [diff] [blame] | 10 | #include "include/gpu/GrDirectContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/gpu/GrContextPriv.h" |
| 12 | #include "src/gpu/GrDrawingManager.h" |
| 13 | #include "src/gpu/GrGpu.h" |
Brian Salomon | f2ebdd9 | 2019-09-30 12:15:30 -0400 | [diff] [blame] | 14 | #include "src/gpu/GrImageInfo.h" |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 15 | #include "src/gpu/GrProgramInfo.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "src/gpu/GrProxyProvider.h" |
Robert Phillips | e19babf | 2020-04-06 13:57:30 -0400 | [diff] [blame] | 17 | #include "src/gpu/GrSurfaceContext.h" |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 18 | #include "src/gpu/SkGr.h" |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 19 | #include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "tools/gpu/ProxyUtils.h" |
Brian Salomon | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 21 | |
| 22 | namespace sk_gpu_test { |
| 23 | |
Adlai Holler | cf0d08e | 2020-08-11 12:36:10 +0000 | [diff] [blame] | 24 | sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrDirectContext* direct, |
Brian Salomon | e7499c7 | 2019-06-24 12:12:36 -0400 | [diff] [blame] | 25 | GrRenderable renderable, |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 26 | GrSurfaceOrigin origin, |
Brian Salomon | 4eda710 | 2019-10-21 15:04:52 -0400 | [diff] [blame] | 27 | const GrImageInfo& imageInfo, |
| 28 | const void* data, |
| 29 | size_t rowBytes) { |
Adlai Holler | cf0d08e | 2020-08-11 12:36:10 +0000 | [diff] [blame] | 30 | if (direct->abandoned()) { |
Robert Phillips | 44333c5 | 2020-06-30 13:28:00 -0400 | [diff] [blame] | 31 | return nullptr; |
| 32 | } |
| 33 | |
Adlai Holler | cf0d08e | 2020-08-11 12:36:10 +0000 | [diff] [blame] | 34 | const GrCaps* caps = direct->priv().caps(); |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 35 | |
Brian Salomon | 4eda710 | 2019-10-21 15:04:52 -0400 | [diff] [blame] | 36 | const GrBackendFormat format = caps->getDefaultBackendFormat(imageInfo.colorType(), renderable); |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 37 | if (!format.isValid()) { |
| 38 | return nullptr; |
| 39 | } |
Greg Daniel | 47c20e8 | 2020-01-21 14:29:57 -0500 | [diff] [blame] | 40 | GrSwizzle swizzle = caps->getReadSwizzle(format, imageInfo.colorType()); |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 41 | |
Brian Salomon | 02bd295 | 2018-03-07 15:20:21 -0500 | [diff] [blame] | 42 | sk_sp<GrTextureProxy> proxy; |
Adlai Holler | cf0d08e | 2020-08-11 12:36:10 +0000 | [diff] [blame] | 43 | proxy = direct->priv().proxyProvider()->createProxy(format, imageInfo.dimensions(), renderable, |
| 44 | 1, GrMipmapped::kNo, SkBackingFit::kExact, |
| 45 | SkBudgeted::kYes, GrProtected::kNo); |
Brian Salomon | 4eda710 | 2019-10-21 15:04:52 -0400 | [diff] [blame] | 46 | if (!proxy) { |
| 47 | return nullptr; |
Brian Salomon | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 48 | } |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 49 | GrSurfaceProxyView view(proxy, origin, swizzle); |
Adlai Holler | cf0d08e | 2020-08-11 12:36:10 +0000 | [diff] [blame] | 50 | auto sContext = GrSurfaceContext::Make(direct, std::move(view), imageInfo.colorType(), |
Greg Daniel | bfa19c4 | 2019-12-19 16:41:40 -0500 | [diff] [blame] | 51 | imageInfo.alphaType(), imageInfo.refColorSpace()); |
Brian Salomon | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 52 | if (!sContext) { |
| 53 | return nullptr; |
| 54 | } |
Adlai Holler | cf0d08e | 2020-08-11 12:36:10 +0000 | [diff] [blame] | 55 | if (!sContext->writePixels(imageInfo, data, rowBytes, {0, 0}, direct)) { |
Brian Salomon | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 56 | return nullptr; |
| 57 | } |
| 58 | return proxy; |
| 59 | } |
| 60 | |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 61 | GrProgramInfo* CreateProgramInfo(const GrCaps* caps, |
| 62 | SkArenaAlloc* arena, |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 63 | const GrSurfaceProxyView* writeView, |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 64 | GrAppliedClip&& appliedClip, |
| 65 | const GrXferProcessor::DstProxyView& dstProxyView, |
| 66 | GrGeometryProcessor* geomProc, |
| 67 | SkBlendMode blendMode, |
| 68 | GrPrimitiveType primitiveType, |
| 69 | GrPipeline::InputFlags flags, |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 70 | const GrUserStencilSettings* stencilSettings) { |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 71 | |
| 72 | GrProcessorSet processors = GrProcessorSet(blendMode); |
| 73 | |
| 74 | SkPMColor4f analysisColor = { 0, 0, 0, 1 }; // opaque black |
| 75 | |
| 76 | SkDEBUGCODE(auto analysis =) processors.finalize(analysisColor, |
Greg Daniel | f6d60d3 | 2020-01-08 13:39:16 -0500 | [diff] [blame] | 77 | GrProcessorAnalysisCoverage::kSingleChannel, |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 78 | &appliedClip, stencilSettings, false, |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 79 | *caps, GrClampType::kAuto, &analysisColor); |
| 80 | SkASSERT(!analysis.requiresDstTexture()); |
| 81 | |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 82 | return GrSimpleMeshDrawOpHelper::CreateProgramInfo(caps, arena, writeView, |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 83 | std::move(appliedClip), dstProxyView, |
| 84 | geomProc, std::move(processors), |
| 85 | primitiveType, flags, stencilSettings); |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | |
Brian Salomon | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 89 | } // namespace sk_gpu_test |