skia2/tools/gpu/ProxyUtils.cpp
Greg Daniel d358cbebd4 Add support for plumbing GrDstSampleType through Ops and Pipeline creation.
This CL adds a new type GrDstSampleType to say how we will sample the dst.

We add tracking of the GrDstSampleType in the recording of GrOps and
then during execution passing the information along to the GrPipeline.

In general the tracking of GrDstSampleType is a global state of a GrOpsTask
so it is kept separate fro the DstProxyView which is more specific to a
single Op on the GrOpsTask.

Bug: skia:10409
Change-Id: Ie843c31f2e48a887daf96cee99ed159b196cb545
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/315645
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
2020-09-11 14:42:34 +00:00

93 lines
3.9 KiB
C++

/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "include/core/SkColor.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrDirectContext.h"
#include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrDrawingManager.h"
#include "src/gpu/GrGpu.h"
#include "src/gpu/GrImageInfo.h"
#include "src/gpu/GrProgramInfo.h"
#include "src/gpu/GrProxyProvider.h"
#include "src/gpu/GrSurfaceContext.h"
#include "src/gpu/SkGr.h"
#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h"
#include "tools/gpu/ProxyUtils.h"
namespace sk_gpu_test {
GrSurfaceProxyView MakeTextureProxyViewFromData(GrDirectContext* dContext,
GrRenderable renderable,
GrSurfaceOrigin origin,
const GrImageInfo& imageInfo,
const void* data,
size_t rowBytes) {
if (dContext->abandoned()) {
return {};
}
const GrCaps* caps = dContext->priv().caps();
const GrBackendFormat format = caps->getDefaultBackendFormat(imageInfo.colorType(), renderable);
if (!format.isValid()) {
return {};
}
GrSwizzle swizzle = caps->getReadSwizzle(format, imageInfo.colorType());
sk_sp<GrTextureProxy> proxy;
proxy = dContext->priv().proxyProvider()->createProxy(format, imageInfo.dimensions(),
renderable, 1, GrMipmapped::kNo,
SkBackingFit::kExact, SkBudgeted::kYes,
GrProtected::kNo);
if (!proxy) {
return {};
}
GrSurfaceProxyView view(proxy, origin, swizzle);
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), imageInfo.colorType(),
imageInfo.alphaType(), imageInfo.refColorSpace());
if (!sContext) {
return {};
}
if (!sContext->writePixels(dContext, imageInfo, data, rowBytes, {0, 0})) {
return {};
}
return sContext->readSurfaceView();
}
GrProgramInfo* CreateProgramInfo(const GrCaps* caps,
SkArenaAlloc* arena,
const GrSurfaceProxyView* writeView,
GrAppliedClip&& appliedClip,
const GrXferProcessor::DstProxyView& dstProxyView,
GrGeometryProcessor* geomProc,
SkBlendMode blendMode,
GrPrimitiveType primitiveType,
GrXferBarrierFlags renderPassXferBarriers,
GrPipeline::InputFlags flags,
const GrUserStencilSettings* stencilSettings) {
GrProcessorSet processors = GrProcessorSet(blendMode);
SkPMColor4f analysisColor = { 0, 0, 0, 1 }; // opaque black
SkDEBUGCODE(auto analysis =) processors.finalize(analysisColor,
GrProcessorAnalysisCoverage::kSingleChannel,
&appliedClip, stencilSettings, false,
*caps, GrClampType::kAuto, &analysisColor);
SkASSERT(!analysis.requiresDstTexture());
return GrSimpleMeshDrawOpHelper::CreateProgramInfo(caps, arena, writeView,
std::move(appliedClip), dstProxyView,
geomProc, std::move(processors),
primitiveType, renderPassXferBarriers, flags,
stencilSettings);
}
} // namespace sk_gpu_test