diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-01-11 18:59:23 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-01-11 18:59:23 +0000 |
commit | 7b201d22541957b128528bc481c6fd4ef0ed2258 (patch) | |
tree | 74c0a40df792b1799ecd397187d2eb2326893c18 | |
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
-rw-r--r-- | include/gpu/SkGpuCanvas.h | 18 | ||||
-rw-r--r-- | include/gpu/SkGpuDevice.h | 19 | ||||
-rw-r--r-- | include/gpu/SkGpuDeviceFactory.h | 42 | ||||
-rw-r--r-- | src/gpu/SkGpuCanvas.cpp | 16 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 27 |
5 files changed, 83 insertions, 39 deletions
diff --git a/include/gpu/SkGpuCanvas.h b/include/gpu/SkGpuCanvas.h index e8e6e7ae10..8194e12123 100644 --- a/include/gpu/SkGpuCanvas.h +++ b/include/gpu/SkGpuCanvas.h @@ -29,38 +29,26 @@ class GrContext; class SkGpuCanvas : public SkCanvas { public: /** - * The GrContext object is reference counted. When passed to our - * constructor, its reference count is incremented. In our destructor, the + * The GrContext object is reference counted. When passed to our + * constructor, its reference count is incremented. In our destructor, the * GrGpu's reference count will be decremented. */ explicit SkGpuCanvas(GrContext*); virtual ~SkGpuCanvas(); /** - * Return our GrContext instance - */ - GrContext* context() const { return fContext; } - - /** * Override from SkCanvas. Returns true, and if not-null, sets size to * be the width/height of our viewport. */ virtual bool getViewport(SkIPoint* size) const; - /** - * Override from SkCanvas. Returns a new device of the correct subclass, - * as determined by the GrGpu passed to our constructor. - */ - virtual SkDevice* createDevice(SkBitmap::Config, int width, int height, - bool isOpaque, bool isLayer); - #if 0 virtual int saveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags = kARGB_ClipLayer_SaveFlag) { return this->save(flags); } #endif - + private: GrContext* fContext; diff --git a/include/gpu/SkGpuDevice.h b/include/gpu/SkGpuDevice.h index e42e99709d..141ed96423 100644 --- a/include/gpu/SkGpuDevice.h +++ b/include/gpu/SkGpuDevice.h @@ -23,7 +23,6 @@ #include "SkRegion.h" struct SkDrawProcs; -class SkGpuCanvas; struct GrSkDrawProcs; class GrTextContext; @@ -33,9 +32,9 @@ class GrTextContext; */ class SkGpuDevice : public SkDevice { public: - SkGpuDevice(SkGpuCanvas*, const SkBitmap& bitmap, bool isLayer); + SkGpuDevice(GrContext*, const SkBitmap& bitmap, bool isLayer); virtual ~SkGpuDevice(); - + GrContext* context() const { return fContext; } /** @@ -46,7 +45,7 @@ public: * is returned. */ intptr_t getLayerTextureHandle() const; - + /** * Attaches the device to a rendering surface. This device will then render * to the surface. @@ -70,7 +69,7 @@ public: virtual bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap); virtual void writePixels(const SkBitmap& bitmap, int x, int y); - + virtual void setMatrixClip(const SkMatrix& matrix, const SkRegion& clip); virtual void drawPaint(const SkDraw&, const SkPaint& paint); @@ -101,10 +100,10 @@ public: const SkPaint& paint); virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y, const SkPaint&); - + virtual void flush() { fContext->flush(false); } - - /** + + /** * Make's this device's rendertarget current in the underlying 3D API. * Also implicitly flushes. */ @@ -145,14 +144,14 @@ private: GrRenderTarget* fRenderTarget; bool fNeedClear; bool fNeedPrepareRenderTarget; - + SkDrawProcs* initDrawForText(const SkPaint&, GrTextContext*); bool bindDeviceAsTexture(SkPoint* max); void prepareRenderTarget(const SkDraw&); void internalDrawBitmap(const SkDraw&, const SkBitmap&, const SkIRect&, const SkMatrix&, const SkPaint&); - + class AutoPaintShader { public: AutoPaintShader(); diff --git a/include/gpu/SkGpuDeviceFactory.h b/include/gpu/SkGpuDeviceFactory.h new file mode 100644 index 0000000000..dd57da2c75 --- /dev/null +++ b/include/gpu/SkGpuDeviceFactory.h @@ -0,0 +1,42 @@ +/* + Copyright 2010 Google Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#ifndef SkGpuDeviceFactory_DEFINED +#define SkGpuDeviceFactory_DEFINED + +#include "SkDevice.h" + +class GrContext; + +class SkGpuDeviceFactory : public SkDeviceFactory { +public: + /** + * The constructor will ref() the context, passing it to each device + * that it creates. It will be unref()'d in the destructor + */ + SkGpuDeviceFactory(GrContext*); + + virtual ~SkGpuDeviceFactory(); + + virtual SkDevice* newDevice(SkCanvas*, SkBitmap::Config, int width, + int height, bool isOpaque, bool isLayer); + +private: + GrContext* fContext; +}; + +#endif + 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); +} |