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.
|
|
|
|
*/
|
|
|
|
|
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"
|
|
|
|
#include "src/gpu/GrContextPriv.h"
|
|
|
|
#include "src/gpu/GrDrawingManager.h"
|
|
|
|
#include "src/gpu/GrGpu.h"
|
2019-09-30 16:15:30 +00:00
|
|
|
#include "src/gpu/GrImageInfo.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"
|
2019-05-13 14:40:06 +00:00
|
|
|
#include "src/gpu/SkGr.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/gpu/ProxyUtils.h"
|
2018-03-07 18:01:25 +00:00
|
|
|
|
|
|
|
namespace sk_gpu_test {
|
|
|
|
|
2019-06-24 16:12:36 +00:00
|
|
|
sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext* context,
|
|
|
|
GrRenderable renderable,
|
2019-05-13 14:40:06 +00:00
|
|
|
GrSurfaceOrigin origin,
|
2019-10-21 19:04:52 +00:00
|
|
|
const GrImageInfo& imageInfo,
|
|
|
|
const void* data,
|
|
|
|
size_t rowBytes) {
|
2019-02-22 16:16:30 +00:00
|
|
|
if (context->priv().abandoned()) {
|
2018-06-25 12:53:09 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-05-13 14:40:06 +00:00
|
|
|
const GrCaps* caps = context->priv().caps();
|
|
|
|
|
2019-10-21 19:04:52 +00:00
|
|
|
const GrBackendFormat format = caps->getDefaultBackendFormat(imageInfo.colorType(), renderable);
|
2019-05-13 14:40:06 +00:00
|
|
|
if (!format.isValid()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-03-07 20:20:21 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy;
|
2019-10-21 19:04:52 +00:00
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fConfig = GrColorTypeToPixelConfig(imageInfo.colorType());
|
|
|
|
desc.fWidth = imageInfo.width();
|
|
|
|
desc.fHeight = imageInfo.height();
|
|
|
|
proxy = context->priv().proxyProvider()->createProxy(format, desc, renderable, 1, origin,
|
|
|
|
GrMipMapped::kNo, SkBackingFit::kExact,
|
|
|
|
SkBudgeted::kYes, GrProtected::kNo);
|
|
|
|
if (!proxy) {
|
|
|
|
return nullptr;
|
2018-03-07 18:01:25 +00:00
|
|
|
}
|
2019-10-21 19:04:52 +00:00
|
|
|
auto sContext = context->priv().makeWrappedSurfaceContext(proxy, imageInfo.colorType(),
|
|
|
|
imageInfo.alphaType(),
|
|
|
|
imageInfo.refColorSpace(), nullptr);
|
2018-03-07 18:01:25 +00:00
|
|
|
if (!sContext) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-10-21 19:04:52 +00:00
|
|
|
if (!sContext->writePixels(imageInfo, data, rowBytes, {0, 0}, context)) {
|
2018-03-07 18:01:25 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return proxy;
|
|
|
|
}
|
|
|
|
|
2019-11-21 21:02:34 +00:00
|
|
|
GrProgramInfo* CreateProgramInfo(const GrCaps* caps,
|
|
|
|
SkArenaAlloc* arena,
|
|
|
|
const GrSurfaceProxyView* dstView,
|
|
|
|
GrAppliedClip&& appliedClip,
|
|
|
|
const GrXferProcessor::DstProxyView& dstProxyView,
|
|
|
|
GrGeometryProcessor* geomProc,
|
|
|
|
SkBlendMode blendMode,
|
|
|
|
GrPrimitiveType primitiveType,
|
|
|
|
GrPipeline::InputFlags flags,
|
|
|
|
const GrUserStencilSettings* stencil) {
|
|
|
|
|
|
|
|
GrPipeline::InitArgs initArgs;
|
|
|
|
initArgs.fInputFlags = flags;
|
|
|
|
initArgs.fUserStencil = stencil;
|
|
|
|
initArgs.fCaps = caps;
|
|
|
|
initArgs.fDstProxyView = dstProxyView;
|
|
|
|
initArgs.fOutputSwizzle = dstView->swizzle();
|
|
|
|
|
|
|
|
GrPipeline::FixedDynamicState* fixedDynamicState = nullptr;
|
|
|
|
|
|
|
|
if (appliedClip.scissorState().enabled()) {
|
|
|
|
fixedDynamicState = arena->make<GrPipeline::FixedDynamicState>(
|
|
|
|
appliedClip.scissorState().rect());
|
|
|
|
}
|
|
|
|
|
|
|
|
GrProcessorSet processors = GrProcessorSet(blendMode);
|
|
|
|
|
|
|
|
SkPMColor4f analysisColor = { 0, 0, 0, 1 }; // opaque black
|
|
|
|
|
|
|
|
SkDEBUGCODE(auto analysis =) processors.finalize(analysisColor,
|
|
|
|
GrProcessorAnalysisCoverage::kNone,
|
|
|
|
&appliedClip, stencil, false,
|
|
|
|
*caps, GrClampType::kAuto, &analysisColor);
|
|
|
|
SkASSERT(!analysis.requiresDstTexture());
|
|
|
|
|
|
|
|
GrPipeline* pipeline = arena->make<GrPipeline>(initArgs,
|
|
|
|
std::move(processors),
|
|
|
|
std::move(appliedClip));
|
|
|
|
|
|
|
|
GrRenderTargetProxy* dstProxy = dstView->asRenderTargetProxy();
|
|
|
|
return arena->make<GrProgramInfo>(dstProxy->numSamples(),
|
2019-11-26 14:38:55 +00:00
|
|
|
dstProxy->numStencilSamples(),
|
|
|
|
dstProxy->backendFormat(),
|
|
|
|
dstView->origin(),
|
|
|
|
pipeline,
|
|
|
|
geomProc,
|
|
|
|
fixedDynamicState,
|
|
|
|
nullptr, 0,
|
|
|
|
primitiveType);
|
2019-11-21 21:02:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-07 18:01:25 +00:00
|
|
|
} // namespace sk_gpu_test
|