diff options
-rw-r--r-- | experimental/iOSSampleApp/SkSampleUIView.mm | 77 | ||||
-rw-r--r-- | include/views/SkWindow.h | 10 | ||||
-rw-r--r-- | samplecode/SampleApp.h | 1 |
3 files changed, 46 insertions, 42 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()); diff --git a/include/views/SkWindow.h b/include/views/SkWindow.h index e964fc681b..1c4b5aef89 100644 --- a/include/views/SkWindow.h +++ b/include/views/SkWindow.h @@ -80,6 +80,11 @@ public: virtual sk_sp<SkSurface> makeSurface(); +#if SK_SUPPORT_GPU + sk_sp<SkSurface> makeGpuBackedSurface(const AttachmentInfo& attachmentInfo, + const GrGLInterface* , GrContext* grContext); +#endif + protected: virtual bool onEvent(const SkEvent&); virtual bool onDispatchClick(int x, int y, Click::State, void* owner, unsigned modi); @@ -97,11 +102,6 @@ protected: virtual bool onGetFocusView(SkView** focus) const; virtual bool onSetFocusView(SkView* focus); -#if SK_SUPPORT_GPU - sk_sp<SkSurface> makeGpuBackedSurface(const AttachmentInfo& attachmentInfo, - const GrGLInterface* , GrContext* grContext); -#endif - private: SkSurfaceProps fSurfaceProps; SkBitmap fBitmap; diff --git a/samplecode/SampleApp.h b/samplecode/SampleApp.h index 24e2390f9a..3011f5f757 100644 --- a/samplecode/SampleApp.h +++ b/samplecode/SampleApp.h @@ -14,6 +14,7 @@ #include "SkPictureRecorder.h" #include "SkScalar.h" #include "SkStream.h" +#include "SkSurface.h" #include "SkTDArray.h" #include "SkTouchGesture.h" #include "SkWindow.h" |