Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright 2013 Google Inc. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | * found in the LICENSE file. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | #ifndef SkDiscardablePixelRef_DEFINED |
michael@0 | 9 | #define SkDiscardablePixelRef_DEFINED |
michael@0 | 10 | |
michael@0 | 11 | #include "SkDiscardableMemory.h" |
michael@0 | 12 | #include "SkImageGenerator.h" |
michael@0 | 13 | #include "SkImageInfo.h" |
michael@0 | 14 | #include "SkPixelRef.h" |
michael@0 | 15 | |
michael@0 | 16 | /** |
michael@0 | 17 | * A PixelRef backed by SkDiscardableMemory, with the ability to |
michael@0 | 18 | * re-generate the pixels (via a SkImageGenerator) if the DM is |
michael@0 | 19 | * purged. |
michael@0 | 20 | * |
michael@0 | 21 | * Since SkColorTable is reference-counted, we do not support indexed |
michael@0 | 22 | * color with this class; there would be no way for the discardable |
michael@0 | 23 | * memory system to unref the color table. |
michael@0 | 24 | */ |
michael@0 | 25 | class SkDiscardablePixelRef : public SkPixelRef { |
michael@0 | 26 | public: |
michael@0 | 27 | SK_DECLARE_INST_COUNT(SkDiscardablePixelRef) |
michael@0 | 28 | SK_DECLARE_UNFLATTENABLE_OBJECT() |
michael@0 | 29 | |
michael@0 | 30 | protected: |
michael@0 | 31 | ~SkDiscardablePixelRef(); |
michael@0 | 32 | |
michael@0 | 33 | virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE; |
michael@0 | 34 | virtual void onUnlockPixels() SK_OVERRIDE; |
michael@0 | 35 | virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } |
michael@0 | 36 | |
michael@0 | 37 | virtual SkData* onRefEncodedData() SK_OVERRIDE { |
michael@0 | 38 | return fGenerator->refEncodedData(); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | private: |
michael@0 | 42 | SkImageGenerator* const fGenerator; |
michael@0 | 43 | SkDiscardableMemory::Factory* const fDMFactory; |
michael@0 | 44 | const size_t fRowBytes; |
michael@0 | 45 | // These const members should not change over the life of the |
michael@0 | 46 | // PixelRef, since the SkBitmap doesn't expect them to change. |
michael@0 | 47 | |
michael@0 | 48 | SkDiscardableMemory* fDiscardableMemory; |
michael@0 | 49 | |
michael@0 | 50 | /* Takes ownership of SkImageGenerator. */ |
michael@0 | 51 | SkDiscardablePixelRef(const SkImageInfo&, SkImageGenerator*, |
michael@0 | 52 | size_t rowBytes, |
michael@0 | 53 | SkDiscardableMemory::Factory* factory); |
michael@0 | 54 | |
michael@0 | 55 | friend bool SkInstallDiscardablePixelRef(SkImageGenerator*, |
michael@0 | 56 | SkBitmap*, |
michael@0 | 57 | SkDiscardableMemory::Factory*); |
michael@0 | 58 | |
michael@0 | 59 | typedef SkPixelRef INHERITED; |
michael@0 | 60 | }; |
michael@0 | 61 | |
michael@0 | 62 | #endif // SkDiscardablePixelRef_DEFINED |