Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / image / src / imgDecoderObserver.h
blob4c37087bca8f25494c53b8a67c5b48a179190429
1 /** -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef MOZILLA_IMAGELIB_IMGDECODEROBSERVER_H_
7 #define MOZILLA_IMAGELIB_IMGDECODEROBSERVER_H_
9 #include "nsRect.h"
10 #include "mozilla/WeakPtr.h"
12 struct nsIntRect;
14 /**
15 * imgDecoderObserver interface
17 * This interface is used to observe Decoder objects.
19 * We make the distinction here between "load" and "decode" notifications. Load
20 * notifications are fired as the image is loaded from the network or
21 * filesystem. Decode notifications are fired as the image is decoded. If an
22 * image is decoded on load and not visibly discarded, decode notifications are
23 * nested logically inside load notifications as one might expect. However, with
24 * decode-on-draw, the set of decode notifications can come completely _after_
25 * the load notifications, and can come multiple times if the image is
26 * discardable. Moreover, they can be interleaved in various ways. In general,
27 * any presumed ordering between load and decode notifications should not be
28 * relied upon.
30 * Decode notifications may or may not be synchronous, depending on the
31 * situation. If imgIDecoder::FLAG_SYNC_DECODE is passed to a function that
32 * triggers a decode, all notifications that can be generated from the currently
33 * loaded data fire before the call returns. If FLAG_SYNC_DECODE is not passed,
34 * all, some, or none of the notifications may fire before the call returns.
36 class imgDecoderObserver
38 public:
39 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(imgDecoderObserver);
41 /**
42 * Load notification.
44 * called at the same time that nsIRequestObserver::onStartRequest would be
45 * (used only for observers of imgIRequest objects, which are nsIRequests,
46 * not imgIDecoder objects)
48 virtual void OnStartRequest() = 0;
50 /**
51 * Decode notification.
53 * Called as soon as the image begins getting decoded. This does not include
54 * "header-only" decodes used by decode-on-draw to parse the width/height
55 * out of the image. Thus, it is a decode notification only.
57 virtual void OnStartDecode() = 0;
59 /**
60 * Load notification.
62 * Called once enough data has been loaded from the network that we were able
63 * to parse the width/height from the image. By the time this callback is been
64 * called, the size has been set on the container and STATUS_SIZE_AVAILABLE
65 * has been set on the associated imgRequest.
67 virtual void OnStartContainer() = 0;
69 /**
70 * Decode notification.
72 * Called when we know a frame has begun decoding.
74 virtual void OnStartFrame() = 0;
76 /**
77 * Decode notification.
79 * called when there is more to paint.
81 virtual void FrameChanged(const nsIntRect * aDirtyRect) = 0;
83 /**
84 * Decode notification.
86 * called when a frame is finished decoding.
88 virtual void OnStopFrame() = 0;
90 /**
91 * Notification for when an image is known to be animated. This should be
92 * fired at the earliest possible time.
94 virtual void OnImageIsAnimated() = 0;
96 /**
97 * Decode notification.
99 * Called when all decoding has terminated.
101 virtual void OnStopDecode(nsresult status) = 0;
104 * Load notification.
106 * called at the same time that nsIRequestObserver::onStopRequest would be
107 * (used only for observers of imgIRequest objects, which are nsIRequests,
108 * not imgIDecoder objects)
110 virtual void OnStopRequest(bool aIsLastPart, nsresult aStatus) = 0;
113 * Called when the decoded image data is discarded. This means that the frames
114 * no longer exist in decoded form, and any attempt to access or draw the
115 * image will initiate a new series of progressive decode notifications.
117 virtual void OnDiscard() = 0;
120 * Called when we are asked to Draw an image that is not locked.
122 virtual void OnUnlockedDraw() = 0;
125 * Called when an image is realized to be in error state.
127 virtual void OnError() = 0;
129 protected:
130 virtual ~imgDecoderObserver() = 0;
133 // We must define a destructor because derived classes call our destructor from
134 // theirs. Pure virtual destructors only requires that child classes implement
135 // a virtual destructor, not that we can't have one too!
136 inline imgDecoderObserver::~imgDecoderObserver()
139 #endif // MOZILLA_IMAGELIB_IMGDECODEROBSERVER_H