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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/image/SkImage_Gpu.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,77 @@
     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 "SkImage_Base.h"
    1.12 +#include "SkImagePriv.h"
    1.13 +#include "SkBitmap.h"
    1.14 +#include "SkCanvas.h"
    1.15 +#include "GrContext.h"
    1.16 +#include "GrTexture.h"
    1.17 +#include "SkGrPixelRef.h"
    1.18 +
    1.19 +class SkImage_Gpu : public SkImage_Base {
    1.20 +public:
    1.21 +    SK_DECLARE_INST_COUNT(SkImage_Gpu)
    1.22 +
    1.23 +    explicit SkImage_Gpu(const SkBitmap&);
    1.24 +    virtual ~SkImage_Gpu();
    1.25 +
    1.26 +    virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) SK_OVERRIDE;
    1.27 +    virtual void onDrawRectToRect(SkCanvas*, const SkRect* src, const SkRect& dst, const SkPaint*) SK_OVERRIDE;
    1.28 +    virtual GrTexture* onGetTexture() SK_OVERRIDE;
    1.29 +    virtual bool getROPixels(SkBitmap*) const SK_OVERRIDE;
    1.30 +
    1.31 +    GrTexture* getTexture() { return fBitmap.getTexture(); }
    1.32 +
    1.33 +private:
    1.34 +    SkBitmap    fBitmap;
    1.35 +
    1.36 +    typedef SkImage_Base INHERITED;
    1.37 +};
    1.38 +
    1.39 +///////////////////////////////////////////////////////////////////////////////
    1.40 +
    1.41 +SkImage_Gpu::SkImage_Gpu(const SkBitmap& bitmap)
    1.42 +    : INHERITED(bitmap.width(), bitmap.height())
    1.43 +    , fBitmap(bitmap) {
    1.44 +    SkASSERT(NULL != fBitmap.getTexture());
    1.45 +}
    1.46 +
    1.47 +SkImage_Gpu::~SkImage_Gpu() {
    1.48 +}
    1.49 +
    1.50 +void SkImage_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
    1.51 +                         const SkPaint* paint) {
    1.52 +    canvas->drawBitmap(fBitmap, x, y, paint);
    1.53 +}
    1.54 +
    1.55 +void SkImage_Gpu::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const SkRect& dst,
    1.56 +                         const SkPaint* paint) {
    1.57 +    canvas->drawBitmapRectToRect(fBitmap, src, dst, paint);
    1.58 +}
    1.59 +
    1.60 +GrTexture* SkImage_Gpu::onGetTexture() {
    1.61 +    return fBitmap.getTexture();
    1.62 +}
    1.63 +
    1.64 +bool SkImage_Gpu::getROPixels(SkBitmap* dst) const {
    1.65 +    return fBitmap.copyTo(dst, kPMColor_SkColorType);
    1.66 +}
    1.67 +
    1.68 +///////////////////////////////////////////////////////////////////////////////
    1.69 +
    1.70 +SkImage* SkImage::NewTexture(const SkBitmap& bitmap) {
    1.71 +    if (NULL == bitmap.getTexture()) {
    1.72 +        return NULL;
    1.73 +    }
    1.74 +
    1.75 +    return SkNEW_ARGS(SkImage_Gpu, (bitmap));
    1.76 +}
    1.77 +
    1.78 +GrTexture* SkTextureImageGetTexture(SkImage* image) {
    1.79 +    return ((SkImage_Gpu*)image)->getTexture();
    1.80 +}

mercurial