1 /* 2 * Copyright 2010 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkGrPixelRef_DEFINED 9 #define SkGrPixelRef_DEFINED 10 11 #include "SkBitmap.h" 12 #include "SkPixelRef.h" 13 #include "GrTexture.h" 14 #include "GrRenderTarget.h" 15 16 17 /** 18 * Common baseclass that implements onLockPixels() by calling onReadPixels(). 19 * Since it has a copy, it always returns false for onLockPixelsAreWritable(). 20 */ 21 class SK_API SkROLockPixelsPixelRef : public SkPixelRef { 22 public: 23 SK_DECLARE_INST_COUNT(SkROLockPixelsPixelRef) 24 SkROLockPixelsPixelRef(const SkImageInfo&); 25 virtual ~SkROLockPixelsPixelRef(); 26 27 protected: 28 bool onNewLockPixels(LockRec*) override; 29 void onUnlockPixels() override; 30 bool onLockPixelsAreWritable() const override; // return false; 31 32 private: 33 SkBitmap fBitmap; 34 typedef SkPixelRef INHERITED; 35 }; 36 37 /** 38 * PixelRef that wraps a GrSurface 39 */ 40 class SK_API SkGrPixelRef : public SkROLockPixelsPixelRef { 41 public: 42 SK_DECLARE_INST_COUNT(SkGrPixelRef) 43 /** 44 * Constructs a pixel ref around a GrSurface. 45 */ 46 SkGrPixelRef(const SkImageInfo&, GrSurface*); 47 virtual ~SkGrPixelRef(); 48 49 // override from SkPixelRef 50 GrTexture* getTexture() override; 51 52 protected: 53 // overrides from SkPixelRef 54 bool onReadPixels(SkBitmap* dst, const SkIRect* subset) override; 55 virtual SkPixelRef* deepCopy(SkColorType, SkColorProfileType, 56 const SkIRect* subset) override; 57 58 private: 59 GrSurface* fSurface; 60 typedef SkROLockPixelsPixelRef INHERITED; 61 }; 62 63 #endif 64