blob: 2de842e3b44ff51879852d8b617c82b1e3ccd332 [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
2 Copyright 2010 Google Inc.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17
18#ifndef SkGrTexturePixelRef_DEFINED
19#define SkGrTexturePixelRef_DEFINED
20
reed@google.com9c49bc32011-07-07 13:42:37 +000021#include "SkBitmap.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000022#include "SkPixelRef.h"
23#include "GrGpu.h"
24
reed@google.com9c49bc32011-07-07 13:42:37 +000025/**
26 * Common baseclass that implements onLockPixels() by calling onReadPixels().
27 * Since it has a copy, it always returns false for onLockPixelsAreWritable().
28 */
29class SkROLockPixelsPixelRef : public SkPixelRef {
30public:
31 SkROLockPixelsPixelRef();
32 virtual ~SkROLockPixelsPixelRef();
33
34protected:
35 // override from SkPixelRef
36 virtual void* onLockPixels(SkColorTable** ptr);
37 virtual void onUnlockPixels();
38 virtual bool onLockPixelsAreWritable() const; // return false;
39
40private:
41 SkBitmap fBitmap;
42 typedef SkPixelRef INHERITED;
43};
44
45/**
46 * PixelRef that wraps a GrTexture
47 */
48class SkGrTexturePixelRef : public SkROLockPixelsPixelRef {
reed@google.comac10a2d2010-12-22 21:39:39 +000049public:
50 SkGrTexturePixelRef(GrTexture*);
51 virtual ~SkGrTexturePixelRef();
52
53 // override from SkPixelRef
reed@google.com9c49bc32011-07-07 13:42:37 +000054 virtual SkGpuTexture* getTexture();
reed@google.comac10a2d2010-12-22 21:39:39 +000055
56protected:
57 // override from SkPixelRef
reed@google.com50dfa012011-04-01 19:05:36 +000058 virtual bool onReadPixels(SkBitmap* dst, const SkIRect* subset);
reed@google.comac10a2d2010-12-22 21:39:39 +000059
60private:
61 GrTexture* fTexture;
reed@google.com9c49bc32011-07-07 13:42:37 +000062 typedef SkROLockPixelsPixelRef INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +000063};
64
reed@google.com9c49bc32011-07-07 13:42:37 +000065/**
66 * PixelRef that wraps a GrRenderTarget
67 */
68class SkGrRenderTargetPixelRef : public SkROLockPixelsPixelRef {
bsalomon@google.com669fdc42011-04-05 17:08:27 +000069public:
70 SkGrRenderTargetPixelRef(GrRenderTarget* rt);
71 virtual ~SkGrRenderTargetPixelRef();
72
73 // override from SkPixelRef
74 virtual SkGpuTexture* getTexture();
75
76protected:
77 // override from SkPixelRef
bsalomon@google.com669fdc42011-04-05 17:08:27 +000078 virtual bool onReadPixels(SkBitmap* dst, const SkIRect* subset);
79
80private:
81 GrRenderTarget* fRenderTarget;
reed@google.com9c49bc32011-07-07 13:42:37 +000082 typedef SkROLockPixelsPixelRef INHERITED;
bsalomon@google.com669fdc42011-04-05 17:08:27 +000083};
84
reed@google.comac10a2d2010-12-22 21:39:39 +000085#endif
86