| Index: samplecode/SampleApp.cpp
|
| diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
|
| index ba2e6ccad1a2fb301e12bb87f5132ef1e4a261da..6b862f4b54d88e2df76628c8c29b7bfcad613296 100644
|
| --- a/samplecode/SampleApp.cpp
|
| +++ b/samplecode/SampleApp.cpp
|
| @@ -16,6 +16,7 @@
|
| #include "SkData.h"
|
| #include "SkDocument.h"
|
| #include "SkGraphics.h"
|
| +#include "SkImage_Base.h"
|
| #include "SkImageEncoder.h"
|
| #include "SkOSFile.h"
|
| #include "SkPaint.h"
|
| @@ -178,6 +179,7 @@ public:
|
| fCurIntf = nullptr;
|
| fCurRenderTarget = nullptr;
|
| fMSAASampleCount = 0;
|
| + fTenBitColor = false;
|
| #endif
|
| fBackend = kNone_BackEndType;
|
| }
|
| @@ -190,7 +192,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 +221,13 @@ public:
|
| break;
|
| }
|
| AttachmentInfo attachmentInfo;
|
| - bool result = win->attach(fBackend, msaaSampleCount, &attachmentInfo);
|
| + bool result = win->attach(fBackend, msaaSampleCount, tenBitColor, &attachmentInfo);
|
| if (!result) {
|
| SkDebugf("Failed to initialize GL");
|
| return;
|
| }
|
| fMSAASampleCount = msaaSampleCount;
|
| + fTenBitColor = tenBitColor;
|
|
|
| SkASSERT(nullptr == fCurIntf);
|
| SkAutoTUnref<const GrGLInterface> glInterface;
|
| @@ -294,9 +297,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 {
|
| @@ -313,29 +317,37 @@ public:
|
| if (fCurContext) {
|
| // in case we have queued drawing calls
|
| fCurContext->flush();
|
| + }
|
|
|
| - if (!IsGpuDeviceType(dType)) {
|
| + if (kRGBA_F16_SkColorType == win->info().colorType() || fTenBitColor) {
|
| + // We made an off-screen surface. Get the contents as an SkImage:
|
| + SkBitmap bm;
|
| + bm.allocPixels(win->info());
|
| + canvas->readPixels(&bm, 0, 0);
|
| + SkPixmap pm;
|
| + bm.peekPixels(&pm);
|
| + sk_sp<SkImage> image(SkImage::MakeTextureFromPixmap(fCurContext, pm,
|
| + SkBudgeted::kNo));
|
| + GrTexture* texture = as_IB(image)->peekTexture();
|
| + SkASSERT(texture);
|
| +
|
| + // With ten-bit output, we need to manually apply the gamma of the output device
|
| + // (unless we're in non-gamma correct mode, in which case our data is already
|
| + // fake-sRGB, like we're expected to put in the 10-bit buffer):
|
| + bool doGamma = fTenBitColor && SkImageInfoIsGammaCorrect(win->info());
|
| + fCurContext->applyGamma(fCurRenderTarget, texture, doGamma ? 2.2f : 1.0f);
|
| + } 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(),
|
| - SkImageInfo2GrPixelConfig(bm.colorType(),
|
| - bm.alphaType(),
|
| - bm.profileType(),
|
| - *fCurContext->caps()),
|
| - bm.getPixels(),
|
| - bm.rowBytes(),
|
| - GrContext::kFlushWrites_PixelOp);
|
| - } else if (kRGBA_F16_SkColorType == win->info().colorType()) {
|
| - SkBitmap bm;
|
| - bm.allocPixels(win->info());
|
| - canvas->readPixels(&bm, 0, 0);
|
| - fCurRenderTarget->writePixels(0, 0, bm.width(), bm.height(),
|
| - SkImageInfo2GrPixelConfig(bm.info(),
|
| + SkImageInfo2GrPixelConfig(bm.colorType(),
|
| + bm.alphaType(),
|
| + bm.profileType(),
|
| *fCurContext->caps()),
|
| bm.getPixels(),
|
| bm.rowBytes(),
|
| GrContext::kFlushWrites_PixelOp);
|
| - }
|
| +
|
| }
|
| #endif
|
|
|
| @@ -346,7 +358,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 +388,7 @@ private:
|
| const GrGLInterface* fCurIntf;
|
| GrRenderTarget* fCurRenderTarget;
|
| int fMSAASampleCount;
|
| + bool fTenBitColor;
|
| #endif
|
|
|
| SkOSWindow::SkBackEndTypes fBackend;
|
| @@ -773,6 +786,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 +875,7 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
|
| }
|
|
|
| fMSAASampleCount = FLAGS_msaa;
|
| + fTenBitColor = FLAGS_tenBit;
|
|
|
| if (FLAGS_list) {
|
| listTitles();
|
| @@ -1023,7 +1038,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 +1862,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 +1872,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 +1899,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 +1912,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 +2177,10 @@ void SampleWindow::updateTitle() {
|
|
|
| title.appendf(" %s", find_config_name(this->info()));
|
|
|
| + if (fTenBitColor) {
|
| + title.append(" 10 bpc");
|
| + }
|
| +
|
| if (gTreatSkColorAsSRGB) {
|
| title.append(" sRGB");
|
| }
|
|
|