skia2/docs/examples/Image_MakeFromAdoptedTexture.cpp
Adlai Holler e34b282ed0 Migrate MakeFromAdoptedTexture to GrDirectContext
More recontexting for SkImage. Chrome flag in CL 2323135.
Flutter migration landed in https://github.com/flutter/engine/pull/19962

Bug: skia:104662
Change-Id: Id725eb130310639457ba90f378ecdb334dd5f3cd
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/306182
Auto-Submit: Adlai Holler <adlai@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
2020-07-29 20:15:00 +00:00

28 lines
1.1 KiB
C++

// Copyright 2019 Google LLC.
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#include "tools/fiddle/examples.h"
// HASH=b034517e39394b7543f06ec885e36d7d
REG_FIDDLE(Image_MakeFromAdoptedTexture, 256, 256, false, 5) {
void draw(SkCanvas* canvas) {
GrDirectContext* dContext = GrAsDirectContext(canvas->recordingContext());
// Example does not support DDL.
if (!dContext) {
return;
}
canvas->scale(.5f, .5f);
canvas->clear(0x7f3f5f7f);
int x = 0, y = 0;
for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) {
for (auto alpha : { kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType } ) {
sk_sp<SkImage> image = SkImage::MakeFromAdoptedTexture(dContext,
backEndTexture, origin,
kRGBA_8888_SkColorType, alpha);
canvas->drawImage(image, x, y);
x += 160;
}
x -= 160 * 3;
y += 256;
}
}
} // END FIDDLE