diff options
-rw-r--r-- | include/views/SkWindow.h | 1 | ||||
-rw-r--r-- | samplecode/SampleApp.cpp | 17 | ||||
-rw-r--r-- | samplecode/SampleApp.h | 6 | ||||
-rw-r--r-- | src/views/SkWindow.cpp | 4 | ||||
-rw-r--r-- | src/views/mac/SkNSView.mm | 7 |
5 files changed, 20 insertions, 15 deletions
diff --git a/include/views/SkWindow.h b/include/views/SkWindow.h index 8b6c29186b..e744b19d9e 100644 --- a/include/views/SkWindow.h +++ b/include/views/SkWindow.h @@ -79,6 +79,7 @@ public: void postConcat(const SkMatrix&); virtual sk_sp<SkSurface> makeSurface(); + virtual void drawIntoSurface(); #if SK_SUPPORT_GPU sk_sp<SkSurface> makeGpuBackedSurface(const AttachmentInfo& attachmentInfo, diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp index 1676fc3b13..102c67a90b 100644 --- a/samplecode/SampleApp.cpp +++ b/samplecode/SampleApp.cpp @@ -332,8 +332,8 @@ public: return nullptr; } - void publishCanvas(SampleWindow::DeviceType dType, - SkCanvas* renderingCanvas, SampleWindow* win) override { + void publishCanvas(SampleWindow::DeviceType dType, SkSurface* surface, + SampleWindow* win) override { #if SK_SUPPORT_GPU if (!IsGpuDeviceType(dType) || kRGBA_F16_SkColorType == win->info().colorType() || @@ -345,7 +345,7 @@ public: auto data = SkData::MakeUninitialized(size); SkASSERT(data); - if (!renderingCanvas->readPixels(info, data->writable_data(), rowBytes, 0, 0)) { + if (!surface->readPixels(info, data->writable_data(), rowBytes, 0, 0)) { SkDEBUGFAIL("Failed to read canvas pixels"); return; } @@ -1091,6 +1091,14 @@ static void drawText(SkCanvas* canvas, SkString str, SkScalar left, SkScalar top #include "SkDeferredCanvas.h" #include "SkDumpCanvas.h" +void SampleWindow::drawIntoSurface() { + auto surf = this->makeSurface(); + + this->draw(surf->getCanvas()); + + fDevManager->publishCanvas(fDeviceType, surf.get(), this); +} + void SampleWindow::draw(SkCanvas* canvas) { std::unique_ptr<SkThreadedBMPDevice> tDev; std::unique_ptr<SkCanvas> tCanvas; @@ -1164,9 +1172,6 @@ void SampleWindow::draw(SkCanvas* canvas) { } canvas->flush(); - - // do this last - fDevManager->publishCanvas(fDeviceType, canvas, this); } static float clipW = 200; diff --git a/samplecode/SampleApp.h b/samplecode/SampleApp.h index 6ddb5c5a0d..954b855d27 100644 --- a/samplecode/SampleApp.h +++ b/samplecode/SampleApp.h @@ -92,9 +92,7 @@ public: // called after drawing, should get the results onto the // screen. - virtual void publishCanvas(DeviceType dType, - SkCanvas* canvas, - SampleWindow* win) = 0; + virtual void publishCanvas(DeviceType, SkSurface*, SampleWindow*) = 0; // called when window changes size, guaranteed to be called // at least once before first draw (after init) @@ -127,6 +125,8 @@ public: return surface; } + void drawIntoSurface() override; + void draw(SkCanvas*) override; void setDeviceType(DeviceType type); diff --git a/src/views/SkWindow.cpp b/src/views/SkWindow.cpp index ba06a1f3c2..f01368b265 100644 --- a/src/views/SkWindow.cpp +++ b/src/views/SkWindow.cpp @@ -35,6 +35,10 @@ sk_sp<SkSurface> SkWindow::makeSurface() { return SkSurface::MakeRasterDirect(bm.info(), bm.getPixels(), bm.rowBytes(), &fSurfaceProps); } +void SkWindow::drawIntoSurface() { + this->draw(this->makeSurface()->getCanvas()); +} + void SkWindow::setMatrix(const SkMatrix& matrix) { if (fMatrix != matrix) { fMatrix = matrix; diff --git a/src/views/mac/SkNSView.mm b/src/views/mac/SkNSView.mm index 64c02ca2a5..7366c5c1c8 100644 --- a/src/views/mac/SkNSView.mm +++ b/src/views/mac/SkNSView.mm @@ -13,7 +13,6 @@ static_assert(SK_SUPPORT_GPU, "not_implemented_for_non_gpu_build"); #include <OpenGL/gl.h> -//#define FORCE_REDRAW // Can be dropped when we no longer support 10.6. #if defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 #define RETINA_API_AVAILABLE 1 @@ -140,11 +139,7 @@ BOOL fRedrawRequestPending; - (void)drawSkia { fRedrawRequestPending = false; if (fWind) { - sk_sp<SkSurface> surface(fWind->makeSurface()); - fWind->draw(surface->getCanvas()); -#ifdef FORCE_REDRAW - fWind->inval(NULL); -#endif + fWind->drawIntoSurface(); } } |