1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
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/. */
6 
7 #ifndef mozilla_dom_ImageBitmapFormatUtils_h
8 #define mozilla_dom_ImageBitmapFormatUtils_h
9 
10 #include "mozilla/UniquePtr.h"
11 #include "nsTArrayForwardDeclare.h"
12 
13 namespace mozilla {
14 
15 namespace layers {
16 class Image;
17 }
18 
19 class ErrorResult;
20 
21 namespace dom {
22 
23 struct ChannelPixelLayout;
24 enum class ImageBitmapFormat : uint8_t;
25 
26 typedef nsTArray<ChannelPixelLayout> ImagePixelLayout;
27 
28 /*
29  * ImageUtils is a wrapper around layers::Image. It provides three unified
30  * methods to all sub-classes of layers::Image, which are:
31  *
32  * (1) GetFormat() converts the image's format into ImageBitmapFormat enum.
33  * (2) GetBufferLength() returns the number of bytes that are used to store
34  *     the image's underlying raw data.
35  *
36  * In theory, the functionalities of this class could be merged into the
37  * interface of layers::Image. However, this is designed as a isolated wrapper
38  * because we don't want to pollute the layers::Image's interface with methods
39  * that are only meaningful to the ImageBitmap.
40  */
41 class ImageUtils {
42  public:
43   class Impl;
44   ImageUtils() = delete;
45   ImageUtils(const ImageUtils&) = delete;
46   ImageUtils(ImageUtils&&) = delete;
47   ImageUtils& operator=(const ImageUtils&) = delete;
48   ImageUtils& operator=(ImageUtils&&) = delete;
49 
50   explicit ImageUtils(layers::Image* aImage);
51   ~ImageUtils();
52 
53   ImageBitmapFormat GetFormat() const;
54 
55   uint32_t GetBufferLength() const;
56 
57  protected:
58   Impl* mImpl;
59 };
60 
61 }  // namespace dom
62 }  // namespace mozilla
63 
64 #endif /* mozilla_dom_ImageBitmapFormatUtils_h */
65