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"
|
2020-07-01 16:55:01 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#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"
|
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"
|
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 {
|
|
|
|
|
2020-08-10 19:43:05 +00:00
|
|
|
sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrDirectContext* dContext,
|
2019-06-24 16:12:36 +00:00
|
|
|
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) {
|
2020-08-10 19:43:05 +00:00
|
|
|
if (dContext->abandoned()) {
|
2020-06-30 17:28:00 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-08-10 19:43:05 +00:00
|
|
|
const GrCaps* caps = dContext->priv().caps();
|
2019-05-13 14:40:06 +00:00
|
|
|
|
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;
|
|
|
|
}
|
2020-01-21 19:29:57 +00:00
|
|
|
GrSwizzle swizzle = caps->getReadSwizzle(format, imageInfo.colorType());
|
2019-05-13 14:40:06 +00:00
|
|
|
|
2018-03-07 20:20:21 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy;
|
2020-08-10 19:43:05 +00:00
|
|
|
proxy = dContext->priv().proxyProvider()->createProxy(format, imageInfo.dimensions(),
|
|
|
|
renderable, 1, GrMipmapped::kNo,
|
|
|
|
SkBackingFit::kExact, SkBudgeted::kYes,
|
|
|
|
GrProtected::kNo);
|
2019-10-21 19:04:52 +00:00
|
|
|
if (!proxy) {
|
|
|
|
return nullptr;
|
2018-03-07 18:01:25 +00:00
|
|
|
}
|
2020-01-14 14:56:04 +00:00
|
|
|
GrSurfaceProxyView view(proxy, origin, swizzle);
|
2020-08-10 19:43:05 +00:00
|
|
|
auto sContext = GrSurfaceContext::Make(dContext, std::move(view), imageInfo.colorType(),
|
2019-12-19 21:41:40 +00:00
|
|
|
imageInfo.alphaType(), imageInfo.refColorSpace());
|
2018-03-07 18:01:25 +00:00
|
|
|
if (!sContext) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2020-08-10 19:43:05 +00:00
|
|
|
if (!sContext->writePixels(dContext, imageInfo, data, rowBytes, {0, 0})) {
|
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,
|
2020-04-01 20:22:00 +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,
|
|
|
|
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,
|
2020-02-28 21:02:40 +00:00
|
|
|
&appliedClip, stencilSettings, false,
|
2019-11-21 21:02:34 +00:00
|
|
|
*caps, GrClampType::kAuto, &analysisColor);
|
|
|
|
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),
|
|
|
|
primitiveType, flags, stencilSettings);
|
2019-11-21 21:02:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-07 18:01:25 +00:00
|
|
|
} // namespace sk_gpu_test
|