gfx/skia/trunk/src/image/SkSurface_Picture.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/image/SkSurface_Picture.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,92 @@
     1.4 +/*
     1.5 + * Copyright 2012 Google Inc.
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +#include "SkSurface_Base.h"
    1.12 +#include "SkCanvas.h"
    1.13 +#include "SkImagePriv.h"
    1.14 +#include "SkPicture.h"
    1.15 +
    1.16 +/**
    1.17 + *  What does it mean to ask for more than one canvas from a picture?
    1.18 + *  How do we return an Image and then "continue" recording?
    1.19 + */
    1.20 +class SkSurface_Picture : public SkSurface_Base {
    1.21 +public:
    1.22 +    SkSurface_Picture(int width, int height);
    1.23 +    virtual ~SkSurface_Picture();
    1.24 +
    1.25 +    virtual SkCanvas* onNewCanvas() SK_OVERRIDE;
    1.26 +    virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE;
    1.27 +    virtual SkImage* onNewImageSnapshot() SK_OVERRIDE;
    1.28 +    virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y,
    1.29 +                        const SkPaint*) SK_OVERRIDE;
    1.30 +    virtual void onCopyOnWrite(ContentChangeMode) SK_OVERRIDE;
    1.31 +
    1.32 +private:
    1.33 +    SkPicture*  fPicture;
    1.34 +
    1.35 +    typedef SkSurface_Base INHERITED;
    1.36 +};
    1.37 +
    1.38 +///////////////////////////////////////////////////////////////////////////////
    1.39 +
    1.40 +SkSurface_Picture::SkSurface_Picture(int width, int height) : INHERITED(width, height) {
    1.41 +    fPicture = NULL;
    1.42 +}
    1.43 +
    1.44 +SkSurface_Picture::~SkSurface_Picture() {
    1.45 +    SkSafeUnref(fPicture);
    1.46 +}
    1.47 +
    1.48 +SkCanvas* SkSurface_Picture::onNewCanvas() {
    1.49 +    if (!fPicture) {
    1.50 +        fPicture = SkNEW(SkPicture);
    1.51 +    }
    1.52 +    SkCanvas* canvas = fPicture->beginRecording(this->width(), this->height());
    1.53 +    canvas->ref();  // our caller will call unref()
    1.54 +    return canvas;
    1.55 +}
    1.56 +
    1.57 +SkSurface* SkSurface_Picture::onNewSurface(const SkImageInfo& info) {
    1.58 +    return SkSurface::NewPicture(info.fWidth, info.fHeight);
    1.59 +}
    1.60 +
    1.61 +SkImage* SkSurface_Picture::onNewImageSnapshot() {
    1.62 +    if (fPicture) {
    1.63 +        return SkNewImageFromPicture(fPicture);
    1.64 +    } else {
    1.65 +        SkImageInfo info;
    1.66 +        info.fWidth = info.fHeight = 0;
    1.67 +        info.fColorType = kPMColor_SkColorType;
    1.68 +        info.fAlphaType = kOpaque_SkAlphaType;
    1.69 +        return SkImage::NewRasterCopy(info, NULL, 0);
    1.70 +    }
    1.71 +}
    1.72 +
    1.73 +void SkSurface_Picture::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
    1.74 +                               const SkPaint* paint) {
    1.75 +    if (!fPicture) {
    1.76 +        return;
    1.77 +    }
    1.78 +    SkImagePrivDrawPicture(canvas, fPicture, x, y, paint);
    1.79 +}
    1.80 +
    1.81 +void SkSurface_Picture::onCopyOnWrite(ContentChangeMode /*mode*/) {
    1.82 +    // We always spawn a copy of the recording picture when we
    1.83 +    // are asked for a snapshot, so we never need to do anything here.
    1.84 +}
    1.85 +
    1.86 +///////////////////////////////////////////////////////////////////////////////
    1.87 +
    1.88 +
    1.89 +SkSurface* SkSurface::NewPicture(int width, int height) {
    1.90 +    if ((width | height) < 0) {
    1.91 +        return NULL;
    1.92 +    }
    1.93 +
    1.94 +    return SkNEW_ARGS(SkSurface_Picture, (width, height));
    1.95 +}

mercurial