blob: 1df10cb5a64f352d502d05d3cf61949c682a33c4 [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
reed@google.comac10a2d2010-12-22 21:39:39 +000011#ifndef SkGrTexturePixelRef_DEFINED
12#define SkGrTexturePixelRef_DEFINED
13
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 */
24class SkROLockPixelsPixelRef : public SkPixelRef {
25public:
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/**
41 * PixelRef that wraps a GrTexture
42 */
43class SkGrTexturePixelRef : public SkROLockPixelsPixelRef {
reed@google.comac10a2d2010-12-22 21:39:39 +000044public:
45 SkGrTexturePixelRef(GrTexture*);
46 virtual ~SkGrTexturePixelRef();
47
48 // override from SkPixelRef
reed@google.com9c49bc32011-07-07 13:42:37 +000049 virtual SkGpuTexture* getTexture();
reed@google.comac10a2d2010-12-22 21:39:39 +000050
51protected:
52 // override from SkPixelRef
reed@google.com50dfa012011-04-01 19:05:36 +000053 virtual bool onReadPixels(SkBitmap* dst, const SkIRect* subset);
reed@google.comac10a2d2010-12-22 21:39:39 +000054
55private:
56 GrTexture* fTexture;
reed@google.com9c49bc32011-07-07 13:42:37 +000057 typedef SkROLockPixelsPixelRef INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +000058};
59
reed@google.com9c49bc32011-07-07 13:42:37 +000060/**
61 * PixelRef that wraps a GrRenderTarget
62 */
63class SkGrRenderTargetPixelRef : public SkROLockPixelsPixelRef {
bsalomon@google.com669fdc42011-04-05 17:08:27 +000064public:
65 SkGrRenderTargetPixelRef(GrRenderTarget* rt);
66 virtual ~SkGrRenderTargetPixelRef();
67
68 // override from SkPixelRef
69 virtual SkGpuTexture* getTexture();
70
71protected:
72 // override from SkPixelRef
bsalomon@google.com669fdc42011-04-05 17:08:27 +000073 virtual bool onReadPixels(SkBitmap* dst, const SkIRect* subset);
74
75private:
76 GrRenderTarget* fRenderTarget;
reed@google.com9c49bc32011-07-07 13:42:37 +000077 typedef SkROLockPixelsPixelRef INHERITED;
bsalomon@google.com669fdc42011-04-05 17:08:27 +000078};
79
reed@google.comac10a2d2010-12-22 21:39:39 +000080#endif
81