blob: 0a32f210647f7917e89768679ffc4e8f52819580 [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:
26 SkROLockPixelsPixelRef();
27 virtual ~SkROLockPixelsPixelRef();
28
29protected:
30 // override from SkPixelRef
31 virtual void* onLockPixels(SkColorTable** ptr);
32 virtual void onUnlockPixels();
33 virtual bool onLockPixelsAreWritable() const; // return false;
34
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 */
50 SkGrPixelRef(GrSurface* surface, bool transferCacheLock = false);
robertphillips@google.comd881bc12012-06-28 20:02:39 +000051 virtual ~SkGrPixelRef();
reed@google.comac10a2d2010-12-22 21:39:39 +000052
53 // override from SkPixelRef
robertphillips@google.comd881bc12012-06-28 20:02:39 +000054 virtual SkGpuTexture* getTexture() SK_OVERRIDE;
reed@google.comac10a2d2010-12-22 21:39:39 +000055
djsollen@google.com5370cd92012-03-28 20:47:01 +000056 SK_DECLARE_UNFLATTENABLE_OBJECT()
57
reed@google.comac10a2d2010-12-22 21:39:39 +000058protected:
robertphillips@google.comd881bc12012-06-28 20:02:39 +000059 // overrides from SkPixelRef
60 virtual bool onReadPixels(SkBitmap* dst, const SkIRect* subset) SK_OVERRIDE;
scroggo@google.coma2a31922012-12-07 19:14:45 +000061 virtual SkPixelRef* deepCopy(SkBitmap::Config dstConfig, const SkIRect* subset) SK_OVERRIDE;
senorblanco@chromium.orgef843cd2011-12-02 19:11:17 +000062
reed@google.comac10a2d2010-12-22 21:39:39 +000063private:
robertphillips@google.comd881bc12012-06-28 20:02:39 +000064 GrSurface* fSurface;
bsalomon@google.com8090e652012-08-28 15:07:11 +000065 bool fUnlock; // if true the pixel ref owns a texture cache lock on fSurface
66
reed@google.com9c49bc32011-07-07 13:42:37 +000067 typedef SkROLockPixelsPixelRef INHERITED;
bsalomon@google.com669fdc42011-04-05 17:08:27 +000068};
69
reed@google.comac10a2d2010-12-22 21:39:39 +000070#endif
71