image/IDecodingTask.h
author Morten Stenshorne <mstensho@chromium.org>
Tue, 09 Oct 2018 04:14:13 +0000
changeset 495959 13844f50ee32e17f513b7c1013c2348200e21b8c
parent 443730 7159964287fe161b0dda9cdfa59d74bc7bead348
child 500481 5223058ac4fffd00aad34eeb29998c3264b250e8
permissions -rw-r--r--
Bug 1496274 [wpt PR 13345] - [LayoutNG] Correct clip-path reference box calculation., a=testonly Automatic update from web-platform-tests[LayoutNG] Correct clip-path reference box calculation. We used coordinates relatively to the line box, while we were expected by the caller to be relative to the containing block. Flipping for writing mode was bogus for NG (but needed by legacy), since NG uses truly physical coordinates. Hardened tests to contain a leading line and padding, and leading content on the first line of the clipped child. Bug: 641907 Change-Id: I2b1b9ff4ea92a6405fcdffcf139842458b46442f Cq-Include-Trybots: luci.chromium.try​:linux_layout_tests_layout_ng Reviewed-on: https://chromium-review.googlesource.com/c/1257913 Reviewed-by: Koji Ishii <kojii@chromium.org> Reviewed-by: Fredrik Söderquist <fs@opera.com> Commit-Queue: Morten Stenshorne <mstensho@chromium.org> Cr-Commit-Position: refs/heads/master@{#596554} -- wpt-commits: e9a0828c85819340f721f121aac19ab8eefa3439 wpt-pr: 13345

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/**
 * An interface for tasks which can execute on the ImageLib DecodePool, and
 * various implementations.
 */

#ifndef mozilla_image_IDecodingTask_h
#define mozilla_image_IDecodingTask_h

#include "imgFrame.h"
#include "mozilla/NotNull.h"
#include "mozilla/RefPtr.h"
#include "nsIEventTarget.h"
#include "SourceBuffer.h"

namespace mozilla {
namespace image {

class Decoder;
class RasterImage;

/// A priority hint that DecodePool can use when scheduling an IDecodingTask.
enum class TaskPriority : uint8_t
{
  eLow,
  eHigh
};

/**
 * An interface for tasks which can execute on the ImageLib DecodePool.
 */
class IDecodingTask : public IResumable
{
public:
  /// Run the task.
  virtual void Run() = 0;

  /// @return true if, given the option, this task prefers to run synchronously.
  virtual bool ShouldPreferSyncRun() const = 0;

  /// @return a priority hint that DecodePool can use when scheduling this task.
  virtual TaskPriority Priority() const = 0;

  /// A default implementation of IResumable which resubmits the task to the
  /// DecodePool. Subclasses can override this if they need different behavior.
  void Resume() override;

protected:
  virtual ~IDecodingTask() { }

  /// Notify @aImage of @aDecoder's progress.
  void NotifyProgress(NotNull<RasterImage*> aImage,
                      NotNull<Decoder*> aDecoder);

  /// Notify @aImage that @aDecoder has finished.
  void NotifyDecodeComplete(NotNull<RasterImage*> aImage,
                            NotNull<Decoder*> aDecoder);

private:
  void EnsureHasEventTarget(NotNull<RasterImage*> aImage);

  bool IsOnEventTarget() const;

  nsCOMPtr<nsIEventTarget> mEventTarget;
};


/**
 * An IDecodingTask implementation for metadata decodes of images.
 */
class MetadataDecodingTask final : public IDecodingTask
{
public:
  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MetadataDecodingTask, override)

  explicit MetadataDecodingTask(NotNull<Decoder*> aDecoder);

  void Run() override;

  // Metadata decodes are very fast (since they only need to examine an image's
  // header) so there's no reason to refuse to run them synchronously if the
  // caller will allow us to.
  bool ShouldPreferSyncRun() const override { return true; }

  // Metadata decodes run at the highest priority because they block layout and
  // page load.
  TaskPriority Priority() const override { return TaskPriority::eHigh; }

private:
  virtual ~MetadataDecodingTask() { }

  /// Mutex protecting access to mDecoder.
  Mutex mMutex;

  NotNull<RefPtr<Decoder>> mDecoder;
};


/**
 * An IDecodingTask implementation for anonymous decoders - that is, decoders
 * with no associated Image object.
 */
class AnonymousDecodingTask final : public IDecodingTask
{
public:
  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AnonymousDecodingTask, override)

  explicit AnonymousDecodingTask(NotNull<Decoder*> aDecoder);

  void Run() override;

  bool ShouldPreferSyncRun() const override { return true; }
  TaskPriority Priority() const override { return TaskPriority::eLow; }

  // Anonymous decoders normally get all their data at once. We have tests where
  // they don't; in these situations, the test re-runs them manually. So no
  // matter what, we don't want to resume by posting a task to the DecodePool.
  void Resume() override { }

private:
  virtual ~AnonymousDecodingTask() { }

  NotNull<RefPtr<Decoder>> mDecoder;
};

} // namespace image
} // namespace mozilla

#endif // mozilla_image_IDecodingTask_h