image/src/imgDecoderObserver.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/image/src/imgDecoderObserver.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,139 @@
     1.4 +/** -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef MOZILLA_IMAGELIB_IMGDECODEROBSERVER_H_
    1.10 +#define MOZILLA_IMAGELIB_IMGDECODEROBSERVER_H_
    1.11 +
    1.12 +#include "nsRect.h"
    1.13 +#include "mozilla/WeakPtr.h"
    1.14 +
    1.15 +struct nsIntRect;
    1.16 +
    1.17 +/**
    1.18 + * imgDecoderObserver interface
    1.19 + *
    1.20 + * This interface is used to observe Decoder objects.
    1.21 + *
    1.22 + * We make the distinction here between "load" and "decode" notifications. Load
    1.23 + * notifications are fired as the image is loaded from the network or
    1.24 + * filesystem. Decode notifications are fired as the image is decoded. If an
    1.25 + * image is decoded on load and not visibly discarded, decode notifications are
    1.26 + * nested logically inside load notifications as one might expect. However, with
    1.27 + * decode-on-draw, the set of decode notifications can come completely _after_
    1.28 + * the load notifications, and can come multiple times if the image is
    1.29 + * discardable. Moreover, they can be interleaved in various ways. In general,
    1.30 + * any presumed ordering between load and decode notifications should not be
    1.31 + * relied upon.
    1.32 + *
    1.33 + * Decode notifications may or may not be synchronous, depending on the
    1.34 + * situation. If imgIDecoder::FLAG_SYNC_DECODE is passed to a function that
    1.35 + * triggers a decode, all notifications that can be generated from the currently
    1.36 + * loaded data fire before the call returns. If FLAG_SYNC_DECODE is not passed,
    1.37 + * all, some, or none of the notifications may fire before the call returns.
    1.38 + */
    1.39 +class imgDecoderObserver
    1.40 +{
    1.41 +public:
    1.42 +  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(imgDecoderObserver);
    1.43 +
    1.44 +  /**
    1.45 +   * Load notification.
    1.46 +   *
    1.47 +   * called at the same time that nsIRequestObserver::onStartRequest would be
    1.48 +   * (used only for observers of imgIRequest objects, which are nsIRequests,
    1.49 +   * not imgIDecoder objects)
    1.50 +   */
    1.51 +  virtual void OnStartRequest() = 0;
    1.52 +
    1.53 +  /**
    1.54 +   * Decode notification.
    1.55 +   *
    1.56 +   * Called as soon as the image begins getting decoded. This does not include
    1.57 +   * "header-only" decodes used by decode-on-draw to parse the width/height
    1.58 +   * out of the image. Thus, it is a decode notification only.
    1.59 +   */
    1.60 +  virtual void OnStartDecode() = 0;
    1.61 +
    1.62 +  /**
    1.63 +   * Load notification.
    1.64 +   *
    1.65 +   * Called once enough data has been loaded from the network that we were able
    1.66 +   * to parse the width/height from the image. By the time this callback is been
    1.67 +   * called, the size has been set on the container and STATUS_SIZE_AVAILABLE
    1.68 +   * has been set on the associated imgRequest.
    1.69 +   */
    1.70 +  virtual void OnStartContainer() = 0;
    1.71 +
    1.72 +  /**
    1.73 +   * Decode notification.
    1.74 +   *
    1.75 +   * Called when we know a frame has begun decoding.
    1.76 +   */
    1.77 +  virtual void OnStartFrame() = 0;
    1.78 +
    1.79 +  /**
    1.80 +   * Decode notification.
    1.81 +   *
    1.82 +   * called when there is more to paint.
    1.83 +   */
    1.84 +  virtual void FrameChanged(const nsIntRect * aDirtyRect) = 0;
    1.85 +
    1.86 +  /**
    1.87 +   * Decode notification.
    1.88 +   *
    1.89 +   * called when a frame is finished decoding.
    1.90 +   */
    1.91 +  virtual void OnStopFrame() = 0;
    1.92 +
    1.93 +  /**
    1.94 +   * Notification for when an image is known to be animated. This should be
    1.95 +   * fired at the earliest possible time.
    1.96 +   */
    1.97 +  virtual void OnImageIsAnimated() = 0;
    1.98 +
    1.99 +  /**
   1.100 +   * Decode notification.
   1.101 +   *
   1.102 +   * Called when all decoding has terminated.
   1.103 +   */
   1.104 +  virtual void OnStopDecode(nsresult status) = 0;
   1.105 +
   1.106 +  /**
   1.107 +   * Load notification.
   1.108 +   *
   1.109 +   * called at the same time that nsIRequestObserver::onStopRequest would be
   1.110 +   * (used only for observers of imgIRequest objects, which are nsIRequests,
   1.111 +   * not imgIDecoder objects)
   1.112 +   */
   1.113 +  virtual void OnStopRequest(bool aIsLastPart, nsresult aStatus) = 0;
   1.114 +
   1.115 +  /**
   1.116 +   * Called when the decoded image data is discarded. This means that the frames
   1.117 +   * no longer exist in decoded form, and any attempt to access or draw the
   1.118 +   * image will initiate a new series of progressive decode notifications.
   1.119 +   */
   1.120 +  virtual void OnDiscard() = 0;
   1.121 +
   1.122 +  /**
   1.123 +   * Called when we are asked to Draw an image that is not locked.
   1.124 +   */
   1.125 +  virtual void OnUnlockedDraw() = 0;
   1.126 +
   1.127 +  /**
   1.128 +   * Called when an image is realized to be in error state.
   1.129 +   */
   1.130 +  virtual void OnError() = 0;
   1.131 +
   1.132 +protected:
   1.133 +  virtual ~imgDecoderObserver() = 0;
   1.134 +};
   1.135 +
   1.136 +// We must define a destructor because derived classes call our destructor from
   1.137 +// theirs.  Pure virtual destructors only requires that child classes implement
   1.138 +// a virtual destructor, not that we can't have one too!
   1.139 +inline imgDecoderObserver::~imgDecoderObserver()
   1.140 +{}
   1.141 +
   1.142 +#endif // MOZILLA_IMAGELIB_IMGDECODEROBSERVER_H

mercurial