blob: 9a81be67de50c1107353bb2e8d8b4c8d0945d95f [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2010 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@google.comac10a2d2010-12-22 21:39:39 +00006 */
7
robertphillips@google.comd881bc12012-06-28 20:02:39 +00008#ifndef SkGrPixelRef_DEFINED
9#define SkGrPixelRef_DEFINED
reed@google.comac10a2d2010-12-22 21:39:39 +000010
reed@google.com9c49bc32011-07-07 13:42:37 +000011#include "SkBitmap.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000012#include "SkPixelRef.h"
bsalomon@google.combbfa1002011-08-16 15:13:54 +000013#include "GrTexture.h"
14#include "GrRenderTarget.h"
15
reed@google.comac10a2d2010-12-22 21:39:39 +000016
reed@google.com9c49bc32011-07-07 13:42:37 +000017/**
18 * Common baseclass that implements onLockPixels() by calling onReadPixels().
19 * Since it has a copy, it always returns false for onLockPixelsAreWritable().
20 */
senorblanco@chromium.org29767652012-02-08 20:27:16 +000021class SK_API SkROLockPixelsPixelRef : public SkPixelRef {
reed@google.com9c49bc32011-07-07 13:42:37 +000022public:
commit-bot@chromium.org227c2462014-01-24 18:33:07 +000023 SK_DECLARE_INST_COUNT(SkROLockPixelsPixelRef)
reed@google.combf790232013-12-13 19:45:58 +000024 SkROLockPixelsPixelRef(const SkImageInfo&);
reed@google.com9c49bc32011-07-07 13:42:37 +000025 virtual ~SkROLockPixelsPixelRef();
26
27protected:
reed@google.comd0419b12014-01-06 17:08:27 +000028 virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE;
29 virtual void onUnlockPixels() SK_OVERRIDE;
30 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE; // return false;
reed@google.com9c49bc32011-07-07 13:42:37 +000031
32private:
33 SkBitmap fBitmap;
34 typedef SkPixelRef INHERITED;
35};
36
37/**
robertphillips@google.comd881bc12012-06-28 20:02:39 +000038 * PixelRef that wraps a GrSurface
reed@google.com9c49bc32011-07-07 13:42:37 +000039 */
robertphillips@google.comd881bc12012-06-28 20:02:39 +000040class SK_API SkGrPixelRef : public SkROLockPixelsPixelRef {
reed@google.comac10a2d2010-12-22 21:39:39 +000041public:
commit-bot@chromium.org227c2462014-01-24 18:33:07 +000042 SK_DECLARE_INST_COUNT(SkGrPixelRef)
bsalomon@google.com8090e652012-08-28 15:07:11 +000043 /**
bsalomonbcf0a522014-10-08 08:40:09 -070044 * Constructs a pixel ref around a GrSurface.
bsalomon@google.com8090e652012-08-28 15:07:11 +000045 */
bsalomonbcf0a522014-10-08 08:40:09 -070046 SkGrPixelRef(const SkImageInfo&, GrSurface*);
robertphillips@google.comd881bc12012-06-28 20:02:39 +000047 virtual ~SkGrPixelRef();
reed@google.comac10a2d2010-12-22 21:39:39 +000048
49 // override from SkPixelRef
commit-bot@chromium.orgb8d00db2013-06-26 19:18:23 +000050 virtual GrTexture* getTexture() SK_OVERRIDE;
reed@google.comac10a2d2010-12-22 21:39:39 +000051
52protected:
robertphillips@google.comd881bc12012-06-28 20:02:39 +000053 // overrides from SkPixelRef
54 virtual bool onReadPixels(SkBitmap* dst, const SkIRect* subset) SK_OVERRIDE;
reede4538f52014-06-11 06:09:50 -070055 virtual SkPixelRef* deepCopy(SkColorType, const SkIRect* subset) SK_OVERRIDE;
senorblanco@chromium.orgef843cd2011-12-02 19:11:17 +000056
reed@google.comac10a2d2010-12-22 21:39:39 +000057private:
robertphillips@google.comd881bc12012-06-28 20:02:39 +000058 GrSurface* fSurface;
reed@google.com9c49bc32011-07-07 13:42:37 +000059 typedef SkROLockPixelsPixelRef INHERITED;
bsalomon@google.com669fdc42011-04-05 17:08:27 +000060};
61
reed@google.comac10a2d2010-12-22 21:39:39 +000062#endif