tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

FrozenImage.cpp (4752B)


      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/. */
      5 
      6 #include "FrozenImage.h"
      7 
      8 namespace mozilla {
      9 
     10 using namespace gfx;
     11 using layers::ImageContainer;
     12 
     13 namespace image {
     14 
     15 void FrozenImage::IncrementAnimationConsumers() {
     16  // Do nothing. This will prevent animation from starting if there are no other
     17  // instances of this image.
     18 }
     19 
     20 void FrozenImage::DecrementAnimationConsumers() {
     21  // Do nothing.
     22 }
     23 
     24 NS_IMETHODIMP
     25 FrozenImage::GetAnimated(bool* aAnimated) {
     26  bool dummy;
     27  nsresult rv = InnerImage()->GetAnimated(&dummy);
     28  if (NS_SUCCEEDED(rv)) {
     29    *aAnimated = false;
     30  }
     31  return rv;
     32 }
     33 
     34 NS_IMETHODIMP_(already_AddRefed<SourceSurface>)
     35 FrozenImage::GetFrame(uint32_t aWhichFrame, uint32_t aFlags) {
     36  return InnerImage()->GetFrame(FRAME_FIRST, aFlags);
     37 }
     38 
     39 NS_IMETHODIMP_(already_AddRefed<SourceSurface>)
     40 FrozenImage::GetFrameAtSize(const IntSize& aSize, uint32_t aWhichFrame,
     41                            uint32_t aFlags) {
     42  return InnerImage()->GetFrameAtSize(aSize, FRAME_FIRST, aFlags);
     43 }
     44 
     45 bool FrozenImage::IsNonAnimated() const {
     46  // We usually don't create frozen images for non-animated images, but it might
     47  // happen if we don't have enough data at the time of the creation to
     48  // determine whether the image is actually animated.
     49  bool animated = false;
     50  return NS_SUCCEEDED(InnerImage()->GetAnimated(&animated)) && !animated;
     51 }
     52 
     53 NS_IMETHODIMP_(bool)
     54 FrozenImage::IsImageContainerAvailable(WindowRenderer* aRenderer,
     55                                       uint32_t aFlags) {
     56  if (IsNonAnimated()) {
     57    return InnerImage()->IsImageContainerAvailable(aRenderer, aFlags);
     58  }
     59  return false;
     60 }
     61 
     62 NS_IMETHODIMP_(ImgDrawResult)
     63 FrozenImage::GetImageProvider(WindowRenderer* aRenderer,
     64                              const gfx::IntSize& aSize,
     65                              const SVGImageContext& aSVGContext,
     66                              const Maybe<ImageIntRegion>& aRegion,
     67                              uint32_t aFlags,
     68                              WebRenderImageProvider** aProvider) {
     69  if (IsNonAnimated()) {
     70    return InnerImage()->GetImageProvider(aRenderer, aSize, aSVGContext,
     71                                          aRegion, aFlags, aProvider);
     72  }
     73 
     74  // XXX(seth): GetImageContainer does not currently support anything but the
     75  // current frame. We work around this by always returning null, but if it ever
     76  // turns out that FrozenImage is widely used on codepaths that can actually
     77  // benefit from GetImageContainer, it would be a good idea to fix that method
     78  // for performance reasons.
     79  return ImgDrawResult::NOT_SUPPORTED;
     80 }
     81 
     82 NS_IMETHODIMP_(ImgDrawResult)
     83 FrozenImage::Draw(gfxContext* aContext, const nsIntSize& aSize,
     84                  const ImageRegion& aRegion,
     85                  uint32_t /* aWhichFrame - ignored */,
     86                  SamplingFilter aSamplingFilter,
     87                  const SVGImageContext& aSVGContext, uint32_t aFlags,
     88                  float aOpacity) {
     89  return InnerImage()->Draw(aContext, aSize, aRegion, FRAME_FIRST,
     90                            aSamplingFilter, aSVGContext, aFlags, aOpacity);
     91 }
     92 
     93 NS_IMETHODIMP
     94 FrozenImage::StartDecoding(uint32_t aFlags, uint32_t aWhichFrame) {
     95  return InnerImage()->StartDecoding(aFlags, FRAME_FIRST);
     96 }
     97 
     98 bool FrozenImage::StartDecodingWithResult(uint32_t aFlags,
     99                                          uint32_t aWhichFrame) {
    100  return InnerImage()->StartDecodingWithResult(aFlags, FRAME_FIRST);
    101 }
    102 
    103 bool FrozenImage::HasDecodedPixels() {
    104  return InnerImage()->HasDecodedPixels();
    105 }
    106 
    107 imgIContainer::DecodeResult FrozenImage::RequestDecodeWithResult(
    108    uint32_t aFlags, uint32_t aWhichFrame) {
    109  return InnerImage()->RequestDecodeWithResult(aFlags, FRAME_FIRST);
    110 }
    111 
    112 NS_IMETHODIMP
    113 FrozenImage::RequestDecodeForSize(const nsIntSize& aSize, uint32_t aFlags,
    114                                  uint32_t aWhichFrame) {
    115  return InnerImage()->RequestDecodeForSize(aSize, aFlags, FRAME_FIRST);
    116 }
    117 
    118 NS_IMETHODIMP_(void)
    119 FrozenImage::RequestRefresh(const TimeStamp& aTime) {
    120  // Do nothing.
    121 }
    122 
    123 NS_IMETHODIMP
    124 FrozenImage::GetAnimationMode(uint16_t* aAnimationMode) {
    125  *aAnimationMode = kNormalAnimMode;
    126  return NS_OK;
    127 }
    128 
    129 NS_IMETHODIMP
    130 FrozenImage::SetAnimationMode(uint16_t aAnimationMode) {
    131  // Do nothing.
    132  return NS_OK;
    133 }
    134 
    135 NS_IMETHODIMP
    136 FrozenImage::ResetAnimation() {
    137  // Do nothing.
    138  return NS_OK;
    139 }
    140 
    141 NS_IMETHODIMP_(float)
    142 FrozenImage::GetFrameIndex(uint32_t aWhichFrame) {
    143  MOZ_ASSERT(aWhichFrame <= FRAME_MAX_VALUE, "Invalid argument");
    144  return 0;
    145 }
    146 
    147 }  // namespace image
    148 }  // namespace mozilla