blob: 4d33b9d06b01498e9891db2e3dd2b43bd414016b [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.comac10a2d2010-12-22 21:39:39 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2010 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@google.comac10a2d2010-12-22 21:39:39 +00007 */
8
9
epoger@google.comec3ed6a2011-07-28 14:26:00 +000010
robertphillips@google.comd881bc12012-06-28 20:02:39 +000011#ifndef SkGrPixelRef_DEFINED
12#define SkGrPixelRef_DEFINED
reed@google.comac10a2d2010-12-22 21:39:39 +000013
reed@google.com9c49bc32011-07-07 13:42:37 +000014#include "SkBitmap.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000015#include "SkPixelRef.h"
bsalomon@google.combbfa1002011-08-16 15:13:54 +000016#include "GrTexture.h"
17#include "GrRenderTarget.h"
18
reed@google.comac10a2d2010-12-22 21:39:39 +000019
reed@google.com9c49bc32011-07-07 13:42:37 +000020/**
21 * Common baseclass that implements onLockPixels() by calling onReadPixels().
22 * Since it has a copy, it always returns false for onLockPixelsAreWritable().
23 */
senorblanco@chromium.org29767652012-02-08 20:27:16 +000024class SK_API SkROLockPixelsPixelRef : public SkPixelRef {
reed@google.com9c49bc32011-07-07 13:42:37 +000025public:
reed@google.com473f0aa2013-12-06 20:31:45 +000026 SkROLockPixelsPixelRef(const SkImageInfo&);
reed@google.com9c49bc32011-07-07 13:42:37 +000027 virtual ~SkROLockPixelsPixelRef();
28
29protected:
reed@google.com473f0aa2013-12-06 20:31:45 +000030 virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE;
31 virtual void onUnlockPixels() SK_OVERRIDE;
32 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE; // return false;
reed@google.com9c49bc32011-07-07 13:42:37 +000033
34private:
35 SkBitmap fBitmap;
36 typedef SkPixelRef INHERITED;
37};
38
39/**
robertphillips@google.comd881bc12012-06-28 20:02:39 +000040 * PixelRef that wraps a GrSurface
reed@google.com9c49bc32011-07-07 13:42:37 +000041 */
robertphillips@google.comd881bc12012-06-28 20:02:39 +000042class SK_API SkGrPixelRef : public SkROLockPixelsPixelRef {
reed@google.comac10a2d2010-12-22 21:39:39 +000043public:
bsalomon@google.com8090e652012-08-28 15:07:11 +000044 /**
45 * Constructs a pixel ref around a GrSurface. If the caller has locked the GrSurface in the
46 * cache and would like the pixel ref to unlock it in its destructor then transferCacheLock
47 * should be set to true.
48 */
reed@google.com473f0aa2013-12-06 20:31:45 +000049 SkGrPixelRef(const SkImageInfo&, GrSurface*, bool transferCacheLock = false);
robertphillips@google.comd881bc12012-06-28 20:02:39 +000050 virtual ~SkGrPixelRef();
reed@google.comac10a2d2010-12-22 21:39:39 +000051
52 // override from SkPixelRef
commit-bot@chromium.orgb8d00db2013-06-26 19:18:23 +000053 virtual GrTexture* getTexture() SK_OVERRIDE;
reed@google.comac10a2d2010-12-22 21:39:39 +000054
djsollen@google.com5370cd92012-03-28 20:47:01 +000055 SK_DECLARE_UNFLATTENABLE_OBJECT()
56
reed@google.comac10a2d2010-12-22 21:39:39 +000057protected:
robertphillips@google.comd881bc12012-06-28 20:02:39 +000058 // overrides from SkPixelRef
59 virtual bool onReadPixels(SkBitmap* dst, const SkIRect* subset) SK_OVERRIDE;
scroggo@google.coma2a31922012-12-07 19:14:45 +000060 virtual SkPixelRef* deepCopy(SkBitmap::Config dstConfig, const SkIRect* subset) SK_OVERRIDE;
senorblanco@chromium.orgef843cd2011-12-02 19:11:17 +000061
reed@google.comac10a2d2010-12-22 21:39:39 +000062private:
robertphillips@google.comd881bc12012-06-28 20:02:39 +000063 GrSurface* fSurface;
bsalomon@google.com8090e652012-08-28 15:07:11 +000064 bool fUnlock; // if true the pixel ref owns a texture cache lock on fSurface
65
reed@google.com9c49bc32011-07-07 13:42:37 +000066 typedef SkROLockPixelsPixelRef INHERITED;
bsalomon@google.com669fdc42011-04-05 17:08:27 +000067};
68
reed@google.comac10a2d2010-12-22 21:39:39 +000069#endif