diff options
author | 2011-01-11 18:59:23 +0000 | |
---|---|---|
committer | 2011-01-11 18:59:23 +0000 | |
commit | 7b201d22541957b128528bc481c6fd4ef0ed2258 (patch) | |
tree | 74c0a40df792b1799ecd397187d2eb2326893c18 /src/gpu | |
parent | 4b226023832011bc3bcdd1e5092ff0645ad0bdee (diff) |
expose gpu-device-factory
use that factory in gpucanvas, rather than overriding createDevice
note: I think we now don't need the canvas parameter in device-factory
git-svn-id: http://skia.googlecode.com/svn/trunk@684 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/SkGpuCanvas.cpp | 16 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 27 |
2 files changed, 29 insertions, 14 deletions
diff --git a/src/gpu/SkGpuCanvas.cpp b/src/gpu/SkGpuCanvas.cpp index 19bda4d943..5ca1736264 100644 --- a/src/gpu/SkGpuCanvas.cpp +++ b/src/gpu/SkGpuCanvas.cpp @@ -19,10 +19,15 @@ #include "SkGpuCanvas.h" #include "SkGpuDevice.h" +#include "SkGpuDeviceFactory.h" /////////////////////////////////////////////////////////////////////////////// -SkGpuCanvas::SkGpuCanvas(GrContext* context) { +static SkDeviceFactory* make_df(GrContext* context) { + return SkNEW_ARGS(SkGpuDeviceFactory, (context)); +} + +SkGpuCanvas::SkGpuCanvas(GrContext* context) : SkCanvas(make_df(context)) { SkASSERT(context); fContext = context; fContext->ref(); @@ -49,12 +54,3 @@ bool SkGpuCanvas::getViewport(SkIPoint* size) const { return true; } -SkDevice* SkGpuCanvas::createDevice(SkBitmap::Config config, int width, int height, - bool isOpaque, bool isLayer) { - SkBitmap bm; - bm.setConfig(config, width, height); - bm.setIsOpaque(isOpaque); - return new SkGpuDevice(this, bm, isLayer); -} - - diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 2d5634c29f..a4fb9869a0 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -18,8 +18,8 @@ #include "GrContext.h" #include "GrTextContext.h" -#include "SkGpuCanvas.h" #include "SkGpuDevice.h" +#include "SkGpuDeviceFactory.h" #include "SkGrTexturePixelRef.h" #include "SkDrawProcs.h" @@ -109,13 +109,14 @@ public: /////////////////////////////////////////////////////////////////////////////// -SkGpuDevice::SkGpuDevice(SkGpuCanvas* canvas, const SkBitmap& bitmap, bool isLayer) - : SkDevice(canvas, bitmap, false) { +SkGpuDevice::SkGpuDevice(GrContext* context, const SkBitmap& bitmap, bool isLayer) + : SkDevice(NULL, bitmap, false) { fNeedPrepareRenderTarget = false; fDrawProcs = NULL; - fContext = canvas->context(); + // should I ref() this, and then unref in destructor? <mrr> + fContext = context; fCache = NULL; fTexture = NULL; @@ -1046,4 +1047,22 @@ void SkGpuDevice::unlockCachedTexture(TexCache* cache) { this->context()->unlockTexture((GrTextureEntry*)cache); } +/////////////////////////////////////////////////////////////////////////////// + +SkGpuDeviceFactory::SkGpuDeviceFactory(GrContext* context) : fContext(context) { + context->ref(); +} + +SkGpuDeviceFactory::~SkGpuDeviceFactory() { + fContext->unref(); +} + +SkDevice* SkGpuDeviceFactory::newDevice(SkCanvas*, SkBitmap::Config config, + int width, int height, + bool isOpaque, bool isLayer) { + SkBitmap bm; + bm.setConfig(config, width, height); + bm.setIsOpaque(isOpaque); + return new SkGpuDevice(fContext, bm, isLayer); +} |