image/encoders/jpeg/nsJPEGEncoder.h

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "imgIEncoder.h"
michael@0 7
michael@0 8 #include "mozilla/ReentrantMonitor.h"
michael@0 9 #include "mozilla/Attributes.h"
michael@0 10
michael@0 11 #include "nsCOMPtr.h"
michael@0 12
michael@0 13 // needed for JPEG library
michael@0 14 #include <stdio.h>
michael@0 15
michael@0 16 extern "C" {
michael@0 17 #include "jpeglib.h"
michael@0 18 }
michael@0 19
michael@0 20 #define NS_JPEGENCODER_CID \
michael@0 21 { /* ac2bb8fe-eeeb-4572-b40f-be03932b56e0 */ \
michael@0 22 0xac2bb8fe, \
michael@0 23 0xeeeb, \
michael@0 24 0x4572, \
michael@0 25 {0xb4, 0x0f, 0xbe, 0x03, 0x93, 0x2b, 0x56, 0xe0} \
michael@0 26 }
michael@0 27
michael@0 28 // Provides JPEG encoding functionality. Use InitFromData() to do the
michael@0 29 // encoding. See that function definition for encoding options.
michael@0 30
michael@0 31 class nsJPEGEncoder MOZ_FINAL : public imgIEncoder
michael@0 32 {
michael@0 33 typedef mozilla::ReentrantMonitor ReentrantMonitor;
michael@0 34 public:
michael@0 35 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 36 NS_DECL_IMGIENCODER
michael@0 37 NS_DECL_NSIINPUTSTREAM
michael@0 38 NS_DECL_NSIASYNCINPUTSTREAM
michael@0 39
michael@0 40 nsJPEGEncoder();
michael@0 41
michael@0 42 private:
michael@0 43 ~nsJPEGEncoder();
michael@0 44
michael@0 45 protected:
michael@0 46
michael@0 47 void ConvertHostARGBRow(const uint8_t* aSrc, uint8_t* aDest,
michael@0 48 uint32_t aPixelWidth);
michael@0 49 void ConvertRGBARow(const uint8_t* aSrc, uint8_t* aDest, uint32_t aPixelWidth);
michael@0 50
michael@0 51 static void initDestination(jpeg_compress_struct* cinfo);
michael@0 52 static boolean emptyOutputBuffer(jpeg_compress_struct* cinfo);
michael@0 53 static void termDestination(jpeg_compress_struct* cinfo);
michael@0 54
michael@0 55 static void errorExit(jpeg_common_struct* cinfo);
michael@0 56
michael@0 57 void NotifyListener();
michael@0 58
michael@0 59 bool mFinished;
michael@0 60
michael@0 61 // image buffer
michael@0 62 uint8_t* mImageBuffer;
michael@0 63 uint32_t mImageBufferSize;
michael@0 64 uint32_t mImageBufferUsed;
michael@0 65
michael@0 66 uint32_t mImageBufferReadPoint;
michael@0 67
michael@0 68 nsCOMPtr<nsIInputStreamCallback> mCallback;
michael@0 69 nsCOMPtr<nsIEventTarget> mCallbackTarget;
michael@0 70 uint32_t mNotifyThreshold;
michael@0 71
michael@0 72 /*
michael@0 73 nsJPEGEncoder is designed to allow one thread to pump data into it while another
michael@0 74 reads from it. We lock to ensure that the buffer remains append-only while
michael@0 75 we read from it (that it is not realloced) and to ensure that only one thread
michael@0 76 dispatches a callback for each call to AsyncWait.
michael@0 77 */
michael@0 78 ReentrantMonitor mReentrantMonitor;
michael@0 79 };

mercurial