Add additional information (e.g. colorspace) to the GpuDrawHandler

Bug: b/115613038
Change-Id: I375fc5f1bac13557b35e39658d678c61f70024c8
Reviewed-on: https://skia-review.googlesource.com/c/182900
Commit-Queue: Derek Sollenberger <djsollen@google.com>
Auto-Submit: Derek Sollenberger <djsollen@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Derek Sollenberger 2019-01-10 13:19:06 -05:00 committed by Skia Commit-Bot
parent f6fca2668d
commit e6fb76bbd2
3 changed files with 38 additions and 21 deletions

View File

@ -9,6 +9,7 @@
#define SkDrawable_DEFINED
#include "SkFlattenable.h"
#include "SkImageInfo.h"
#include "SkScalar.h"
class GrBackendDrawableInfo;
@ -74,13 +75,14 @@ public:
/**
* Snaps off a GpuDrawHandler to represent the state of the SkDrawable at the time the snap is
* called. This is used for executing GPU backend specific draws intermixed with normal Skia GPU
* draws. The GPU API, which will be used for the draw, as well as the full matrix and device
* clip bounds are passed in as inputs.
* draws. The GPU API, which will be used for the draw, as well as the full matrix, device clip
* bounds and imageInfo of the target buffer are passed in as inputs.
*/
std::unique_ptr<GpuDrawHandler> snapGpuDrawHandler(GrBackendApi backendApi,
const SkMatrix& matrix,
const SkIRect& clipBounds) {
return this->onSnapGpuDrawHandler(backendApi, matrix, clipBounds);
const SkIRect& clipBounds,
const SkImageInfo& bufferInfo) {
return this->onSnapGpuDrawHandler(backendApi, matrix, clipBounds, bufferInfo);
}
SkPicture* newPictureSnapshot();
@ -133,7 +135,8 @@ protected:
virtual void onDraw(SkCanvas*) = 0;
virtual std::unique_ptr<GpuDrawHandler> onSnapGpuDrawHandler(GrBackendApi, const SkMatrix&,
const SkIRect& /*clipBounds*/) {
const SkIRect& /*clipBounds*/,
const SkImageInfo&) {
return nullptr;
}

View File

@ -1747,7 +1747,8 @@ void SkGpuDevice::drawDrawable(SkDrawable* drawable, const SkMatrix* matrix, SkC
const SkMatrix& ctm = canvas->getTotalMatrix();
const SkMatrix& combinedMatrix = matrix ? SkMatrix::Concat(ctm, *matrix) : ctm;
std::unique_ptr<SkDrawable::GpuDrawHandler> gpuDraw =
drawable->snapGpuDrawHandler(api, combinedMatrix, canvas->getDeviceClipBounds());
drawable->snapGpuDrawHandler(api, combinedMatrix, canvas->getDeviceClipBounds(),
this->imageInfo());
if (gpuDraw) {
fRenderTargetContext->drawDrawable(std::move(gpuDraw), drawable->getBounds());
return;

View File

@ -88,7 +88,8 @@ public:
typedef GpuDrawHandler INHERITED;
};
typedef void (*DrawProc)(TestDrawable*, const GrVkDrawableInfo&);
typedef void (*DrawProc)(TestDrawable*, const SkMatrix&, const SkIRect&,
const SkImageInfo&, const GrVkDrawableInfo&);
typedef void (*SubmitProc)(TestDrawable*);
// Exercises the exporting of a secondary command buffer from one GrContext and then importing
@ -96,11 +97,17 @@ public:
// GrContext.
class DrawHandlerImport : public GpuDrawHandler {
public:
DrawHandlerImport(TestDrawable* td, DrawProc drawProc, SubmitProc submitProc)
DrawHandlerImport(TestDrawable* td, DrawProc drawProc, SubmitProc submitProc,
const SkMatrix& matrix,
const SkIRect& clipBounds,
const SkImageInfo& bufferInfo)
: INHERITED()
, fTestDrawable(td)
, fDrawProc(drawProc)
, fSubmitProc(submitProc) {}
, fSubmitProc(submitProc)
, fMatrix(matrix)
, fClipBounds(clipBounds)
, fBufferInfo(bufferInfo) {}
~DrawHandlerImport() override {
fSubmitProc(fTestDrawable);
}
@ -109,28 +116,32 @@ public:
GrVkDrawableInfo vkInfo;
SkAssertResult(info.getVkDrawableInfo(&vkInfo));
fDrawProc(fTestDrawable, vkInfo);
fDrawProc(fTestDrawable, fMatrix, fClipBounds, fBufferInfo, vkInfo);
}
private:
TestDrawable* fTestDrawable;
DrawProc fDrawProc;
SubmitProc fSubmitProc;
TestDrawable* fTestDrawable;
DrawProc fDrawProc;
SubmitProc fSubmitProc;
const SkMatrix fMatrix;
const SkIRect fClipBounds;
const SkImageInfo fBufferInfo;
typedef GpuDrawHandler INHERITED;
};
// Helper function to test drawing to a secondary command buffer that we imported into the
// GrContext using a GrVkSecondaryCBDrawContext.
static void ImportDraw(TestDrawable* td, const GrVkDrawableInfo& info) {
SkImageInfo imageInfo = SkImageInfo::Make(td->fWidth, td->fHeight, kRGBA_8888_SkColorType,
kPremul_SkAlphaType);
td->fDrawContext = GrVkSecondaryCBDrawContext::Make(td->fContext, imageInfo, info, nullptr);
static void ImportDraw(TestDrawable* td, const SkMatrix& matrix, const SkIRect& clipBounds,
const SkImageInfo& bufferInfo, const GrVkDrawableInfo& info) {
td->fDrawContext = GrVkSecondaryCBDrawContext::Make(td->fContext, bufferInfo, info, nullptr);
if (!td->fDrawContext) {
return;
}
SkCanvas* canvas = td->fDrawContext->getCanvas();
canvas->clipRect(SkRect::Make(clipBounds));
canvas->setMatrix(matrix);
SkIRect rect = SkIRect::MakeXYWH(td->fWidth/2, 0, td->fWidth/4, td->fHeight);
SkPaint paint;
paint.setColor(SK_ColorRED);
@ -139,7 +150,7 @@ public:
// Draw to an offscreen target so that we end up with a mix of "real" secondary command
// buffers and the imported secondary command buffer.
sk_sp<SkSurface> surf = SkSurface::MakeRenderTarget(td->fContext, SkBudgeted::kYes,
imageInfo);
bufferInfo);
surf->getCanvas()->clear(SK_ColorRED);
SkRect dstRect = SkRect::MakeXYWH(3*td->fWidth/4, 0, td->fWidth/4, td->fHeight);
@ -171,13 +182,15 @@ public:
std::unique_ptr<GpuDrawHandler> onSnapGpuDrawHandler(GrBackendApi backendApi,
const SkMatrix& matrix,
const SkIRect& clipBounds) override {
const SkIRect& clipBounds,
const SkImageInfo& bufferInfo) override {
if (backendApi != GrBackendApi::kVulkan) {
return nullptr;
}
std::unique_ptr<GpuDrawHandler> draw;
if (fContext) {
draw.reset(new DrawHandlerImport(this, ImportDraw, ImportSubmitted));
draw.reset(new DrawHandlerImport(this, ImportDraw, ImportSubmitted, matrix,
clipBounds, bufferInfo));
} else {
draw.reset(new DrawHandlerBasic(fInterface, fWidth, fHeight));
}