2015-08-13 16:37:45 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkImage.h"
|
2015-08-13 20:32:39 +00:00
|
|
|
#include "SkImageCacherator.h"
|
2017-02-15 20:14:16 +00:00
|
|
|
#include "SkMakeUnique.h"
|
2015-08-13 16:37:45 +00:00
|
|
|
#include "SkPictureRecorder.h"
|
2015-08-13 20:32:39 +00:00
|
|
|
#include "SkSurface.h"
|
2015-08-13 16:37:45 +00:00
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
#include "GrContext.h"
|
2016-12-15 14:23:05 +00:00
|
|
|
#include "GrContextPriv.h"
|
|
|
|
#include "GrSurfaceContext.h"
|
|
|
|
#include "GrSurfaceProxy.h"
|
2015-08-13 20:32:39 +00:00
|
|
|
#include "GrTexture.h"
|
2016-12-15 14:23:05 +00:00
|
|
|
#include "GrTextureProxy.h"
|
2015-08-13 20:32:39 +00:00
|
|
|
#include "../src/image/SkImage_Gpu.h"
|
2015-08-13 16:37:45 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static void draw_something(SkCanvas* canvas, const SkRect& bounds) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(10);
|
|
|
|
canvas->drawRect(bounds, paint);
|
|
|
|
paint.setStyle(SkPaint::kFill_Style);
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
canvas->drawOval(bounds, paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Exercise drawing pictures inside an image, showing that the image version is pixelated
|
|
|
|
* (correctly) when it is inside an image.
|
|
|
|
*/
|
|
|
|
class ImagePictGM : public skiagm::GM {
|
2016-03-18 14:25:55 +00:00
|
|
|
sk_sp<SkPicture> fPicture;
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> fImage0;
|
|
|
|
sk_sp<SkImage> fImage1;
|
2015-08-13 16:37:45 +00:00
|
|
|
public:
|
|
|
|
ImagePictGM() {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkString onShortName() override {
|
|
|
|
return SkString("image-picture");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override {
|
|
|
|
return SkISize::Make(850, 450);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onOnceBeforeDraw() override {
|
|
|
|
const SkRect bounds = SkRect::MakeXYWH(100, 100, 100, 100);
|
|
|
|
SkPictureRecorder recorder;
|
|
|
|
draw_something(recorder.beginRecording(bounds), bounds);
|
2016-03-18 14:25:55 +00:00
|
|
|
fPicture = recorder.finishRecordingAsPicture();
|
2015-08-13 16:37:45 +00:00
|
|
|
|
|
|
|
// extract enough just for the oval.
|
|
|
|
const SkISize size = SkISize::Make(100, 100);
|
2017-02-07 18:56:11 +00:00
|
|
|
auto srgbColorSpace = SkColorSpace::MakeSRGB();
|
2015-08-13 16:37:45 +00:00
|
|
|
|
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.setTranslate(-100, -100);
|
2017-01-09 17:38:59 +00:00
|
|
|
fImage0 = SkImage::MakeFromPicture(fPicture, size, &matrix, nullptr,
|
|
|
|
SkImage::BitDepth::kU8, srgbColorSpace);
|
2015-08-13 16:37:45 +00:00
|
|
|
matrix.postTranslate(-50, -50);
|
|
|
|
matrix.postRotate(45);
|
|
|
|
matrix.postTranslate(50, 50);
|
2017-01-09 17:38:59 +00:00
|
|
|
fImage1 = SkImage::MakeFromPicture(fPicture, size, &matrix, nullptr,
|
|
|
|
SkImage::BitDepth::kU8, srgbColorSpace);
|
2015-08-13 16:37:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void drawSet(SkCanvas* canvas) const {
|
|
|
|
SkMatrix matrix = SkMatrix::MakeTrans(-100, -100);
|
|
|
|
canvas->drawPicture(fPicture, &matrix, nullptr);
|
2016-03-17 17:51:11 +00:00
|
|
|
canvas->drawImage(fImage0.get(), 150, 0);
|
|
|
|
canvas->drawImage(fImage1.get(), 300, 0);
|
2015-08-13 16:37:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
|
|
canvas->translate(20, 20);
|
|
|
|
|
|
|
|
this->drawSet(canvas);
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(0, 130);
|
|
|
|
canvas->scale(0.25f, 0.25f);
|
|
|
|
this->drawSet(canvas);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(0, 200);
|
|
|
|
canvas->scale(2, 2);
|
|
|
|
this->drawSet(canvas);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef skiagm::GM INHERITED;
|
|
|
|
};
|
|
|
|
DEF_GM( return new ImagePictGM; )
|
|
|
|
|
2015-08-13 20:32:39 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-02-15 20:14:16 +00:00
|
|
|
static std::unique_ptr<SkImageGenerator> make_pic_generator(GrContext*, sk_sp<SkPicture> pic) {
|
2015-08-18 18:16:09 +00:00
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.setTranslate(-100, -100);
|
2017-02-15 20:14:16 +00:00
|
|
|
return SkImageGenerator::MakeFromPicture({ 100, 100 }, std::move(pic), &matrix, nullptr,
|
2017-01-09 17:38:59 +00:00
|
|
|
SkImage::BitDepth::kU8,
|
2017-02-07 18:56:11 +00:00
|
|
|
SkColorSpace::MakeSRGB());
|
2015-08-18 18:16:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class RasterGenerator : public SkImageGenerator {
|
|
|
|
public:
|
2015-09-11 18:47:27 +00:00
|
|
|
RasterGenerator(const SkBitmap& bm) : SkImageGenerator(bm.info()), fBM(bm) {
|
|
|
|
fBM.lockPixels();
|
|
|
|
}
|
2015-08-18 18:16:09 +00:00
|
|
|
protected:
|
|
|
|
bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
|
2015-09-11 18:47:27 +00:00
|
|
|
SkPMColor* ctable, int* ctableCount) override {
|
|
|
|
SkASSERT(fBM.width() == info.width());
|
|
|
|
SkASSERT(fBM.height() == info.height());
|
|
|
|
|
|
|
|
if (info.colorType() == kIndex_8_SkColorType) {
|
|
|
|
if (SkColorTable* ct = fBM.getColorTable()) {
|
|
|
|
if (ctable) {
|
|
|
|
memcpy(ctable, ct->readColors(), ct->count() * sizeof(SkPMColor));
|
|
|
|
}
|
|
|
|
if (ctableCount) {
|
|
|
|
*ctableCount = ct->count();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int y = 0; y < info.height(); ++y) {
|
|
|
|
memcpy(pixels, fBM.getAddr8(0, y), fBM.width());
|
|
|
|
pixels = (char*)pixels + rowBytes;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return fBM.readPixels(info, pixels, rowBytes, 0, 0);
|
|
|
|
}
|
2015-08-18 18:16:09 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
SkBitmap fBM;
|
|
|
|
};
|
2017-02-15 20:14:16 +00:00
|
|
|
static std::unique_ptr<SkImageGenerator> make_ras_generator(GrContext*, sk_sp<SkPicture> pic) {
|
2015-08-18 18:16:09 +00:00
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocN32Pixels(100, 100);
|
|
|
|
SkCanvas canvas(bm);
|
|
|
|
canvas.clear(0);
|
|
|
|
canvas.translate(-100, -100);
|
|
|
|
canvas.drawPicture(pic);
|
2017-02-15 20:14:16 +00:00
|
|
|
return skstd::make_unique<RasterGenerator>(bm);
|
2015-08-18 18:16:09 +00:00
|
|
|
}
|
|
|
|
|
2015-09-11 18:47:27 +00:00
|
|
|
// so we can create a color-table
|
|
|
|
static int find_closest(SkPMColor c, const SkPMColor table[], int count) {
|
|
|
|
const int cr = SkGetPackedR32(c);
|
|
|
|
const int cg = SkGetPackedG32(c);
|
|
|
|
const int cb = SkGetPackedB32(c);
|
|
|
|
|
|
|
|
int minDist = 999999999;
|
|
|
|
int index = 0;
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
int dr = SkAbs32((int)SkGetPackedR32(table[i]) - cr);
|
|
|
|
int dg = SkAbs32((int)SkGetPackedG32(table[i]) - cg);
|
|
|
|
int db = SkAbs32((int)SkGetPackedB32(table[i]) - cb);
|
|
|
|
int dist = dr + dg + db;
|
|
|
|
if (dist < minDist) {
|
|
|
|
minDist = dist;
|
|
|
|
index = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2017-02-15 20:14:16 +00:00
|
|
|
static std::unique_ptr<SkImageGenerator> make_ctable_generator(GrContext*, sk_sp<SkPicture> pic) {
|
2015-09-11 18:47:27 +00:00
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocN32Pixels(100, 100);
|
|
|
|
SkCanvas canvas(bm);
|
|
|
|
canvas.clear(0);
|
|
|
|
canvas.translate(-100, -100);
|
|
|
|
canvas.drawPicture(pic);
|
|
|
|
|
|
|
|
const SkPMColor colors[] = {
|
|
|
|
SkPreMultiplyColor(SK_ColorRED),
|
|
|
|
SkPreMultiplyColor(0),
|
|
|
|
SkPreMultiplyColor(SK_ColorBLUE),
|
|
|
|
};
|
|
|
|
const int count = SK_ARRAY_COUNT(colors);
|
|
|
|
SkImageInfo info = SkImageInfo::Make(100, 100, kIndex_8_SkColorType, kPremul_SkAlphaType);
|
|
|
|
|
|
|
|
SkBitmap bm2;
|
2016-11-04 20:26:16 +00:00
|
|
|
sk_sp<SkColorTable> ct(new SkColorTable(colors, count));
|
|
|
|
bm2.allocPixels(info, nullptr, ct.get());
|
2015-09-11 18:47:27 +00:00
|
|
|
for (int y = 0; y < info.height(); ++y) {
|
|
|
|
for (int x = 0; x < info.width(); ++x) {
|
|
|
|
*bm2.getAddr8(x, y) = find_closest(*bm.getAddr32(x, y), colors, count);
|
|
|
|
}
|
|
|
|
}
|
2017-02-15 20:14:16 +00:00
|
|
|
return skstd::make_unique<RasterGenerator>(bm2);
|
2015-09-11 18:47:27 +00:00
|
|
|
}
|
|
|
|
|
2015-08-18 18:16:09 +00:00
|
|
|
class EmptyGenerator : public SkImageGenerator {
|
|
|
|
public:
|
|
|
|
EmptyGenerator(const SkImageInfo& info) : SkImageGenerator(info) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
class TextureGenerator : public SkImageGenerator {
|
|
|
|
public:
|
2017-02-15 20:14:16 +00:00
|
|
|
TextureGenerator(GrContext* ctx, const SkImageInfo& info, sk_sp<SkPicture> pic)
|
2015-08-18 18:16:09 +00:00
|
|
|
: SkImageGenerator(info)
|
2016-12-15 14:23:05 +00:00
|
|
|
, fCtx(SkRef(ctx)) {
|
|
|
|
|
|
|
|
sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info));
|
2016-05-13 14:25:44 +00:00
|
|
|
if (surface) {
|
|
|
|
surface->getCanvas()->clear(0);
|
|
|
|
surface->getCanvas()->translate(-100, -100);
|
|
|
|
surface->getCanvas()->drawPicture(pic);
|
|
|
|
sk_sp<SkImage> image(surface->makeImageSnapshot());
|
2017-01-31 16:31:39 +00:00
|
|
|
fProxy = as_IB(image)->asTextureProxyRef();
|
2016-05-13 14:25:44 +00:00
|
|
|
}
|
2015-08-18 18:16:09 +00:00
|
|
|
}
|
|
|
|
protected:
|
2017-03-03 16:10:18 +00:00
|
|
|
sk_sp<GrTextureProxy> onGenerateTexture(GrContext* ctx, const SkImageInfo& info,
|
|
|
|
const SkIPoint& origin) override {
|
|
|
|
SkASSERT(ctx);
|
|
|
|
SkASSERT(ctx == fCtx.get());
|
2015-08-18 18:16:09 +00:00
|
|
|
|
2016-12-15 14:23:05 +00:00
|
|
|
if (!fProxy) {
|
2016-05-13 14:25:44 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-12-15 14:23:05 +00:00
|
|
|
if (origin.fX == 0 && origin.fY == 0 &&
|
|
|
|
info.width() == fProxy->width() && info.height() == fProxy->height()) {
|
2017-03-03 16:10:18 +00:00
|
|
|
return fProxy;
|
2016-12-15 14:23:05 +00:00
|
|
|
}
|
|
|
|
|
2015-08-18 18:16:09 +00:00
|
|
|
// need to copy the subset into a new texture
|
2016-12-15 14:23:05 +00:00
|
|
|
GrSurfaceDesc desc = fProxy->desc();
|
2016-12-14 20:42:36 +00:00
|
|
|
desc.fWidth = info.width();
|
|
|
|
desc.fHeight = info.height();
|
2015-08-18 18:16:09 +00:00
|
|
|
|
2016-12-15 14:23:05 +00:00
|
|
|
sk_sp<GrSurfaceContext> dstContext(fCtx->contextPriv().makeDeferredSurfaceContext(
|
|
|
|
desc,
|
|
|
|
SkBackingFit::kExact,
|
|
|
|
SkBudgeted::kNo));
|
|
|
|
if (!dstContext) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dstContext->copy(
|
|
|
|
fProxy.get(),
|
|
|
|
SkIRect::MakeXYWH(origin.x(), origin.y(), info.width(), info.height()),
|
|
|
|
SkIPoint::Make(0, 0))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-03-03 16:10:18 +00:00
|
|
|
return dstContext->asTextureProxyRef();
|
2015-08-18 18:16:09 +00:00
|
|
|
}
|
2017-03-03 16:10:18 +00:00
|
|
|
|
2015-08-18 18:16:09 +00:00
|
|
|
private:
|
2016-12-15 14:23:05 +00:00
|
|
|
sk_sp<GrContext> fCtx;
|
2017-03-03 16:10:18 +00:00
|
|
|
sk_sp<GrTextureProxy> fProxy;
|
2015-08-18 18:16:09 +00:00
|
|
|
};
|
2017-03-03 16:10:18 +00:00
|
|
|
|
2017-02-15 20:14:16 +00:00
|
|
|
static std::unique_ptr<SkImageGenerator> make_tex_generator(GrContext* ctx, sk_sp<SkPicture> pic) {
|
2015-08-18 18:16:09 +00:00
|
|
|
const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
|
|
|
|
|
|
|
|
if (!ctx) {
|
2017-02-15 20:14:16 +00:00
|
|
|
return skstd::make_unique<EmptyGenerator>(info);
|
2015-08-18 18:16:09 +00:00
|
|
|
}
|
2017-02-15 20:14:16 +00:00
|
|
|
return skstd::make_unique<TextureGenerator>(ctx, info, pic);
|
2015-08-18 18:16:09 +00:00
|
|
|
}
|
|
|
|
#endif
|
2015-08-13 20:32:39 +00:00
|
|
|
|
|
|
|
class ImageCacheratorGM : public skiagm::GM {
|
2015-08-18 18:16:09 +00:00
|
|
|
SkString fName;
|
2017-02-15 20:14:16 +00:00
|
|
|
std::unique_ptr<SkImageGenerator> (*fFactory)(GrContext*, sk_sp<SkPicture>);
|
2016-03-18 14:25:55 +00:00
|
|
|
sk_sp<SkPicture> fPicture;
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<SkImageCacherator> fCache;
|
|
|
|
std::unique_ptr<SkImageCacherator> fCacheSubset;
|
2015-08-13 20:32:39 +00:00
|
|
|
|
|
|
|
public:
|
2017-02-15 20:14:16 +00:00
|
|
|
ImageCacheratorGM(const char suffix[],
|
|
|
|
std::unique_ptr<SkImageGenerator> (*factory)(GrContext*, sk_sp<SkPicture>))
|
2015-08-18 18:16:09 +00:00
|
|
|
: fFactory(factory)
|
|
|
|
{
|
|
|
|
fName.printf("image-cacherator-from-%s", suffix);
|
|
|
|
}
|
2015-08-13 20:32:39 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
SkString onShortName() override {
|
2015-08-18 18:16:09 +00:00
|
|
|
return fName;
|
2015-08-13 20:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override {
|
2015-08-19 13:07:29 +00:00
|
|
|
return SkISize::Make(960, 450);
|
2015-08-13 20:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void onOnceBeforeDraw() override {
|
|
|
|
const SkRect bounds = SkRect::MakeXYWH(100, 100, 100, 100);
|
|
|
|
SkPictureRecorder recorder;
|
|
|
|
draw_something(recorder.beginRecording(bounds), bounds);
|
2016-03-18 14:25:55 +00:00
|
|
|
fPicture = recorder.finishRecordingAsPicture();
|
2015-08-18 18:16:09 +00:00
|
|
|
}
|
2015-08-13 20:32:39 +00:00
|
|
|
|
2015-08-18 18:16:09 +00:00
|
|
|
void makeCaches(GrContext* ctx) {
|
2017-02-15 20:14:16 +00:00
|
|
|
auto gen = fFactory(ctx, fPicture);
|
2015-08-18 18:16:09 +00:00
|
|
|
SkDEBUGCODE(const uint32_t genID = gen->uniqueID();)
|
2017-02-15 20:14:16 +00:00
|
|
|
fCache.reset(SkImageCacherator::NewFromGenerator(std::move(gen)));
|
2015-08-18 18:16:09 +00:00
|
|
|
|
|
|
|
const SkIRect subset = SkIRect::MakeLTRB(50, 50, 100, 100);
|
|
|
|
|
2017-02-15 20:14:16 +00:00
|
|
|
gen = fFactory(ctx, fPicture);
|
2015-08-18 18:16:09 +00:00
|
|
|
SkDEBUGCODE(const uint32_t genSubsetID = gen->uniqueID();)
|
2017-02-15 20:14:16 +00:00
|
|
|
fCacheSubset.reset(SkImageCacherator::NewFromGenerator(std::move(gen), &subset));
|
2015-08-18 18:16:09 +00:00
|
|
|
|
|
|
|
// whole caches should have the same ID as the generator. Subsets should be diff
|
|
|
|
SkASSERT(fCache->uniqueID() == genID);
|
|
|
|
SkASSERT(fCacheSubset->uniqueID() != genID);
|
|
|
|
SkASSERT(fCacheSubset->uniqueID() != genSubsetID);
|
|
|
|
|
|
|
|
SkASSERT(fCache->info().dimensions() == SkISize::Make(100, 100));
|
|
|
|
SkASSERT(fCacheSubset->info().dimensions() == SkISize::Make(50, 50));
|
2015-08-13 20:32:39 +00:00
|
|
|
}
|
|
|
|
|
2015-08-18 18:16:09 +00:00
|
|
|
static void draw_as_bitmap(SkCanvas* canvas, SkImageCacherator* cache, SkScalar x, SkScalar y) {
|
|
|
|
SkBitmap bitmap;
|
2017-03-03 16:10:18 +00:00
|
|
|
cache->lockAsBitmap(canvas->getGrContext(), &bitmap, nullptr,
|
|
|
|
canvas->imageInfo().colorSpace());
|
2015-08-18 18:16:09 +00:00
|
|
|
canvas->drawBitmap(bitmap, x, y);
|
|
|
|
}
|
2015-08-13 20:32:39 +00:00
|
|
|
|
2015-08-18 18:16:09 +00:00
|
|
|
static void draw_as_tex(SkCanvas* canvas, SkImageCacherator* cache, SkScalar x, SkScalar y) {
|
2015-08-13 20:32:39 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2016-11-18 16:28:24 +00:00
|
|
|
sk_sp<SkColorSpace> texColorSpace;
|
2016-11-08 22:08:54 +00:00
|
|
|
sk_sp<GrTexture> texture(
|
2016-11-17 20:17:07 +00:00
|
|
|
cache->lockAsTexture(canvas->getGrContext(), GrSamplerParams::ClampBilerp(),
|
2017-01-20 17:44:06 +00:00
|
|
|
canvas->imageInfo().colorSpace(), &texColorSpace,
|
|
|
|
nullptr, nullptr));
|
2015-08-18 18:16:09 +00:00
|
|
|
if (!texture) {
|
2015-08-19 13:07:29 +00:00
|
|
|
// show placeholder if we have no texture
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
SkRect r = SkRect::MakeXYWH(x, y, SkIntToScalar(cache->info().width()),
|
|
|
|
SkIntToScalar(cache->info().width()));
|
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
canvas->drawLine(r.left(), r.top(), r.right(), r.bottom(), paint);
|
|
|
|
canvas->drawLine(r.left(), r.bottom(), r.right(), r.top(), paint);
|
2015-08-18 18:16:09 +00:00
|
|
|
return;
|
2015-08-13 20:32:39 +00:00
|
|
|
}
|
2015-08-18 18:16:09 +00:00
|
|
|
// No API to draw a GrTexture directly, so we cheat and create a private image subclass
|
2016-10-27 16:30:08 +00:00
|
|
|
sk_sp<SkImage> image(new SkImage_Gpu(cache->info().width(), cache->info().height(),
|
|
|
|
cache->uniqueID(), kPremul_SkAlphaType,
|
2016-11-18 16:28:24 +00:00
|
|
|
std::move(texture), std::move(texColorSpace),
|
2016-10-27 16:30:08 +00:00
|
|
|
SkBudgeted::kNo));
|
|
|
|
canvas->drawImage(image.get(), x, y);
|
2015-08-13 20:32:39 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-08-18 18:16:09 +00:00
|
|
|
void drawSet(SkCanvas* canvas) const {
|
|
|
|
SkMatrix matrix = SkMatrix::MakeTrans(-100, -100);
|
|
|
|
canvas->drawPicture(fPicture, &matrix, nullptr);
|
|
|
|
|
|
|
|
// Draw the tex first, so it doesn't hit a lucky cache from the raster version. This
|
|
|
|
// way we also can force the generateTexture call.
|
|
|
|
|
2016-11-03 18:40:50 +00:00
|
|
|
draw_as_tex(canvas, fCache.get(), 310, 0);
|
|
|
|
draw_as_tex(canvas, fCacheSubset.get(), 310+101, 0);
|
2015-08-18 18:16:09 +00:00
|
|
|
|
2016-11-03 18:40:50 +00:00
|
|
|
draw_as_bitmap(canvas, fCache.get(), 150, 0);
|
|
|
|
draw_as_bitmap(canvas, fCacheSubset.get(), 150+101, 0);
|
2015-08-18 18:16:09 +00:00
|
|
|
}
|
|
|
|
|
2015-08-13 20:32:39 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2015-08-18 18:16:09 +00:00
|
|
|
this->makeCaches(canvas->getGrContext());
|
|
|
|
|
2015-08-13 20:32:39 +00:00
|
|
|
canvas->translate(20, 20);
|
|
|
|
|
|
|
|
this->drawSet(canvas);
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(0, 130);
|
|
|
|
canvas->scale(0.25f, 0.25f);
|
|
|
|
this->drawSet(canvas);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(0, 200);
|
|
|
|
canvas->scale(2, 2);
|
|
|
|
this->drawSet(canvas);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef skiagm::GM INHERITED;
|
|
|
|
};
|
2015-08-18 18:16:09 +00:00
|
|
|
DEF_GM( return new ImageCacheratorGM("picture", make_pic_generator); )
|
|
|
|
DEF_GM( return new ImageCacheratorGM("raster", make_ras_generator); )
|
2015-09-11 18:47:27 +00:00
|
|
|
DEF_GM( return new ImageCacheratorGM("ctable", make_ctable_generator); )
|
2015-08-18 18:16:09 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
DEF_GM( return new ImageCacheratorGM("texture", make_tex_generator); )
|
|
|
|
#endif
|