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.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkColorSpace.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkImage.h"
|
|
|
|
#include "include/core/SkImageGenerator.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkImageInfo.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPicture.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkPictureRecorder.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkPoint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkSurface.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrContext.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/gpu/GrTypes.h"
|
|
|
|
#include "include/private/GrTypesPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrContextPriv.h"
|
2019-08-14 21:00:30 +00:00
|
|
|
#include "src/gpu/GrSamplerState.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrSurfaceContext.h"
|
2019-06-18 13:58:02 +00:00
|
|
|
#include "src/gpu/GrTextureProxy.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "src/image/SkImage_Base.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/image/SkImage_Gpu.h"
|
2015-08-13 16:37:45 +00:00
|
|
|
|
2019-05-01 21:28:53 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
class GrRecordingContext;
|
|
|
|
|
2015-08-13 16:37:45 +00:00
|
|
|
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:
|
2017-04-17 15:02:51 +00:00
|
|
|
RasterGenerator(const SkBitmap& bm) : SkImageGenerator(bm.info()), fBM(bm)
|
|
|
|
{}
|
|
|
|
|
2015-08-18 18:16:09 +00:00
|
|
|
protected:
|
|
|
|
bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
|
2017-05-12 15:41:27 +00:00
|
|
|
const Options&) override {
|
2015-09-11 18:47:27 +00:00
|
|
|
SkASSERT(fBM.width() == info.width());
|
|
|
|
SkASSERT(fBM.height() == info.height());
|
2017-05-12 15:41:27 +00:00
|
|
|
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);
|
2019-12-11 15:45:01 +00:00
|
|
|
return std::make_unique<RasterGenerator>(bm);
|
2015-08-18 18:16:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class EmptyGenerator : public SkImageGenerator {
|
|
|
|
public:
|
|
|
|
EmptyGenerator(const SkImageInfo& info) : SkImageGenerator(info) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
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)) {
|
|
|
|
|
2017-09-21 12:26:08 +00:00
|
|
|
sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kYes, info, 0,
|
2017-07-21 19:37:19 +00:00
|
|
|
kTopLeft_GrSurfaceOrigin, nullptr));
|
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());
|
2019-03-05 17:35:44 +00:00
|
|
|
fProxy = as_IB(image)->asTextureProxyRef(fCtx.get());
|
2016-05-13 14:25:44 +00:00
|
|
|
}
|
2015-08-18 18:16:09 +00:00
|
|
|
}
|
|
|
|
protected:
|
2019-02-19 17:52:29 +00:00
|
|
|
sk_sp<GrTextureProxy> onGenerateTexture(GrRecordingContext* ctx, const SkImageInfo& info,
|
2017-07-08 08:47:47 +00:00
|
|
|
const SkIPoint& origin,
|
2017-10-09 13:57:35 +00:00
|
|
|
bool willBeMipped) override {
|
2017-03-03 16:10:18 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-10-22 14:37:46 +00:00
|
|
|
if (origin.fX == 0 && origin.fY == 0 && info.dimensions() == fProxy->dimensions()) {
|
2017-03-03 16:10:18 +00:00
|
|
|
return fProxy;
|
2016-12-15 14:23:05 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 17:39:09 +00:00
|
|
|
GrMipMapped mipMapped = willBeMipped ? GrMipMapped::kYes : GrMipMapped::kNo;
|
|
|
|
|
2019-11-23 00:09:27 +00:00
|
|
|
return GrSurfaceProxy::Copy(
|
2020-01-16 21:54:26 +00:00
|
|
|
fCtx.get(), fProxy.get(), SkColorTypeToGrColorType(info.colorType()), mipMapped,
|
Reland "Reland "Remove support for copyAsDraw in gpu copySurface.""
This reverts commit 4c6f9b767034c6812d868108516c2580dce3cb56.
Reason for revert: Landing with neuxs 7 and androind one fixes
Original change's description:
> Revert "Reland "Remove support for copyAsDraw in gpu copySurface.""
>
> This reverts commit 84ea04949cabc87a88d06c5c6f6aeb944a745911.
>
> Reason for revert: nexus 7 and android one broken
>
> Original change's description:
> > Reland "Remove support for copyAsDraw in gpu copySurface."
> >
> > This reverts commit c5167c053bd58e6afbad83fe493c0231df3f9704.
> >
> > Reason for revert: fixed
> >
> > Original change's description:
> > > Revert "Remove support for copyAsDraw in gpu copySurface."
> > >
> > > This reverts commit 6565506463db042d3d543a1707f473cdf1ef4e9e.
> > >
> > > Reason for revert: seems to break things?
> > >
> > > Original change's description:
> > > > Remove support for copyAsDraw in gpu copySurface.
> > > >
> > > > The major changes on a higher lever are:
> > > > 1) The majority of all copies now go through GrSurfaceProxy::Copy which
> > > > takes in a proxy and returns a new one with the data copied to it. This
> > > > is the most common use case within Ganesh.
> > > >
> > > > 2) The backend copy calls no longer do draws, require origins to be the
> > > > same, and won't do any swizzling or adjustment of subrects. They are
> > > > all implemented to be dumb copy this data to this other spot.
> > > >
> > > > 3) The GrSurfaceContext copy call has now been moved to priv and renamed
> > > > copyNoDraw, and a new priv copyAsDraw was added to GrRenderTargetContext.
> > > >
> > > > 4) WritePixels and ReplaceRenderTarget both need to specifiy the destination
> > > > of copies. They are the only users (besides the GrSurfaceProxy::Copy) which
> > > > call the priv methods on GrSurfaceContext.
> > > >
> > > > Change-Id: Iaf1eb3a73ccaf39a75af77e281dae594f809186f
> > > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/217459
> > > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > >
> > > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com
> > >
> > > Change-Id: Id43aa8aa1451e794342e930441d9975b90e6b59f
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/218549
> > > Reviewed-by: Greg Daniel <egdaniel@google.com>
> > > Commit-Queue: Greg Daniel <egdaniel@google.com>
> >
> > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com
> >
> > Change-Id: I1a96f85ae2ff7622a6b57406755d478e7fbcf56e
> > No-Presubmit: true
> > No-Tree-Checks: true
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/218797
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com
>
> Change-Id: I310930a9df30535f45a065263a40239141e15562
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/219384
> Reviewed-by: Greg Daniel <egdaniel@google.com>
> Commit-Queue: Greg Daniel <egdaniel@google.com>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com
Change-Id: I88df4f19aa26ed77b5af4e25d138387cbabd1934
No-Presubmit: true
No-Tree-Checks: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/219386
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
2019-06-07 15:43:30 +00:00
|
|
|
SkIRect::MakeXYWH(origin.x(), origin.y(), info.width(), info.height()),
|
|
|
|
SkBackingFit::kExact, SkBudgeted::kYes);
|
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) {
|
2019-12-11 15:45:01 +00:00
|
|
|
return std::make_unique<EmptyGenerator>(info);
|
2015-08-18 18:16:09 +00:00
|
|
|
}
|
2019-12-11 15:45:01 +00:00
|
|
|
return std::make_unique<TextureGenerator>(ctx, info, pic);
|
2015-08-18 18:16:09 +00:00
|
|
|
}
|
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;
|
2017-04-24 20:44:03 +00:00
|
|
|
sk_sp<SkImage> fImage;
|
|
|
|
sk_sp<SkImage> fImageSubset;
|
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);
|
2017-04-24 20:44:03 +00:00
|
|
|
fImage = SkImage::MakeFromGenerator(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);
|
2017-04-24 20:44:03 +00:00
|
|
|
fImageSubset = SkImage::MakeFromGenerator(std::move(gen), &subset);
|
2015-08-18 18:16:09 +00:00
|
|
|
|
2017-04-26 20:20:28 +00:00
|
|
|
SkASSERT(fImage->dimensions() == SkISize::Make(100, 100));
|
|
|
|
SkASSERT(fImageSubset->dimensions() == SkISize::Make(50, 50));
|
2015-08-13 20:32:39 +00:00
|
|
|
}
|
|
|
|
|
2017-04-24 20:44:03 +00:00
|
|
|
static void draw_as_bitmap(SkCanvas* canvas, SkImage* image, SkScalar x, SkScalar y) {
|
2015-08-18 18:16:09 +00:00
|
|
|
SkBitmap bitmap;
|
2018-10-19 17:02:14 +00:00
|
|
|
as_IB(image)->getROPixels(&bitmap);
|
2015-08-18 18:16:09 +00:00
|
|
|
canvas->drawBitmap(bitmap, x, y);
|
|
|
|
}
|
2015-08-13 20:32:39 +00:00
|
|
|
|
2017-04-24 20:44:03 +00:00
|
|
|
static void draw_as_tex(SkCanvas* canvas, SkImage* image, SkScalar x, SkScalar y) {
|
2019-09-30 16:33:11 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy(as_IB(image)->asTextureProxyRef(
|
2020-01-09 15:46:36 +00:00
|
|
|
canvas->getGrContext(), GrSamplerState::Filter::kBilerp, nullptr));
|
2019-09-30 16:33:11 +00:00
|
|
|
if (!proxy) {
|
2015-08-19 13:07:29 +00:00
|
|
|
// show placeholder if we have no texture
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
2017-04-24 20:44:03 +00:00
|
|
|
SkRect r = SkRect::MakeXYWH(x, y, SkIntToScalar(image->width()),
|
|
|
|
SkIntToScalar(image->width()));
|
2015-08-19 13:07:29 +00:00
|
|
|
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
|
|
|
}
|
2019-09-30 16:33:11 +00:00
|
|
|
|
2019-12-13 16:09:43 +00:00
|
|
|
// TODO: The asTextureProxyRef which takes a sampler and adjust needs to return a
|
|
|
|
// GrSurfaceProxyView instead. For now we just grab the info off the proxy.
|
|
|
|
GrSurfaceOrigin origin = proxy->origin();
|
|
|
|
const GrSwizzle& swizzle = proxy->textureSwizzle();
|
|
|
|
GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
|
|
|
|
|
2019-09-30 16:33:11 +00:00
|
|
|
// No API to draw a GrTexture directly, so we cheat and create a private image subclass
|
|
|
|
sk_sp<SkImage> texImage(new SkImage_Gpu(sk_ref_sp(canvas->getGrContext()),
|
2020-01-22 17:22:36 +00:00
|
|
|
image->uniqueID(), std::move(view),
|
|
|
|
image->colorType(), image->alphaType(),
|
|
|
|
image->refColorSpace()));
|
2017-04-24 20:44:03 +00:00
|
|
|
canvas->drawImage(texImage.get(), x, y);
|
2015-08-13 20:32:39 +00:00
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
|
2017-04-24 20:44:03 +00:00
|
|
|
draw_as_tex(canvas, fImage.get(), 310, 0);
|
|
|
|
draw_as_tex(canvas, fImageSubset.get(), 310+101, 0);
|
2015-08-18 18:16:09 +00:00
|
|
|
|
2017-04-24 20:44:03 +00:00
|
|
|
draw_as_bitmap(canvas, fImage.get(), 150, 0);
|
|
|
|
draw_as_bitmap(canvas, fImageSubset.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); )
|
2018-05-31 18:27:17 +00:00
|
|
|
DEF_GM( return new ImageCacheratorGM("texture", make_tex_generator); )
|