diff options
author | robertphillips <robertphillips@google.com> | 2016-07-28 15:17:34 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-07-28 15:17:34 -0700 |
commit | ecf3dbe8f2987a08b21be1aff61b7fbfbb69640a (patch) | |
tree | 99358f3174597d234b1fdba3528dfdc513a09101 /example | |
parent | 99fb670977b5566e901cb4b95531a000ed0ec8a9 (diff) |
Remove use of MakeRenderTargetDirect from view system
Here is the CL that sent me down the SkGammaColorFilter path
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2178353005
Review-Url: https://codereview.chromium.org/2178353005
Diffstat (limited to 'example')
-rw-r--r-- | example/HelloWorld.cpp | 27 | ||||
-rw-r--r-- | example/HelloWorld.h | 17 |
2 files changed, 21 insertions, 23 deletions
diff --git a/example/HelloWorld.cpp b/example/HelloWorld.cpp index 32bee5dccd..5239311c85 100644 --- a/example/HelloWorld.cpp +++ b/example/HelloWorld.cpp @@ -29,7 +29,6 @@ void application_term() { HelloWorldWindow::HelloWorldWindow(void* hwnd) : INHERITED(hwnd) { fType = kGPU_DeviceType; - fRenderTarget = NULL; fRotationAngle = 0; this->setTitle(); this->setUpBackend(); @@ -46,8 +45,7 @@ void HelloWorldWindow::tearDownBackend() { SkSafeUnref(fInterface); fInterface = NULL; - SkSafeUnref(fRenderTarget); - fRenderTarget = NULL; + fGpuSurface = nullptr; INHERITED::release(); } @@ -70,19 +68,17 @@ bool HelloWorldWindow::setUpBackend() { } fInterface = GrGLCreateNativeInterface(); - SkASSERT(NULL != fInterface); fContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fInterface); SkASSERT(NULL != fContext); - this->setUpRenderTarget(); + this->setUpGpuBackedSurface(); return true; } -void HelloWorldWindow::setUpRenderTarget() { - SkSafeUnref(fRenderTarget); - fRenderTarget = this->renderTarget(fAttachmentInfo, fInterface, fContext); +void HelloWorldWindow::setUpGpuBackedSurface() { + fGpuSurface = this->makeGpuBackedSurface(fAttachmentInfo, fInterface, fContext); } void HelloWorldWindow::drawContents(SkCanvas* canvas) { @@ -142,7 +138,7 @@ void HelloWorldWindow::drawContents(SkCanvas* canvas) { } void HelloWorldWindow::draw(SkCanvas* canvas) { - drawContents(canvas); + this->drawContents(canvas); // in case we have queued drawing calls fContext->flush(); // Invalidate the window to force a redraw. Poor man's animation mechanism. @@ -150,21 +146,22 @@ void HelloWorldWindow::draw(SkCanvas* canvas) { if (kRaster_DeviceType == fType) { // need to send the raster bits to the (gpu) window - sk_sp<SkImage> snap = fSurface->makeImageSnapshot(); + sk_sp<SkImage> snap = fRasterSurface->makeImageSnapshot(); SkPixmap pmap; if (snap->peekPixels(&pmap)) { const SkImageInfo& info = pmap.info(); - fRenderTarget->writePixels(0, 0, snap->width(), snap->height(), - SkImageInfo2GrPixelConfig(info, *fContext->caps()), - pmap.addr(), pmap.rowBytes(), - GrContext::kFlushWrites_PixelOp); + + SkCanvas* canvas = fGpuSurface->getCanvas(); + + canvas->writePixels(info, pmap.addr(), pmap.rowBytes(), 0, 0); + canvas->flush(); } } INHERITED::present(); } void HelloWorldWindow::onSizeChange() { - setUpRenderTarget(); + this->setUpGpuBackedSurface(); } bool HelloWorldWindow::onHandleChar(SkUnichar unichar) { diff --git a/example/HelloWorld.h b/example/HelloWorld.h index deb56ba699..d3fc7cfb16 100644 --- a/example/HelloWorld.h +++ b/example/HelloWorld.h @@ -33,14 +33,15 @@ public: DeviceType getDeviceType() const { return fType; } protected: - SkSurface* createSurface() override { + sk_sp<SkSurface> makeSurface() override { SkSurfaceProps props(INHERITED::getSurfaceProps()); if (kGPU_DeviceType == fType) { - return SkSurface::MakeRenderTargetDirect(fRenderTarget, nullptr, &props).release(); + return fGpuSurface; } - static const SkImageInfo info = SkImageInfo::MakeN32Premul( - SkScalarRoundToInt(this->width()), SkScalarRoundToInt(this->height())); - return fSurface = SkSurface::MakeRaster(info, &props).release(); + const SkImageInfo info = SkImageInfo::MakeN32Premul(SkScalarRoundToInt(this->width()), + SkScalarRoundToInt(this->height())); + fRasterSurface = SkSurface::MakeRaster(info, &props); + return fRasterSurface; } void draw(SkCanvas* canvas) override; @@ -51,7 +52,7 @@ protected: private: bool findNextMatch(); // Set example to the first one that matches FLAGS_match. void setTitle(); - void setUpRenderTarget(); + void setUpGpuBackedSurface(); bool onHandleChar(SkUnichar unichar) override; void tearDownBackend(); @@ -60,9 +61,9 @@ private: // support framework DeviceType fType; - SkSurface* fSurface; + sk_sp<SkSurface> fRasterSurface; GrContext* fContext; - GrRenderTarget* fRenderTarget; + sk_sp<SkSurface> fGpuSurface; AttachmentInfo fAttachmentInfo; const GrGLInterface* fInterface; |