Backed out 9 changesets (bug 1846848) for causing multiple build bustages. CLOSED...
[gecko.git] / dom / base / ImageTracker.h
blobd179bf66c85aef419ef1e7e3cbb1859341858c43
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* table of images used in a document, for batch locking/unlocking and
8 * animating */
10 #ifndef mozilla_dom_ImageTracker
11 #define mozilla_dom_ImageTracker
13 #include "nsTHashMap.h"
14 #include "nsHashKeys.h"
16 class imgIRequest;
17 namespace mozilla {
18 struct MediaFeatureChange;
21 namespace mozilla::dom {
24 * Image Tracking
26 * Style and content images register their imgIRequests with their document's
27 * image tracker, so that we can efficiently tell all descendant images when
28 * they are and are not visible. When an image is on-screen, we want to call
29 * LockImage() on it so that it doesn't do things like discarding frame data
30 * to save memory. The PresShell informs its document's image tracker whether
31 * its images should be locked or not via SetLockingState().
33 * See bug 512260.
35 class ImageTracker {
36 public:
37 ImageTracker();
38 ImageTracker(const ImageTracker&) = delete;
39 ImageTracker& operator=(const ImageTracker&) = delete;
41 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ImageTracker)
43 nsresult Add(imgIRequest* aImage);
45 enum { REQUEST_DISCARD = 0x1 };
46 nsresult Remove(imgIRequest* aImage, uint32_t aFlags = 0);
48 // Makes the images on this document locked/unlocked. By default, the locking
49 // state is unlocked/false.
50 void SetLockingState(bool aLocked);
51 bool GetLockingState() const { return mLocking; }
53 // Makes the images on this document capable of having their animation
54 // active or suspended. An Image will animate as long as at least one of its
55 // owning Documents needs it to animate; otherwise it can suspend.
56 void SetAnimatingState(bool aAnimating);
58 void RequestDiscardAll();
59 void MediaFeatureValuesChangedAllDocuments(const MediaFeatureChange&);
61 private:
62 ~ImageTracker();
64 nsTHashMap<nsPtrHashKey<imgIRequest>, uint32_t> mImages;
65 bool mLocking = false;
66 bool mAnimating = true;
69 } // namespace mozilla::dom
71 #endif // mozilla_dom_ImageTracker