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
This commit is contained in:
reed@google.com 2011-01-11 18:59:23 +00:00
parent 4b22602383
commit 7b201d2254
5 changed files with 83 additions and 39 deletions

View File

@ -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;

View File

@ -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();

View File

@ -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

View File

@ -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);
}

View File

@ -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);
}