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 | |
Brian Salomon | dd4087d | 2020-12-23 20:36:44 -0500 | [diff] [blame] | 8 | #include "tools/gpu/ProxyUtils.h" |
| 9 | |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 10 | #include "include/core/SkColor.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/gpu/GrBackendSurface.h" |
Robert Phillips | b7bfbc2 | 2020-07-01 12:55:01 -0400 | [diff] [blame] | 12 | #include "include/gpu/GrDirectContext.h" |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 13 | #include "src/gpu/GrDirectContextPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/GrDrawingManager.h" |
| 15 | #include "src/gpu/GrGpu.h" |
Brian Salomon | dd4087d | 2020-12-23 20:36:44 -0500 | [diff] [blame] | 16 | #include "src/gpu/GrPixmap.h" |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 17 | #include "src/gpu/GrProgramInfo.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "src/gpu/GrProxyProvider.h" |
Robert Phillips | e19babf | 2020-04-06 13:57:30 -0400 | [diff] [blame] | 19 | #include "src/gpu/GrSurfaceContext.h" |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 20 | #include "src/gpu/SkGr.h" |
Robert Phillips | ac6156c | 2020-02-28 16:02:40 -0500 | [diff] [blame] | 21 | #include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h" |
Brian Salomon | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 22 | |
| 23 | namespace sk_gpu_test { |
| 24 | |
Brian Salomon | 652124c | 2020-08-12 14:06:50 -0400 | [diff] [blame] | 25 | GrSurfaceProxyView MakeTextureProxyViewFromData(GrDirectContext* dContext, |
| 26 | GrRenderable renderable, |
| 27 | GrSurfaceOrigin origin, |
Brian Salomon | dd4087d | 2020-12-23 20:36:44 -0500 | [diff] [blame] | 28 | GrPixmap pixmap) { |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 29 | if (dContext->abandoned()) { |
Brian Salomon | 652124c | 2020-08-12 14:06:50 -0400 | [diff] [blame] | 30 | return {}; |
Robert Phillips | 44333c5 | 2020-06-30 13:28:00 -0400 | [diff] [blame] | 31 | } |
| 32 | |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 33 | const GrCaps* caps = dContext->priv().caps(); |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 34 | |
Brian Salomon | dd4087d | 2020-12-23 20:36:44 -0500 | [diff] [blame] | 35 | const GrBackendFormat format = caps->getDefaultBackendFormat(pixmap.colorType(), renderable); |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 36 | if (!format.isValid()) { |
Brian Salomon | 652124c | 2020-08-12 14:06:50 -0400 | [diff] [blame] | 37 | return {}; |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 38 | } |
Brian Salomon | dd4087d | 2020-12-23 20:36:44 -0500 | [diff] [blame] | 39 | GrSwizzle swizzle = caps->getReadSwizzle(format, pixmap.colorType()); |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 40 | |
Brian Salomon | 02bd295 | 2018-03-07 15:20:21 -0500 | [diff] [blame] | 41 | sk_sp<GrTextureProxy> proxy; |
Brian Salomon | dd4087d | 2020-12-23 20:36:44 -0500 | [diff] [blame] | 42 | proxy = dContext->priv().proxyProvider()->createProxy(format, |
| 43 | pixmap.dimensions(), |
| 44 | renderable, |
| 45 | /*sample count*/ 1, |
| 46 | GrMipmapped::kNo, |
| 47 | SkBackingFit::kExact, |
| 48 | SkBudgeted::kYes, |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 49 | GrProtected::kNo); |
Brian Salomon | 4eda710 | 2019-10-21 15:04:52 -0400 | [diff] [blame] | 50 | if (!proxy) { |
Brian Salomon | 652124c | 2020-08-12 14:06:50 -0400 | [diff] [blame] | 51 | return {}; |
Brian Salomon | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 52 | } |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 53 | GrSurfaceProxyView view(proxy, origin, swizzle); |
Brian Salomon | dd4087d | 2020-12-23 20:36:44 -0500 | [diff] [blame] | 54 | auto sContext = GrSurfaceContext::Make(dContext, std::move(view), pixmap.colorInfo()); |
Brian Salomon | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 55 | if (!sContext) { |
Brian Salomon | 652124c | 2020-08-12 14:06:50 -0400 | [diff] [blame] | 56 | return {}; |
Brian Salomon | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 57 | } |
Brian Salomon | dd4087d | 2020-12-23 20:36:44 -0500 | [diff] [blame] | 58 | if (!sContext->writePixels(dContext, pixmap, {0, 0})) { |
Brian Salomon | 652124c | 2020-08-12 14:06:50 -0400 | [diff] [blame] | 59 | return {}; |
Brian Salomon | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 60 | } |
Brian Salomon | 652124c | 2020-08-12 14:06:50 -0400 | [diff] [blame] | 61 | return sContext->readSurfaceView(); |
Brian Salomon | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 62 | } |
| 63 | |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 64 | GrProgramInfo* CreateProgramInfo(const GrCaps* caps, |
| 65 | SkArenaAlloc* arena, |
Adlai Holler | e2296f7 | 2020-11-19 13:41:26 -0500 | [diff] [blame] | 66 | const GrSurfaceProxyView& writeView, |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 67 | GrAppliedClip&& appliedClip, |
| 68 | const GrXferProcessor::DstProxyView& dstProxyView, |
| 69 | GrGeometryProcessor* geomProc, |
| 70 | SkBlendMode blendMode, |
| 71 | GrPrimitiveType primitiveType, |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 72 | GrXferBarrierFlags renderPassXferBarriers, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 73 | GrLoadOp colorLoadOp, |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 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), |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 90 | primitiveType, renderPassXferBarriers, |
| 91 | colorLoadOp, flags, stencilSettings); |
Robert Phillips | 34cea00 | 2019-11-21 16:02:34 -0500 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | |
Brian Salomon | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 95 | } // namespace sk_gpu_test |