• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2013 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.
6  */
7 
8 #ifndef SkDiscardablePixelRef_DEFINED
9 #define SkDiscardablePixelRef_DEFINED
10 
11 #include "SkDiscardableMemory.h"
12 #include "SkImageGenerator.h"
13 #include "SkImageInfo.h"
14 #include "SkPixelRef.h"
15 
16 class SkDiscardablePixelRef : public SkPixelRef {
17 public:
18     SK_DECLARE_UNFLATTENABLE_OBJECT()
19 
20 protected:
21     ~SkDiscardablePixelRef();
22     virtual void* onLockPixels(SkColorTable**) SK_OVERRIDE;
23     virtual void onUnlockPixels() SK_OVERRIDE;
onLockPixelsAreWritable()24     virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; }
25 
onRefEncodedData()26     virtual SkData* onRefEncodedData() SK_OVERRIDE {
27         return fGenerator->refEncodedData();
28     }
29 
30 private:
31     SkImageGenerator* const fGenerator;
32     SkDiscardableMemory::Factory* const fDMFactory;
33     const size_t fRowBytes;
34     // These const members should not change over the life of the
35     // PixelRef, since the SkBitmap doesn't expect them to change.
36 
37     SkDiscardableMemory* fDiscardableMemory;
38 
39     /* Takes ownership of SkImageGenerator. */
40     SkDiscardablePixelRef(const SkImageInfo&, SkImageGenerator*,
41                           size_t rowBytes,
42                           SkDiscardableMemory::Factory* factory);
43     friend bool SkInstallDiscardablePixelRef(SkImageGenerator*,
44                                              SkBitmap*,
45                                              SkDiscardableMemory::Factory*);
46     typedef SkPixelRef INHERITED;
47 };
48 #endif  // SkDiscardablePixelRef_DEFINED
49