diff --git a/include/views/SkWindow.h b/include/views/SkWindow.h index 2a9315dc8c..40cc5ecb31 100644 --- a/include/views/SkWindow.h +++ b/include/views/SkWindow.h @@ -21,8 +21,7 @@ #endif //#define USE_GX_SCREEN -class SkCanvas; - +class SkSurface; class SkOSMenu; class SkWindow : public SkView { @@ -59,7 +58,7 @@ public: void preConcat(const SkMatrix&); void postConcat(const SkMatrix&); - virtual SkCanvas* createCanvas(); + virtual SkSurface* createSurface(); virtual void onPDFSaved(const char title[], const char desc[], const char path[]) {} diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp index 9d7e727ce5..08e7240f98 100644 --- a/samplecode/SampleApp.cpp +++ b/samplecode/SampleApp.cpp @@ -271,17 +271,14 @@ public: fBackend = kNone_BackEndType; } - virtual SkCanvas* createCanvas(SampleWindow::DeviceType dType, - SampleWindow* win) { + virtual SkSurface* createSurface(SampleWindow::DeviceType dType, + SampleWindow* win) SK_OVERRIDE { #if SK_SUPPORT_GPU if (IsGpuDeviceType(dType) && fCurContext) { - SkAutoTUnref device(SkGpuDevice::Create(fCurRenderTarget)); - return new SkCanvas(device); - } else -#endif - { - return NULL; + return SkSurface::NewRenderTargetDirect(fCurRenderTarget); } +#endif + return NULL; } virtual void publishCanvas(SampleWindow::DeviceType dType, diff --git a/samplecode/SampleApp.h b/samplecode/SampleApp.h index e08ff8a8f4..abb1f24002 100644 --- a/samplecode/SampleApp.h +++ b/samplecode/SampleApp.h @@ -76,7 +76,7 @@ public: // called before drawing. should install correct device // type on the canvas. Will skip drawing if returns false. - virtual SkCanvas* createCanvas(DeviceType dType, SampleWindow* win) = 0; + virtual SkSurface* createSurface(DeviceType dType, SampleWindow* win) = 0; // called after drawing, should get the results onto the // screen. @@ -100,18 +100,18 @@ public: SampleWindow(void* hwnd, int argc, char** argv, DeviceManager*); virtual ~SampleWindow(); - virtual SkCanvas* createCanvas() SK_OVERRIDE { - SkCanvas* canvas = NULL; + virtual SkSurface* createSurface() SK_OVERRIDE { + SkSurface* surface = NULL; if (fDevManager) { - canvas = fDevManager->createCanvas(fDeviceType, this); + surface = fDevManager->createSurface(fDeviceType, this); } - if (NULL == canvas) { - canvas = this->INHERITED::createCanvas(); + if (NULL == surface) { + surface = this->INHERITED::createSurface(); } - return canvas; + return surface; } - virtual void draw(SkCanvas* canvas); + virtual void draw(SkCanvas*) SK_OVERRIDE; void setDeviceType(DeviceType type); void toggleRendering(); diff --git a/samplecode/SampleBitmapRect.cpp b/samplecode/SampleBitmapRect.cpp index cf1196c62d..006b919554 100644 --- a/samplecode/SampleBitmapRect.cpp +++ b/samplecode/SampleBitmapRect.cpp @@ -24,12 +24,6 @@ #include "SkOSFile.h" #include "SkStream.h" -#if SK_SUPPORT_GPU -#include "SkGpuDevice.h" -#else -class GrContext; -#endif - #define INT_SIZE 64 #define SCALAR_SIZE SkIntToScalar(INT_SIZE) diff --git a/src/views/SkWindow.cpp b/src/views/SkWindow.cpp index 99c2d30e8a..90ef2804e6 100644 --- a/src/views/SkWindow.cpp +++ b/src/views/SkWindow.cpp @@ -1,14 +1,14 @@ - /* * Copyright 2011 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ + #include "SkWindow.h" #include "SkCanvas.h" -#include "SkDevice.h" #include "SkOSMenu.h" +#include "SkSurface.h" #include "SkSystemEventTypes.h" #include "SkTime.h" @@ -32,8 +32,9 @@ SkWindow::~SkWindow() { fMenus.deleteAll(); } -SkCanvas* SkWindow::createCanvas() { - return new SkCanvas(this->getBitmap()); +SkSurface* SkWindow::createSurface() { + const SkBitmap& bm = this->getBitmap(); + return SkSurface::NewRasterDirect(bm.info(), bm.getPixels(), bm.rowBytes()); } void SkWindow::setMatrix(const SkMatrix& matrix) { @@ -126,7 +127,8 @@ bool SkWindow::update(SkIRect* updateArea) { bm.setPixels(buffer); #endif - SkAutoTUnref canvas(this->createCanvas()); + SkAutoTUnref surface(this->createSurface()); + SkCanvas* canvas = surface->getCanvas(); canvas->clipRegion(fDirtyRgn); if (updateArea) diff --git a/src/views/mac/SkNSView.mm b/src/views/mac/SkNSView.mm index 6347d46408..67141679db 100644 --- a/src/views/mac/SkNSView.mm +++ b/src/views/mac/SkNSView.mm @@ -1,4 +1,3 @@ - /* * Copyright 2011 Google Inc. * @@ -8,6 +7,7 @@ #import "SkNSView.h" #include "SkCanvas.h" +#include "SkSurface.h" #include "SkCGUtils.h" #include "SkEvent.h" SK_COMPILE_ASSERT(SK_SUPPORT_GPU, not_implemented_for_non_gpu_build); @@ -129,8 +129,8 @@ SK_COMPILE_ASSERT(SK_SUPPORT_GPU, not_implemented_for_non_gpu_build); - (void)drawSkia { fRedrawRequestPending = false; if (fWind) { - SkAutoTUnref canvas(fWind->createCanvas()); - fWind->draw(canvas); + SkAutoTUnref surface(fWind->createSurface()); + fWind->draw(surface->getCanvas()); #ifdef FORCE_REDRAW fWind->inval(NULL); #endif