nsWebPEncoder.h (1961B)
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 #ifndef mozilla_image_encoders_webp_nsWebPEncoder_h 7 #define mozilla_image_encoders_webp_nsWebPEncoder_h 8 9 #include "webp/encode.h" 10 11 #include "imgIEncoder.h" 12 #include "nsCOMPtr.h" 13 14 #include "mozilla/Attributes.h" 15 #include "mozilla/ReentrantMonitor.h" 16 17 #define NS_WEBPENCODER_CID \ 18 {/* a8e5a8e5-bebf-4512-9f50-e41e4748ce28 */ \ 19 0xa8e5a8e5, \ 20 0xbebf, \ 21 0x4512, \ 22 {0x9f, 0x50, 0xe4, 0x1e, 0x47, 0x48, 0xce, 0x28}} 23 24 // Provides WEBP encoding functionality. Use InitFromData() to do the 25 // encoding. See that function definition for encoding options. 26 27 class nsWebPEncoder final : public imgIEncoder { 28 typedef mozilla::ReentrantMonitor ReentrantMonitor; 29 30 public: 31 NS_DECL_THREADSAFE_ISUPPORTS 32 NS_DECL_IMGIENCODER 33 NS_DECL_NSIINPUTSTREAM 34 NS_DECL_NSIASYNCINPUTSTREAM 35 36 nsWebPEncoder(); 37 38 protected: 39 ~nsWebPEncoder(); 40 41 void NotifyListener(); 42 43 bool mFinished; 44 45 // image buffer 46 uint8_t* mImageBuffer; 47 uint32_t mImageBufferSize; 48 uint32_t mImageBufferUsed; 49 50 uint32_t mImageBufferReadPoint; 51 52 nsCOMPtr<nsIInputStreamCallback> mCallback; 53 nsCOMPtr<nsIEventTarget> mCallbackTarget; 54 uint32_t mNotifyThreshold; 55 56 // nsWebPEncoder is designed to allow one thread to pump data into it while 57 // another reads from it. We lock to ensure that the buffer remains 58 // append-only while we read from it (that it is not realloced) and to 59 // ensure that only one thread dispatches a callback for each call to 60 // AsyncWait. 61 ReentrantMonitor mReentrantMonitor MOZ_UNANNOTATED; 62 }; 63 #endif // mozilla_image_encoders_webp_nsWebPEncoder_h