Reland "Migrate MakeCrossContextFromPixmap to GrDirectContext"
This reverts commitae04cc9099
. Reason for revert: Flutter g3 roll complete Original change's description: > Revert "Migrate MakeCrossContextFromPixmap to GrDirectContext" > > This reverts commit066f7d6b1a
. > > Reason for revert: Cant land until flutter PR 20235 reaches g3 > > Original change's description: > > Migrate MakeCrossContextFromPixmap to GrDirectContext > > > > This function isn't used by Chrome so we migrate directly. > > Flutter migration is at https://github.com/flutter/engine/pull/20235 > > > > Bug: skia:104662 > > Change-Id: I9d875acdbd162f50a6d86b3a4cae3f400e4dd38f > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/305180 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: I100a87075ffdf5c0cda78c95f1cfe3310f97630e > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:104662 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/308501 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com # Not skipping CQ checks because original CL landed > 1 day ago. Bug: skia:104662 Change-Id: I32e36aa1c70902296e7f28d0f8b52d4e55b264a4 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309320 Reviewed-by: Adlai Holler <adlai@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Adlai Holler <adlai@google.com>
This commit is contained in:
parent
ba1879d9f1
commit
c41ae2a3cf
@ -4,10 +4,13 @@
|
||||
// HASH=45bca8747b8f49b5be34b520897ef048
|
||||
REG_FIDDLE(Image_MakeCrossContextFromPixmap, 256, 64, false, 4) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
GrContext* context = canvas->getGrContext();
|
||||
auto dContext = GrAsDirectContext(canvas->recordingContext());
|
||||
if (!dContext) {
|
||||
return;
|
||||
}
|
||||
SkPixmap pixmap;
|
||||
if (source.peekPixels(&pixmap)) {
|
||||
sk_sp<SkImage> image = SkImage::MakeCrossContextFromPixmap(context, pixmap, false);
|
||||
sk_sp<SkImage> image = SkImage::MakeCrossContextFromPixmap(dContext, pixmap, false);
|
||||
canvas->drawImage(image, 0, 0);
|
||||
}
|
||||
}
|
||||
|
@ -32,8 +32,8 @@ DEF_SIMPLE_GPU_GM_CAN_FAIL(cross_context_image, context, rtc, canvas, errorMsg,
|
||||
return skiagm::DrawResult::kFail;
|
||||
}
|
||||
|
||||
auto direct = context->asDirectContext();
|
||||
if (!direct) {
|
||||
auto dContext = context->asDirectContext();
|
||||
if (!dContext) {
|
||||
*errorMsg = "CrossContext image creation requires a direct context.";
|
||||
return skiagm::DrawResult::kSkip;
|
||||
}
|
||||
@ -46,8 +46,8 @@ DEF_SIMPLE_GPU_GM_CAN_FAIL(cross_context_image, context, rtc, canvas, errorMsg,
|
||||
SkAssertResult(images[0]->asLegacyBitmap(&bmp) &&
|
||||
bmp.peekPixels(&pixmap));
|
||||
|
||||
images[1] = SkImage::MakeCrossContextFromPixmap(direct, pixmap, false);
|
||||
images[2] = SkImage::MakeCrossContextFromPixmap(direct, pixmap, true);
|
||||
images[1] = SkImage::MakeCrossContextFromPixmap(dContext, pixmap, false);
|
||||
images[2] = SkImage::MakeCrossContextFromPixmap(dContext, pixmap, true);
|
||||
|
||||
canvas->translate(10, 10);
|
||||
|
||||
@ -57,7 +57,8 @@ DEF_SIMPLE_GPU_GM_CAN_FAIL(cross_context_image, context, rtc, canvas, errorMsg,
|
||||
canvas->drawImage(images[i], 0, 0);
|
||||
canvas->translate(0, 256 + 10);
|
||||
|
||||
canvas->drawImage(images[i]->makeSubset(SkIRect::MakeXYWH(64, 64, 128, 128), direct), 0, 0);
|
||||
canvas->drawImage(images[i]->makeSubset(SkIRect::MakeXYWH(64, 64, 128, 128), dContext),
|
||||
0, 0);
|
||||
canvas->translate(128, 0);
|
||||
|
||||
SkPaint paint;
|
||||
|
@ -385,7 +385,8 @@ public:
|
||||
@param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary
|
||||
@return created SkImage, or nullptr
|
||||
*/
|
||||
static sk_sp<SkImage> MakeCrossContextFromPixmap(GrContext* context, const SkPixmap& pixmap,
|
||||
static sk_sp<SkImage> MakeCrossContextFromPixmap(GrDirectContext* context,
|
||||
const SkPixmap& pixmap,
|
||||
bool buildMips,
|
||||
bool limitToMaxTextureSize = false);
|
||||
|
||||
|
@ -586,29 +586,22 @@ sk_sp<SkImage> SkImage_Gpu::MakePromiseTexture(GrRecordingContext* context,
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
sk_sp<SkImage> SkImage::MakeCrossContextFromPixmap(GrContext* context,
|
||||
sk_sp<SkImage> SkImage::MakeCrossContextFromPixmap(GrDirectContext* dContext,
|
||||
const SkPixmap& originalPixmap, bool buildMips,
|
||||
bool limitToMaxTextureSize) {
|
||||
// Some backends or drivers don't support (safely) moving resources between contexts
|
||||
if (!context || !context->priv().caps()->crossContextTextureSupport()) {
|
||||
return SkImage::MakeRasterCopy(originalPixmap);
|
||||
}
|
||||
|
||||
// If we don't have access to the resource provider and gpu (i.e. in a DDL context) we will not
|
||||
// be able to make everything needed for a GPU CrossContext image. Thus return a raster copy
|
||||
// instead.
|
||||
if (!context->priv().resourceProvider()) {
|
||||
if (!dContext || !dContext->priv().caps()->crossContextTextureSupport()) {
|
||||
return SkImage::MakeRasterCopy(originalPixmap);
|
||||
}
|
||||
|
||||
// If non-power-of-two mipmapping isn't supported, ignore the client's request
|
||||
if (!context->priv().caps()->mipmapSupport()) {
|
||||
if (!dContext->priv().caps()->mipmapSupport()) {
|
||||
buildMips = false;
|
||||
}
|
||||
|
||||
const SkPixmap* pixmap = &originalPixmap;
|
||||
SkAutoPixmapStorage resized;
|
||||
int maxTextureSize = context->priv().caps()->maxTextureSize();
|
||||
int maxTextureSize = dContext->priv().caps()->maxTextureSize();
|
||||
int maxDim = std::max(originalPixmap.width(), originalPixmap.height());
|
||||
if (limitToMaxTextureSize && maxDim > maxTextureSize) {
|
||||
float scale = static_cast<float>(maxTextureSize) / maxDim;
|
||||
@ -623,7 +616,7 @@ sk_sp<SkImage> SkImage::MakeCrossContextFromPixmap(GrContext* context,
|
||||
// Turn the pixmap into a GrTextureProxy
|
||||
SkBitmap bmp;
|
||||
bmp.installPixels(*pixmap);
|
||||
GrBitmapTextureMaker bitmapMaker(context, bmp, GrImageTexGenPolicy::kNew_Uncached_Budgeted);
|
||||
GrBitmapTextureMaker bitmapMaker(dContext, bmp, GrImageTexGenPolicy::kNew_Uncached_Budgeted);
|
||||
GrMipmapped mipMapped = buildMips ? GrMipmapped::kYes : GrMipmapped::kNo;
|
||||
auto view = bitmapMaker.view(mipMapped);
|
||||
if (!view) {
|
||||
@ -633,8 +626,8 @@ sk_sp<SkImage> SkImage::MakeCrossContextFromPixmap(GrContext* context,
|
||||
sk_sp<GrTexture> texture = sk_ref_sp(view.proxy()->peekTexture());
|
||||
|
||||
// Flush any writes or uploads
|
||||
context->priv().flushSurface(view.proxy());
|
||||
GrGpu* gpu = context->priv().getGpu();
|
||||
dContext->priv().flushSurface(view.proxy());
|
||||
GrGpu* gpu = dContext->priv().getGpu();
|
||||
|
||||
std::unique_ptr<GrSemaphore> sema = gpu->prepareTextureForCrossContextUsage(texture.get());
|
||||
|
||||
|
@ -1033,15 +1033,15 @@ DEF_GPUTEST(SkImage_CrossContextGrayAlphaConfigs, reporter, options) {
|
||||
GrContextFactory testFactory(options);
|
||||
GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i);
|
||||
ContextInfo ctxInfo = testFactory.getContextInfo(ctxType);
|
||||
auto ctx = ctxInfo.directContext();
|
||||
if (!ctx || !ctx->priv().caps()->crossContextTextureSupport()) {
|
||||
auto dContext = ctxInfo.directContext();
|
||||
if (!dContext || !dContext->priv().caps()->crossContextTextureSupport()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
sk_sp<SkImage> image = SkImage::MakeCrossContextFromPixmap(ctx, pixmap, false);
|
||||
sk_sp<SkImage> image = SkImage::MakeCrossContextFromPixmap(dContext, pixmap, false);
|
||||
REPORTER_ASSERT(reporter, image);
|
||||
|
||||
GrSurfaceProxyView view = as_IB(image)->refView(ctx, GrMipmapped::kNo);
|
||||
GrSurfaceProxyView view = as_IB(image)->refView(dContext, GrMipmapped::kNo);
|
||||
REPORTER_ASSERT(reporter, view);
|
||||
|
||||
bool expectAlpha = kAlpha_8_SkColorType == ct;
|
||||
|
Loading…
Reference in New Issue
Block a user