Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2253)

Unified Diff: tools/skiaserve/Request.cpp

Issue 1893393002: Adding support for playback to L32/S32/F16 canvas. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/skiaserve/Request.cpp
diff --git a/tools/skiaserve/Request.cpp b/tools/skiaserve/Request.cpp
index 7534b1df98e985b0ba4b0fedd806d96c9c96c816..6e0275426491e264ed080e977b730067fcfa4625 100644
--- a/tools/skiaserve/Request.cpp
+++ b/tools/skiaserve/Request.cpp
@@ -19,7 +19,8 @@ static int kDefaultHeight = 1080;
Request::Request(SkString rootUrl)
: fUploadContext(nullptr)
, fUrlDataManager(rootUrl)
- , fGPUEnabled(false) {
+ , fGPUEnabled(false)
+ , fColorMode(0) {
// create surface
#if SK_SUPPORT_GPU
GrContextOptions grContextOpts;
@@ -42,10 +43,26 @@ SkBitmap* Request::getBitmapFromCanvas(SkCanvas* canvas) {
SkIRect bounds = this->getBounds();
SkImageInfo info = SkImageInfo::Make(bounds.width(), bounds.height(),
kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
- bmp->setInfo(info);
- if (!canvas->readPixels(bmp, 0, 0)) {
- fprintf(stderr, "Can't read pixels\n");
- return nullptr;
+ if (kRGBA_F16_SkColorType == canvas->imageInfo().colorType()) {
Brian Osman 2016/04/18 16:17:03 We have other special-case conversion code in DM,
mtklein 2016/04/18 17:40:48 Think this is a sign we should fix readPixels() fi
+ SkBitmap n32TempBmp;
+ SkImageInfo n32Info = SkImageInfo::Make(bounds.width(), bounds.height(),
+ kN32_SkColorType, kOpaque_SkAlphaType);
+ n32TempBmp.setInfo(n32Info);
+ if (!canvas->readPixels(&n32TempBmp, 0, 0)) {
+ fprintf(stderr, "Can't read pixels\n");
+ return nullptr;
+ }
+
+ if (!n32TempBmp.copyTo(bmp, kRGBA_8888_SkColorType)) {
+ fprintf(stderr, "Can't copy pixels\n");
+ return nullptr;
+ }
+ } else {
+ bmp->setInfo(info);
+ if (!canvas->readPixels(bmp, 0, 0)) {
+ fprintf(stderr, "Can't read pixels\n");
+ return nullptr;
+ }
}
return bmp;
}
@@ -138,25 +155,48 @@ SkIRect Request::getBounds() {
return bounds;
}
+namespace {
+
+struct ColorAndProfile {
+ SkColorType fColorType;
+ SkColorProfileType fProfileType;
+ bool fGammaCorrect;
+};
+
+ColorAndProfile ColorModes[] = {
+ { kN32_SkColorType, kLinear_SkColorProfileType, false },
+ { kN32_SkColorType, kSRGB_SkColorProfileType, true },
+ { kRGBA_F16_SkColorType, kLinear_SkColorProfileType, true },
+};
+
+}
+
SkSurface* Request::createCPUSurface() {
SkIRect bounds = this->getBounds();
- SkImageInfo info = SkImageInfo::Make(bounds.width(), bounds.height(), kN32_SkColorType,
- kPremul_SkAlphaType);
+ ColorAndProfile cap = ColorModes[fColorMode];
+ SkImageInfo info = SkImageInfo::Make(bounds.width(), bounds.height(), cap.fColorType,
+ kPremul_SkAlphaType, cap.fProfileType);
return SkSurface::MakeRaster(info).release();
}
SkSurface* Request::createGPUSurface() {
GrContext* context = this->getContext();
SkIRect bounds = this->getBounds();
- SkImageInfo info = SkImageInfo::Make(bounds.width(), bounds.height(),
- kN32_SkColorType, kPremul_SkAlphaType);
- uint32_t flags = 0;
+ ColorAndProfile cap = ColorModes[fColorMode];
+ SkImageInfo info = SkImageInfo::Make(bounds.width(), bounds.height(), cap.fColorType,
+ kPremul_SkAlphaType, cap.fProfileType);
+ uint32_t flags = cap.fGammaCorrect ? SkSurfaceProps::kGammaCorrect_Flag : 0;
Brian Osman 2016/04/18 16:17:03 Need to do this in createCPUSurface, too.
SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
SkSurface* surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0,
&props).release();
return surface;
}
+bool Request::setColorMode(int mode) {
+ fColorMode = mode;
+ return enableGPU(fGPUEnabled);
+}
+
bool Request::enableGPU(bool enable) {
if (enable) {
SkSurface* surface = this->createGPUSurface();
@@ -167,8 +207,10 @@ bool Request::enableGPU(bool enable) {
// When we switch to GPU, there seems to be some mystery draws in the canvas. So we
// draw once to flush the pipe
// TODO understand what is actually happening here
- fDebugCanvas->drawTo(this->getCanvas(), this->getLastOp());
- this->getCanvas()->flush();
+ if (fDebugCanvas) {
+ fDebugCanvas->drawTo(this->getCanvas(), this->getLastOp());
+ this->getCanvas()->flush();
+ }
return true;
}
@@ -206,6 +248,7 @@ SkData* Request::getJsonOps(int n) {
Json::Value root = fDebugCanvas->toJSON(fUrlDataManager, n, canvas);
root["mode"] = Json::Value(fGPUEnabled ? "gpu" : "cpu");
root["drawGpuBatchBounds"] = Json::Value(fDebugCanvas->getDrawGpuBatchBounds());
+ root["colorMode"] = Json::Value(fColorMode);
SkDynamicMemoryWStream stream;
stream.writeText(Json::FastWriter().write(root).c_str());

Powered by Google App Engine
This is Rietveld 408576698