michael@0: /* michael@0: * Copyright 2010 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef SkGrPixelRef_DEFINED michael@0: #define SkGrPixelRef_DEFINED michael@0: michael@0: #include "SkBitmap.h" michael@0: #include "SkPixelRef.h" michael@0: #include "GrTexture.h" michael@0: #include "GrRenderTarget.h" michael@0: michael@0: michael@0: /** michael@0: * Common baseclass that implements onLockPixels() by calling onReadPixels(). michael@0: * Since it has a copy, it always returns false for onLockPixelsAreWritable(). michael@0: */ michael@0: class SK_API SkROLockPixelsPixelRef : public SkPixelRef { michael@0: public: michael@0: SK_DECLARE_INST_COUNT(SkROLockPixelsPixelRef) michael@0: SkROLockPixelsPixelRef(const SkImageInfo&); michael@0: virtual ~SkROLockPixelsPixelRef(); michael@0: michael@0: protected: michael@0: virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE; michael@0: virtual void onUnlockPixels() SK_OVERRIDE; michael@0: virtual bool onLockPixelsAreWritable() const SK_OVERRIDE; // return false; michael@0: michael@0: private: michael@0: SkBitmap fBitmap; michael@0: typedef SkPixelRef INHERITED; michael@0: }; michael@0: michael@0: /** michael@0: * PixelRef that wraps a GrSurface michael@0: */ michael@0: class SK_API SkGrPixelRef : public SkROLockPixelsPixelRef { michael@0: public: michael@0: SK_DECLARE_INST_COUNT(SkGrPixelRef) michael@0: /** michael@0: * Constructs a pixel ref around a GrSurface. If the caller has locked the GrSurface in the michael@0: * cache and would like the pixel ref to unlock it in its destructor then transferCacheLock michael@0: * should be set to true. michael@0: */ michael@0: SkGrPixelRef(const SkImageInfo&, GrSurface*, bool transferCacheLock = false); michael@0: virtual ~SkGrPixelRef(); michael@0: michael@0: // override from SkPixelRef michael@0: virtual GrTexture* getTexture() SK_OVERRIDE; michael@0: michael@0: SK_DECLARE_UNFLATTENABLE_OBJECT() michael@0: michael@0: protected: michael@0: // overrides from SkPixelRef michael@0: virtual bool onReadPixels(SkBitmap* dst, const SkIRect* subset) SK_OVERRIDE; michael@0: virtual SkPixelRef* deepCopy(SkBitmap::Config dstConfig, const SkIRect* subset) SK_OVERRIDE; michael@0: michael@0: private: michael@0: GrSurface* fSurface; michael@0: bool fUnlock; // if true the pixel ref owns a texture cache lock on fSurface michael@0: michael@0: typedef SkROLockPixelsPixelRef INHERITED; michael@0: }; michael@0: michael@0: #endif