Chinaunix首页 | 论坛 | 博客
  • 博客访问: 64125
  • 博文数量: 29
  • 博客积分: 1250
  • 博客等级: 中尉
  • 技术积分: 292
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-30 13:04
文章分类

全部博文(29)

文章存档

2009年(24)

2008年(5)

我的朋友

分类:

2009-03-18 16:00:49

Device           : SkDevice.h

//SkDevice.h

class SkDevice : public SkRefCnt {

public:

    SkDevice();

    /** Construct a new device, extracting the width/height/config/isOpaque values from

        the bitmap. If transferPixelOwnership is true, and the bitmap claims to own its

        own pixels (getOwnsPixels() == true), then transfer this responsibility to the

        device, and call setOwnsPixels(false) on the bitmap.

       

        Subclasses may override the destructor, which is virtual, even though this class

        doesn't have one. SkRefCnt does.

   

        @param bitmap   A copy of this bitmap is made and stored in the device

    */

    SkDevice(const SkBitmap& bitmap);

    // SkDeviceSkBitmap为基础进行构建width/height/config/isOpaque来自于SkBitmap

 

    /** Return the width of the device (in pixels).

    */

    int width() const { return fBitmap.width(); }

    /** Return the height of the device (in pixels).

    */

    int height() const { return fBitmap.height(); }

    /** Return the bitmap config of the device's pixels

    */

    SkBitmap::Config config() const { return fBitmap.getConfig(); }

    /** Returns true if the device's bitmap's config treats every pixels as

    implicitly opaque.

    */

    bool isOpaque() const { return fBitmap.isOpaque(); }

 

    /** Return the bounds of the device

    */

    void getBounds(SkIRect* bounds) const;

    //获得当前的device边界矩形,也就是(0,0) (SkBitmap的宽,高)的范围

   

    /** Return true if the specified rectangle intersects the bounds of the

        device. If sect is not NULL and there is an intersection, sect returns

        the intersection.

    */

    bool intersects(const SkIRect& r, SkIRect* sect = NULL) const;

    //判断sect和当前的device的边界是否相交,如果相交,则sect返回相交矩形。

    //这里涉及到两个矩形的的坐标系统问题。当前SkDevice的坐标是(0,0, width, height)这个坐标是由SkBitmap计算来的,

    //也就是它会始终固定在左上角。对应图像是没有坐标系统的,但对应矩形是有坐标系统的。一个矩形可以是图像上的某个部分,所有有坐标。

 

    /** Return the bitmap associated with this device. Call this each time you need

        to access the bitmap, as it notifies the subclass to perform any flushing

        etc. before you examine the pixels.

        @param changePixels set to true if the caller plans to change the pixels

        @return the device's bitmap

    */

    const SkBitmap& accessBitmap(bool changePixels);

    //获得当前和SkDevice相联系的SkBitmap。也就是说每个SkDevice必然对应一个SkBitmap,而且只能是一个。

 

    /** Helper to erase the entire device to the specified color (including

        alpha).

    */

    void eraseColor(SkColor eraseColor);

    //用指定的颜色擦除SkDevice对应的SkBitmap

 

    /** Called when this device is installed into a Canvas. Balanced by a call

        to unlockPixels() when the device is removed from a Canvas.

    */

    virtual void lockPixels();

    virtual void unlockPixels();

    //这两个函数说明SkDevice会被安装到Canvas中去,而且在Canvas使用的过程中必须lock当前的对应的SkBitmap

    //Canvas包含绘画的函数,也就会在这个SkBitmap中绘画。

    //但为什么要lock呢?因为一个位图数据可以被多重引用,所以在对位图数据访问(尤其是改变数据内容)时需要lockunlock.

 

    /** Called with the correct matrix and clip before this device is drawn

        to using those settings. If your subclass overrides this, be sure to

        call through to the base class as well.

    */

    virtual void setMatrixClip(const SkMatrix&, const SkRegion&);

    //首先SkMatrix应该是一个包含有裁剪,旋转,缩放等功能的类;而SkRegion是个区域,区域应该是由一系列的矩形所构成的。

    //从描述上看不出特别的作用,函数实现为空。

 

 

    //下面的是虚函数。

    /** Called when this device gains focus (i.e becomes the current device

        for drawing).

    */

    virtual void gainFocus(SkCanvas*) {}

 

    /** These are called inside the per-device-layer loop for each draw call.

     When these are called, we have already applied any saveLayer operations,

     and are handling any looping from the paint, and any effects from the

     DrawFilter.

     */

    virtual void drawPaint(const SkDraw&, const SkPaint& paint);

    virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count,

                            const SkPoint[], const SkPaint& paint);

    virtual void drawRect(const SkDraw&, const SkRect& r,

                          const SkPaint& paint);

    virtual void drawPath(const SkDraw&, const SkPath& path,

                          const SkPaint& paint);

    virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,

                            const SkMatrix& matrix, const SkPaint& paint);

    virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap,

                            int x, int y, const SkPaint& paint);

    virtual void drawText(const SkDraw&, const void* text, size_t len,

                          SkScalar x, SkScalar y, const SkPaint& paint);

    virtual void drawPosText(const SkDraw&, const void* text, size_t len,

                             const SkScalar pos[], SkScalar constY,

                             int scalarsPerPos, const SkPaint& paint);

    virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len,

                                const SkPath& path, const SkMatrix* matrix,

                                const SkPaint& paint);

    virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCount,

                              const SkPoint verts[], const SkPoint texs[],

                              const SkColor colors[], SkXfermode* xmode,

                              const uint16_t indices[], int indexCount,

                              const SkPaint& paint);

    virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y,

                            const SkPaint&);

 

protected:

    /** Update as needed the pixel value in the bitmap, so that the caller can access

        the pixels directly. Note: only the pixels field should be altered. The config/width/height/rowbytes

        must remain unchanged.

    */

    virtual void onAccessBitmap(SkBitmap*);

 

private:

    SkBitmap fBitmap;

    //这个SkBitmap也就是当前SkDevice对应的位图

};

 

SkDevice只是SkBitmap的一个外包装。当前SkDevice的参数基本可以从SkBitmap结构取得。所以SkDevice本身没有特别的逻辑,它存在的意义可能在于系统的架构。SkBitmap我们只能作为一个位图来看待,而SkDevice则可以作为一个绘图的实体。具体的逻辑关系需要以后再理清。

 

阅读(740) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~