Chromium Code Reviews| Index: samplecode/SampleApp.cpp |
| diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp |
| index ba2e6ccad1a2fb301e12bb87f5132ef1e4a261da..aa3177a8f58d8cacb84fd26c86266ccfadaa9793 100644 |
| --- a/samplecode/SampleApp.cpp |
| +++ b/samplecode/SampleApp.cpp |
| @@ -12,6 +12,7 @@ |
| #include "SampleCode.h" |
| #include "SkAnimTimer.h" |
| #include "SkCanvas.h" |
| +#include "SkColorSpace.h" |
| #include "SkCommandLineFlags.h" |
| #include "SkData.h" |
| #include "SkDocument.h" |
| @@ -36,7 +37,9 @@ |
| # include "gl/GrGLInterface.h" |
| # include "gl/GrGLUtil.h" |
| # include "GrRenderTarget.h" |
| +# include "effects/GrColorSpaceEffect.h" |
| # include "GrContext.h" |
| +# include "GrDrawContext.h" |
| # include "SkGr.h" |
| # if SK_ANGLE |
| # include "gl/angle/GLTestContext_angle.h" |
| @@ -178,6 +181,7 @@ public: |
| fCurIntf = nullptr; |
| fCurRenderTarget = nullptr; |
| fMSAASampleCount = 0; |
| + fTenBitColor = false; |
| #endif |
| fBackend = kNone_BackEndType; |
| } |
| @@ -190,7 +194,7 @@ public: |
| #endif |
| } |
| - void setUpBackend(SampleWindow* win, int msaaSampleCount) override { |
| + void setUpBackend(SampleWindow* win, int msaaSampleCount, bool tenBitColor) override { |
| SkASSERT(kNone_BackEndType == fBackend); |
| fBackend = kNone_BackEndType; |
| @@ -219,12 +223,13 @@ public: |
| break; |
| } |
| AttachmentInfo attachmentInfo; |
| - bool result = win->attach(fBackend, msaaSampleCount, &attachmentInfo); |
| + bool result = win->attach(fBackend, msaaSampleCount, tenBitColor, &attachmentInfo); |
|
Brian Osman
2016/04/27 19:55:01
Seems like I should add fColorBits to AttachmentIn
|
| if (!result) { |
| SkDebugf("Failed to initialize GL"); |
| return; |
| } |
| fMSAASampleCount = msaaSampleCount; |
| + fTenBitColor = tenBitColor; |
| SkASSERT(nullptr == fCurIntf); |
| SkAutoTUnref<const GrGLInterface> glInterface; |
| @@ -294,9 +299,10 @@ public: |
| #if SK_SUPPORT_GPU |
| if (IsGpuDeviceType(dType) && fCurContext) { |
| SkSurfaceProps props(win->getSurfaceProps()); |
| - if (kRGBA_F16_SkColorType == win->info().colorType()) { |
| + if (kRGBA_F16_SkColorType == win->info().colorType() || fTenBitColor) { |
| // Need to make an off-screen F16 surface - the current render target is |
| - // (probably) the wrong format. |
| + // (probably) the wrong format. If we're using a 10-bit surface, we definitely |
| + // need an off-screen surface, because 10-bit behaves strangely wrt gamma. |
| return SkSurface::MakeRenderTarget(fCurContext, SkBudgeted::kNo, win->info(), |
| fMSAASampleCount, &props).release(); |
| } else { |
| @@ -314,7 +320,33 @@ public: |
| // in case we have queued drawing calls |
| fCurContext->flush(); |
| - if (!IsGpuDeviceType(dType)) { |
| + if (fTenBitColor) { |
| + SkBitmap bm; |
| + bm.allocPixels(win->info()); |
| + canvas->readPixels(&bm, 0, 0); |
|
Brian Osman
2016/04/27 19:55:01
This is really ugly, but I couldn't find a way to
bsalomon
2016/04/27 20:28:24
My gut take is that this adds too much technical d
|
| + if (SkImageInfoIsGammaCorrect(win->info())) { |
| + // For now, assuming source and destination are both sRGB. |
| + // TODO: Fetch destination space from device, or allow it to be specified |
| + // on the command line, etc... |
| + sk_sp<SkColorSpace> srgb(SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named)); |
| + |
| + fCurRenderTarget->writePixelsWithColorSpace( |
| + 0, 0, bm.width(), bm.height(), |
| + SkImageInfo2GrPixelConfig(bm.info(), *fCurContext->caps()), |
| + srgb.get(), srgb.get(), bm.getPixels(), bm.rowBytes(), |
| + GrContext::kManualDstGamma_ColorSpaceOpsFlag); |
| + } else { |
| + // We rendered to L32 (legacy mode). That matches the semantics of the windowing |
| + // system's 10-bit buffer (data is treated as sRGB, but not gamma-corrected on |
| + // write). We can just do a writePixels, which is just a copy of values. |
| + fCurRenderTarget->writePixels(0, 0, bm.width(), bm.height(), |
| + SkImageInfo2GrPixelConfig(bm.info(), |
| + *fCurContext->caps()), |
| + bm.getPixels(), |
| + bm.rowBytes(), |
| + GrContext::kFlushWrites_PixelOp); |
| + } |
| + } else if (!IsGpuDeviceType(dType)) { |
| // need to send the raster bits to the (gpu) window |
| const SkBitmap& bm = win->getBitmap(); |
| fCurRenderTarget->writePixels(0, 0, bm.width(), bm.height(), |
| @@ -346,7 +378,7 @@ public: |
| #if SK_SUPPORT_GPU |
| if (fCurContext) { |
| AttachmentInfo attachmentInfo; |
| - win->attach(fBackend, fMSAASampleCount, &attachmentInfo); |
| + win->attach(fBackend, fMSAASampleCount, fTenBitColor, &attachmentInfo); |
| SkSafeUnref(fCurRenderTarget); |
| fCurRenderTarget = win->renderTarget(attachmentInfo, fCurIntf, fCurContext); |
| } |
| @@ -376,6 +408,7 @@ private: |
| const GrGLInterface* fCurIntf; |
| GrRenderTarget* fCurRenderTarget; |
| int fMSAASampleCount; |
| + bool fTenBitColor; |
| #endif |
| SkOSWindow::SkBackEndTypes fBackend; |
| @@ -773,6 +806,7 @@ static void restrict_samples(SkTDArray<const SkViewFactory*>& factories, const S |
| DEFINE_string(slide, "", "Start on this sample."); |
| DEFINE_int32(msaa, 0, "Request multisampling with this count."); |
| +DEFINE_bool(tenBit, false, "Request 10-bit/channel display buffer."); |
| DEFINE_string(pictureDir, "", "Read pictures from here."); |
| DEFINE_string(picture, "", "Path to single picture."); |
| DEFINE_string(sequence, "", "Path to file containing the desired samples/gms to show."); |
| @@ -861,6 +895,7 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev |
| } |
| fMSAASampleCount = FLAGS_msaa; |
| + fTenBitColor = FLAGS_tenBit; |
| if (FLAGS_list) { |
| listTitles(); |
| @@ -1023,7 +1058,7 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev |
| devManager->ref(); |
| fDevManager = devManager; |
| } |
| - fDevManager->setUpBackend(this, fMSAASampleCount); |
| + fDevManager->setUpBackend(this, fMSAASampleCount, fTenBitColor); |
| // If another constructor set our dimensions, ensure that our |
| // onSizeChange gets called. |
| @@ -1847,7 +1882,7 @@ void SampleWindow::setDeviceType(DeviceType type) { |
| fDevManager->tearDownBackend(this); |
| fDeviceType = type; |
| - fDevManager->setUpBackend(this, fMSAASampleCount); |
| + fDevManager->setUpBackend(this, fMSAASampleCount, fTenBitColor); |
| this->updateTitle(); |
| this->inval(nullptr); |
| @@ -1857,7 +1892,7 @@ void SampleWindow::setDeviceColorType(SkColorType ct, SkColorProfileType pt) { |
| this->setColorType(ct, pt); |
| fDevManager->tearDownBackend(this); |
| - fDevManager->setUpBackend(this, fMSAASampleCount); |
| + fDevManager->setUpBackend(this, fMSAASampleCount, fTenBitColor); |
| this->updateTitle(); |
| this->inval(nullptr); |
| @@ -1884,7 +1919,7 @@ void SampleWindow::toggleFPS() { |
| void SampleWindow::toggleDistanceFieldFonts() { |
| // reset backend |
| fDevManager->tearDownBackend(this); |
| - fDevManager->setUpBackend(this, fMSAASampleCount); |
| + fDevManager->setUpBackend(this, fMSAASampleCount, fTenBitColor); |
| SkSurfaceProps props = this->getSurfaceProps(); |
| uint32_t flags = props.flags() ^ SkSurfaceProps::kUseDeviceIndependentFonts_Flag; |
| @@ -1897,7 +1932,7 @@ void SampleWindow::toggleDistanceFieldFonts() { |
| void SampleWindow::setPixelGeometry(int pixelGeometryIndex) { |
| // reset backend |
| fDevManager->tearDownBackend(this); |
| - fDevManager->setUpBackend(this, fMSAASampleCount); |
| + fDevManager->setUpBackend(this, fMSAASampleCount, fTenBitColor); |
| const SkSurfaceProps& oldProps = this->getSurfaceProps(); |
| SkSurfaceProps newProps(oldProps.flags(), SkSurfaceProps::kLegacyFontHost_InitType); |
| @@ -2162,6 +2197,10 @@ void SampleWindow::updateTitle() { |
| title.appendf(" %s", find_config_name(this->info())); |
| + if (fTenBitColor) { |
| + title.append(" 10 bpc"); |
| + } |
| + |
| if (gTreatSkColorAsSRGB) { |
| title.append(" sRGB"); |
| } |