blob: 0e1b3b62be5e7f48261211e18bd217b63494f389 [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"
16#include "GrGpu.h"
17
reed@google.com9c49bc32011-07-07 13:42:37 +000018/**
19 * Common baseclass that implements onLockPixels() by calling onReadPixels().
20 * Since it has a copy, it always returns false for onLockPixelsAreWritable().
21 */
22class SkROLockPixelsPixelRef : public SkPixelRef {
23public:
24 SkROLockPixelsPixelRef();
25 virtual ~SkROLockPixelsPixelRef();
26
27protected:
28 // override from SkPixelRef
29 virtual void* onLockPixels(SkColorTable** ptr);
30 virtual void onUnlockPixels();
31 virtual bool onLockPixelsAreWritable() const; // return false;
32
33private:
34 SkBitmap fBitmap;
35 typedef SkPixelRef INHERITED;
36};
37
38/**
39 * PixelRef that wraps a GrTexture
40 */
41class SkGrTexturePixelRef : public SkROLockPixelsPixelRef {
reed@google.comac10a2d2010-12-22 21:39:39 +000042public:
43 SkGrTexturePixelRef(GrTexture*);
44 virtual ~SkGrTexturePixelRef();
45
46 // override from SkPixelRef
reed@google.com9c49bc32011-07-07 13:42:37 +000047 virtual SkGpuTexture* getTexture();
reed@google.comac10a2d2010-12-22 21:39:39 +000048
49protected:
50 // override from SkPixelRef
reed@google.com50dfa012011-04-01 19:05:36 +000051 virtual bool onReadPixels(SkBitmap* dst, const SkIRect* subset);
reed@google.comac10a2d2010-12-22 21:39:39 +000052
53private:
54 GrTexture* fTexture;
reed@google.com9c49bc32011-07-07 13:42:37 +000055 typedef SkROLockPixelsPixelRef INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +000056};
57
reed@google.com9c49bc32011-07-07 13:42:37 +000058/**
59 * PixelRef that wraps a GrRenderTarget
60 */
61class SkGrRenderTargetPixelRef : public SkROLockPixelsPixelRef {
bsalomon@google.com669fdc42011-04-05 17:08:27 +000062public:
63 SkGrRenderTargetPixelRef(GrRenderTarget* rt);
64 virtual ~SkGrRenderTargetPixelRef();
65
66 // override from SkPixelRef
67 virtual SkGpuTexture* getTexture();
68
69protected:
70 // override from SkPixelRef
bsalomon@google.com669fdc42011-04-05 17:08:27 +000071 virtual bool onReadPixels(SkBitmap* dst, const SkIRect* subset);
72
73private:
74 GrRenderTarget* fRenderTarget;
reed@google.com9c49bc32011-07-07 13:42:37 +000075 typedef SkROLockPixelsPixelRef INHERITED;
bsalomon@google.com669fdc42011-04-05 17:08:27 +000076};
77
reed@google.comac10a2d2010-12-22 21:39:39 +000078#endif
79