diff options
author | jvanverth <jvanverth@google.com> | 2016-10-10 07:39:38 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-10-10 07:39:38 -0700 |
commit | 38c72151576a6e89b31b0bd4c45a0b01c11641ff (patch) | |
tree | 396dc6f84fd50c6a43b4d7a73e511b360f8c4306 /experimental | |
parent | 42f4b42e8311f168aeeadd939b476c05b329500e (diff) |
Fix iOS surface creation for SampleApp
BUG=skia:5810
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2394843003
TBR=bsalomon@google.com
Review-Url: https://codereview.chromium.org/2394843003
Diffstat (limited to 'experimental')
-rw-r--r-- | experimental/iOSSampleApp/SkSampleUIView.mm | 77 |
1 files changed, 40 insertions, 37 deletions
diff --git a/experimental/iOSSampleApp/SkSampleUIView.mm b/experimental/iOSSampleApp/SkSampleUIView.mm index b4c6b1cd2b..b1e04873cd 100644 --- a/experimental/iOSSampleApp/SkSampleUIView.mm +++ b/experimental/iOSSampleApp/SkSampleUIView.mm @@ -32,9 +32,9 @@ public: #if SK_SUPPORT_GPU fCurContext = NULL; fCurIntf = NULL; - fCurRenderTarget = NULL; fMSAASampleCount = 0; - fLayerFBO = layerFBO; + fDeepColor = false; + fActualColorBits = 0; #endif fBackend = SkOSWindow::kNone_BackEndType; } @@ -43,7 +43,6 @@ public: #if SK_SUPPORT_GPU SkSafeUnref(fCurContext); SkSafeUnref(fCurIntf); - SkSafeUnref(fCurRenderTarget); #endif } @@ -71,6 +70,9 @@ public: return; } fMSAASampleCount = msaaSampleCount; + fDeepColor = deepColor; + // Assume that we have at least 24-bit output, for backends that don't supply this data + fActualColorBits = SkTMax(info.fColorBits, 24); SkASSERT(NULL == fCurIntf); switch (win->getDeviceType()) { @@ -112,20 +114,27 @@ public: SkSafeUnref(fCurIntf); fCurIntf = NULL; - SkSafeUnref(fCurRenderTarget); - fCurRenderTarget = NULL; + fGpuSurface = nullptr; #endif win->release(); fBackend = SampleWindow::kNone_BackEndType; } - SkSurface* createSurface(SampleWindow::DeviceType dType, SampleWindow* win) override{ + sk_sp<SkSurface> makeSurface(SampleWindow::DeviceType dType, SampleWindow* win) override { #if SK_SUPPORT_GPU if (SampleWindow::IsGpuDeviceType(dType) && fCurContext) { SkSurfaceProps props(win->getSurfaceProps()); - return SkSurface::MakeRenderTargetDirect(fCurRenderTarget, - sk_ref_sp(win->info().colorSpace()), - &props).release(); + if (kRGBA_F16_SkColorType == win->info().colorType() || fActualColorBits > 24) { + // If we're rendering to F16, we need an off-screen surface - the current render + // target is most likely the wrong format. + // + // If we're using a deep (10-bit or higher) surface, we probably need an off-screen + // surface. 10-bit, in particular, has strange gamma behavior. + return SkSurface::MakeRenderTarget(fCurContext, SkBudgeted::kNo, win->info(), + fMSAASampleCount, &props); + } else { + return fGpuSurface; + } } #endif return nullptr; @@ -141,29 +150,18 @@ public: #endif win->present(); } - + void windowSizeChanged(SampleWindow* win) override { #if SK_SUPPORT_GPU - if (NULL != fCurContext) { - SkOSWindow::AttachmentInfo info; - - win->attach(fBackend, fMSAASampleCount, false, &info); - - glBindFramebuffer(GL_FRAMEBUFFER, fLayerFBO); - GrBackendRenderTargetDesc desc; - desc.fWidth = SkScalarRoundToInt(win->width()); - desc.fHeight = SkScalarRoundToInt(win->height()); - desc.fConfig = kSkia8888_GrPixelConfig; - desc.fRenderTargetHandle = fLayerFBO; - desc.fSampleCnt = info.fSampleCount; - desc.fStencilBits = info.fStencilBits; - - SkSafeUnref(fCurRenderTarget); - fCurRenderTarget = fCurContext->textureProvider()->wrapBackendRenderTarget(desc); + if (fCurContext) { + SampleWindow::AttachmentInfo attachmentInfo; + win->attach(fBackend, fMSAASampleCount, fDeepColor, &attachmentInfo); + fActualColorBits = SkTMax(attachmentInfo.fColorBits, 24); + fGpuSurface = win->makeGpuBackedSurface(attachmentInfo, fCurIntf, fCurContext); } #endif } - + GrContext* getGrContext() override { #if SK_SUPPORT_GPU return fCurContext; @@ -171,29 +169,34 @@ public: return NULL; #endif } - - GrRenderTarget* getGrRenderTarget() override { + + int numColorSamples() const override { #if SK_SUPPORT_GPU - return fCurRenderTarget; + return fMSAASampleCount; #else - return NULL; + return 0; #endif } int getColorBits() override { +#if SK_SUPPORT_GPU + return fActualColorBits; +#else return 24; +#endif } bool isUsingGL() const { return SkOSWindow::kNone_BackEndType != fBackend; } - + private: - + #if SK_SUPPORT_GPU GrContext* fCurContext; const GrGLInterface* fCurIntf; - GrRenderTarget* fCurRenderTarget; + sk_sp<SkSurface> fGpuSurface; int fMSAASampleCount; - GLint fLayerFBO; + bool fDeepColor; + int fActualColorBits; #endif SkOSWindow::SkBackEndTypes fBackend; @@ -419,7 +422,7 @@ static FPSState gFPS; glViewport(0, 0, fGL.fWidth, fGL.fHeight); - SkAutoTUnref<SkSurface> surface(fWind->createSurface()); + sk_sp<SkSurface> surface(fWind->makeSurface()); SkCanvas* canvas = surface->getCanvas(); // if we're not "retained", then we have to always redraw everything. @@ -436,7 +439,7 @@ static FPSState gFPS; } - (void)drawInRaster { - SkAutoTUnref<SkSurface> surface(fWind->createSurface()); + sk_sp<SkSurface> surface(fWind->makeSurface()); SkCanvas* canvas = surface->getCanvas(); [self drawWithCanvas:canvas]; CGImageRef cgimage = SkCreateCGImageRef(fWind->getBitmap()); |