2018-03-07 18:01:25 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2020-12-24 01:36:44 +00:00
|
|
|
#include "tools/gpu/ProxyUtils.h"
|
|
|
|
|
2019-11-21 21:02:34 +00:00
|
|
|
#include "include/core/SkColor.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrBackendSurface.h"
|
2020-07-01 16:55:01 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2021-02-23 15:45:39 +00:00
|
|
|
#include "include/private/GrImageContext.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrDrawingManager.h"
|
|
|
|
#include "src/gpu/GrGpu.h"
|
2021-02-23 15:45:39 +00:00
|
|
|
#include "src/gpu/GrImageContextPriv.h"
|
2020-12-24 01:36:44 +00:00
|
|
|
#include "src/gpu/GrPixmap.h"
|
2019-11-21 21:02:34 +00:00
|
|
|
#include "src/gpu/GrProgramInfo.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrProxyProvider.h"
|
2020-04-06 17:57:30 +00:00
|
|
|
#include "src/gpu/GrSurfaceContext.h"
|
2019-05-13 14:40:06 +00:00
|
|
|
#include "src/gpu/SkGr.h"
|
2020-02-28 21:02:40 +00:00
|
|
|
#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h"
|
2021-02-23 15:45:39 +00:00
|
|
|
#include "src/image/SkImage_Base.h"
|
2018-03-07 18:01:25 +00:00
|
|
|
|
|
|
|
namespace sk_gpu_test {
|
|
|
|
|
2021-02-23 15:45:39 +00:00
|
|
|
GrTextureProxy* GetTextureImageProxy(SkImage* image, GrRecordingContext* rContext) {
|
|
|
|
if (!image->isTextureBacked() || as_IB(image)->isYUVA()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (!rContext) {
|
|
|
|
// If the image is backed by a recording context we'll use that.
|
|
|
|
GrImageContext* iContext = as_IB(image)->context();
|
|
|
|
SkASSERT(iContext);
|
|
|
|
rContext = iContext->priv().asRecordingContext();
|
|
|
|
if (!rContext) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto [view, ct] = as_IB(image)->asView(rContext, GrMipmapped::kNo);
|
|
|
|
if (!view) {
|
|
|
|
// With the above checks we expect this to succeed unless there is a context mismatch.
|
|
|
|
SkASSERT(!image->isValid(rContext));
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
GrSurfaceProxy* proxy = view.proxy();
|
|
|
|
SkASSERT(proxy->asTextureProxy());
|
|
|
|
return proxy->asTextureProxy();
|
|
|
|
}
|
|
|
|
|
2020-08-12 18:06:50 +00:00
|
|
|
GrSurfaceProxyView MakeTextureProxyViewFromData(GrDirectContext* dContext,
|
|
|
|
GrRenderable renderable,
|
|
|
|
GrSurfaceOrigin origin,
|
2021-03-30 20:14:37 +00:00
|
|
|
GrCPixmap pixmap) {
|
2020-08-11 16:02:22 +00:00
|
|
|
if (dContext->abandoned()) {
|
2020-08-12 18:06:50 +00:00
|
|
|
return {};
|
2020-06-30 17:28:00 +00:00
|
|
|
}
|
|
|
|
|
2020-08-11 16:02:22 +00:00
|
|
|
const GrCaps* caps = dContext->priv().caps();
|
2019-05-13 14:40:06 +00:00
|
|
|
|
2020-12-24 01:36:44 +00:00
|
|
|
const GrBackendFormat format = caps->getDefaultBackendFormat(pixmap.colorType(), renderable);
|
2019-05-13 14:40:06 +00:00
|
|
|
if (!format.isValid()) {
|
2020-08-12 18:06:50 +00:00
|
|
|
return {};
|
2019-05-13 14:40:06 +00:00
|
|
|
}
|
2020-12-24 01:36:44 +00:00
|
|
|
GrSwizzle swizzle = caps->getReadSwizzle(format, pixmap.colorType());
|
2019-05-13 14:40:06 +00:00
|
|
|
|
2018-03-07 20:20:21 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy;
|
2020-12-24 01:36:44 +00:00
|
|
|
proxy = dContext->priv().proxyProvider()->createProxy(format,
|
|
|
|
pixmap.dimensions(),
|
|
|
|
renderable,
|
|
|
|
/*sample count*/ 1,
|
|
|
|
GrMipmapped::kNo,
|
|
|
|
SkBackingFit::kExact,
|
|
|
|
SkBudgeted::kYes,
|
2020-08-11 16:02:22 +00:00
|
|
|
GrProtected::kNo);
|
2019-10-21 19:04:52 +00:00
|
|
|
if (!proxy) {
|
2020-08-12 18:06:50 +00:00
|
|
|
return {};
|
2018-03-07 18:01:25 +00:00
|
|
|
}
|
2020-01-14 14:56:04 +00:00
|
|
|
GrSurfaceProxyView view(proxy, origin, swizzle);
|
2020-12-24 01:36:44 +00:00
|
|
|
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), pixmap.colorInfo());
|
2018-03-07 18:01:25 +00:00
|
|
|
if (!sContext) {
|
2020-08-12 18:06:50 +00:00
|
|
|
return {};
|
2018-03-07 18:01:25 +00:00
|
|
|
}
|
2020-12-24 01:36:44 +00:00
|
|
|
if (!sContext->writePixels(dContext, pixmap, {0, 0})) {
|
2020-08-12 18:06:50 +00:00
|
|
|
return {};
|
2018-03-07 18:01:25 +00:00
|
|
|
}
|
2020-08-12 18:06:50 +00:00
|
|
|
return sContext->readSurfaceView();
|
2018-03-07 18:01:25 +00:00
|
|
|
}
|
|
|
|
|
2019-11-21 21:02:34 +00:00
|
|
|
GrProgramInfo* CreateProgramInfo(const GrCaps* caps,
|
|
|
|
SkArenaAlloc* arena,
|
2020-11-19 18:41:26 +00:00
|
|
|
const GrSurfaceProxyView& writeView,
|
2019-11-21 21:02:34 +00:00
|
|
|
GrAppliedClip&& appliedClip,
|
|
|
|
const GrXferProcessor::DstProxyView& dstProxyView,
|
|
|
|
GrGeometryProcessor* geomProc,
|
|
|
|
SkBlendMode blendMode,
|
|
|
|
GrPrimitiveType primitiveType,
|
2020-09-11 13:33:54 +00:00
|
|
|
GrXferBarrierFlags renderPassXferBarriers,
|
2020-11-20 15:22:43 +00:00
|
|
|
GrLoadOp colorLoadOp,
|
2019-11-21 21:02:34 +00:00
|
|
|
GrPipeline::InputFlags flags,
|
2020-02-28 21:02:40 +00:00
|
|
|
const GrUserStencilSettings* stencilSettings) {
|
2019-11-21 21:02:34 +00:00
|
|
|
|
|
|
|
GrProcessorSet processors = GrProcessorSet(blendMode);
|
|
|
|
|
|
|
|
SkPMColor4f analysisColor = { 0, 0, 0, 1 }; // opaque black
|
|
|
|
|
|
|
|
SkDEBUGCODE(auto analysis =) processors.finalize(analysisColor,
|
2020-01-08 18:39:16 +00:00
|
|
|
GrProcessorAnalysisCoverage::kSingleChannel,
|
2021-04-22 18:57:28 +00:00
|
|
|
&appliedClip, stencilSettings, *caps,
|
|
|
|
GrClampType::kAuto, &analysisColor);
|
2019-11-21 21:02:34 +00:00
|
|
|
SkASSERT(!analysis.requiresDstTexture());
|
|
|
|
|
2020-04-01 20:22:00 +00:00
|
|
|
return GrSimpleMeshDrawOpHelper::CreateProgramInfo(caps, arena, writeView,
|
2020-02-28 21:02:40 +00:00
|
|
|
std::move(appliedClip), dstProxyView,
|
|
|
|
geomProc, std::move(processors),
|
2020-11-20 15:22:43 +00:00
|
|
|
primitiveType, renderPassXferBarriers,
|
|
|
|
colorLoadOp, flags, stencilSettings);
|
2019-11-21 21:02:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-07 18:01:25 +00:00
|
|
|
} // namespace sk_gpu_test
|