blob: c29c27fb3bdc0b3d0963fcaa0fda82ef3d0285a1 [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.com398337b2013-12-11 21:22:39 +000026 SkROLockPixelsPixelRef();
reed@google.com9c49bc32011-07-07 13:42:37 +000027 virtual ~SkROLockPixelsPixelRef();
28
29protected:
reed@google.com398337b2013-12-11 21:22:39 +000030 // override from SkPixelRef
31 virtual void* onLockPixels(SkColorTable** ptr);
32 virtual void onUnlockPixels();
33 virtual bool onLockPixelsAreWritable() const; // return false;
reed@google.com9c49bc32011-07-07 13:42:37 +000034
35private:
36 SkBitmap fBitmap;
37 typedef SkPixelRef INHERITED;
38};
39
40/**
robertphillips@google.comd881bc12012-06-28 20:02:39 +000041 * PixelRef that wraps a GrSurface
reed@google.com9c49bc32011-07-07 13:42:37 +000042 */
robertphillips@google.comd881bc12012-06-28 20:02:39 +000043class SK_API SkGrPixelRef : public SkROLockPixelsPixelRef {
reed@google.comac10a2d2010-12-22 21:39:39 +000044public:
bsalomon@google.com8090e652012-08-28 15:07:11 +000045 /**
46 * Constructs a pixel ref around a GrSurface. If the caller has locked the GrSurface in the
47 * cache and would like the pixel ref to unlock it in its destructor then transferCacheLock
48 * should be set to true.
49 */
reed@google.com398337b2013-12-11 21:22:39 +000050 SkGrPixelRef(GrSurface*, bool transferCacheLock = false);
reed@google.com61867872013-12-09 13:41:06 +000051 SkGrPixelRef(const SkImageInfo&, GrSurface*, bool transferCacheLock = false);
robertphillips@google.comd881bc12012-06-28 20:02:39 +000052 virtual ~SkGrPixelRef();
reed@google.comac10a2d2010-12-22 21:39:39 +000053
54 // override from SkPixelRef
commit-bot@chromium.orgb8d00db2013-06-26 19:18:23 +000055 virtual GrTexture* getTexture() SK_OVERRIDE;
reed@google.comac10a2d2010-12-22 21:39:39 +000056
djsollen@google.com5370cd92012-03-28 20:47:01 +000057 SK_DECLARE_UNFLATTENABLE_OBJECT()
58
reed@google.comac10a2d2010-12-22 21:39:39 +000059protected:
robertphillips@google.comd881bc12012-06-28 20:02:39 +000060 // overrides from SkPixelRef
61 virtual bool onReadPixels(SkBitmap* dst, const SkIRect* subset) SK_OVERRIDE;
scroggo@google.coma2a31922012-12-07 19:14:45 +000062 virtual SkPixelRef* deepCopy(SkBitmap::Config dstConfig, const SkIRect* subset) SK_OVERRIDE;
senorblanco@chromium.orgef843cd2011-12-02 19:11:17 +000063
reed@google.comac10a2d2010-12-22 21:39:39 +000064private:
robertphillips@google.comd881bc12012-06-28 20:02:39 +000065 GrSurface* fSurface;
bsalomon@google.com8090e652012-08-28 15:07:11 +000066 bool fUnlock; // if true the pixel ref owns a texture cache lock on fSurface
67
reed@google.com9c49bc32011-07-07 13:42:37 +000068 typedef SkROLockPixelsPixelRef INHERITED;
bsalomon@google.com669fdc42011-04-05 17:08:27 +000069};
70
reed@google.comac10a2d2010-12-22 21:39:39 +000071#endif