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