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