gfx/skia/trunk/src/images/SkDecodingImageGenerator.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /*
michael@0 2 * Copyright 2013 Google Inc.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8 #ifndef SkDecodingImageGenerator_DEFINED
michael@0 9 #define SkDecodingImageGenerator_DEFINED
michael@0 10
michael@0 11 #include "SkBitmap.h"
michael@0 12 #include "SkImageGenerator.h"
michael@0 13
michael@0 14 class SkData;
michael@0 15 class SkStreamRewindable;
michael@0 16
michael@0 17 /**
michael@0 18 * An implementation of SkImageGenerator that calls into
michael@0 19 * SkImageDecoder.
michael@0 20 */
michael@0 21 class SkDecodingImageGenerator : public SkImageGenerator {
michael@0 22 public:
michael@0 23 virtual ~SkDecodingImageGenerator();
michael@0 24 virtual SkData* refEncodedData() SK_OVERRIDE;
michael@0 25 // This implementaion of getInfo() always returns true.
michael@0 26 virtual bool getInfo(SkImageInfo* info) SK_OVERRIDE;
michael@0 27 virtual bool getPixels(const SkImageInfo& info,
michael@0 28 void* pixels,
michael@0 29 size_t rowBytes) SK_OVERRIDE;
michael@0 30 /**
michael@0 31 * These options will be passed on to the image decoder. The
michael@0 32 * defaults are sensible.
michael@0 33 *
michael@0 34 * @param fSampleSize If set to > 1, tells the decoder to return a
michael@0 35 * smaller than original bitmap, sampling 1 pixel for
michael@0 36 * every size pixels. e.g. if sample size is set to 3,
michael@0 37 * then the returned bitmap will be 1/3 as wide and high,
michael@0 38 * and will contain 1/9 as many pixels as the original.
michael@0 39 * Note: this is a hint, and the codec may choose to
michael@0 40 * ignore this, or only approximate the sample size.
michael@0 41 *
michael@0 42 * @param fDitherImage Set to true if the the decoder should try to
michael@0 43 * dither the resulting image when decoding to a smaller
michael@0 44 * color-space. The default is true.
michael@0 45 *
michael@0 46 * @param fRequestedColorType If not given, then use whichever
michael@0 47 * config the decoder wants. Else try to use this color
michael@0 48 * type. If the decoder won't support this color type,
michael@0 49 * SkDecodingImageGenerator::Create will return
michael@0 50 * NULL. kIndex_8_SkColorType is not supported.
michael@0 51 */
michael@0 52 struct Options {
michael@0 53 Options()
michael@0 54 : fSampleSize(1)
michael@0 55 , fDitherImage(true)
michael@0 56 , fUseRequestedColorType(false)
michael@0 57 , fRequestedColorType() { }
michael@0 58 Options(int sampleSize, bool dither)
michael@0 59 : fSampleSize(sampleSize)
michael@0 60 , fDitherImage(dither)
michael@0 61 , fUseRequestedColorType(false)
michael@0 62 , fRequestedColorType() { }
michael@0 63 Options(int sampleSize, bool dither, SkColorType colorType)
michael@0 64 : fSampleSize(sampleSize)
michael@0 65 , fDitherImage(dither)
michael@0 66 , fUseRequestedColorType(true)
michael@0 67 , fRequestedColorType(colorType) { }
michael@0 68 const int fSampleSize;
michael@0 69 const bool fDitherImage;
michael@0 70 const bool fUseRequestedColorType;
michael@0 71 const SkColorType fRequestedColorType;
michael@0 72 };
michael@0 73
michael@0 74 /**
michael@0 75 * These two functions return a SkImageGenerator that calls into
michael@0 76 * SkImageDecoder. They return NULL on failure.
michael@0 77 *
michael@0 78 * The SkData version of this function is preferred. If the stream
michael@0 79 * has an underlying SkData (such as a SkMemoryStream) pass that in.
michael@0 80 *
michael@0 81 * This object will unref the stream when done or on failure. Since
michael@0 82 * streams have internal state (position), the caller should not pass
michael@0 83 * a shared stream in. Pass either a new duplicated stream in or
michael@0 84 * transfer ownership of the stream. This factory asserts
michael@0 85 * stream->unique().
michael@0 86 *
michael@0 87 * For example:
michael@0 88 * SkStreamRewindable* stream;
michael@0 89 * ...
michael@0 90 * SkImageGenerator* gen
michael@0 91 * = SkDecodingImageGenerator::Create(
michael@0 92 * stream->duplicate(), SkDecodingImageGenerator::Options());
michael@0 93 * ...
michael@0 94 * SkDELETE(gen);
michael@0 95 *
michael@0 96 * @param Options (see above)
michael@0 97 *
michael@0 98 * @return NULL on failure, a new SkImageGenerator on success.
michael@0 99 */
michael@0 100 static SkImageGenerator* Create(SkStreamRewindable* stream,
michael@0 101 const Options& opt);
michael@0 102
michael@0 103 /**
michael@0 104 * @param data Contains the encoded image data that will be used by
michael@0 105 * the SkDecodingImageGenerator. Will be ref()ed by the
michael@0 106 * SkImageGenerator constructor and and unref()ed on deletion.
michael@0 107 */
michael@0 108 static SkImageGenerator* Create(SkData* data, const Options& opt);
michael@0 109
michael@0 110 private:
michael@0 111 SkData* fData;
michael@0 112 SkStreamRewindable* fStream;
michael@0 113 const SkImageInfo fInfo;
michael@0 114 const int fSampleSize;
michael@0 115 const bool fDitherImage;
michael@0 116
michael@0 117 SkDecodingImageGenerator(SkData* data,
michael@0 118 SkStreamRewindable* stream,
michael@0 119 const SkImageInfo& info,
michael@0 120 int sampleSize,
michael@0 121 bool ditherImage);
michael@0 122 static SkImageGenerator* Create(SkData*, SkStreamRewindable*,
michael@0 123 const Options&);
michael@0 124 typedef SkImageGenerator INHERITED;
michael@0 125 };
michael@0 126
michael@0 127 // // Example of most basic use case:
michael@0 128 //
michael@0 129 // bool install_data(SkData* data, SkBitmap* dst) {
michael@0 130 // return SkInstallDiscardablePixelRef(
michael@0 131 // SkDecodingImageGenerator::Create(
michael@0 132 // data, SkDecodingImageGenerator::Options()), dst, NULL);
michael@0 133 // }
michael@0 134 // bool install_stream(SkStreamRewindable* stream, SkBitmap* dst) {
michael@0 135 // return SkInstallDiscardablePixelRef(
michael@0 136 // SkDecodingImageGenerator::Create(
michael@0 137 // stream, SkDecodingImageGenerator::Options()), dst, NULL);
michael@0 138 // }
michael@0 139
michael@0 140 #endif // SkDecodingImageGenerator_DEFINED

mercurial