gfx/skia/trunk/include/core/SkImage.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 2012 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 SkImage_DEFINED
michael@0 9 #define SkImage_DEFINED
michael@0 10
michael@0 11 #include "SkImageInfo.h"
michael@0 12 #include "SkImageEncoder.h"
michael@0 13 #include "SkRefCnt.h"
michael@0 14 #include "SkScalar.h"
michael@0 15
michael@0 16 class SkData;
michael@0 17 class SkCanvas;
michael@0 18 class SkPaint;
michael@0 19 class SkShader;
michael@0 20 class GrContext;
michael@0 21 class GrTexture;
michael@0 22
michael@0 23 // need for TileMode
michael@0 24 #include "SkShader.h"
michael@0 25
michael@0 26 /**
michael@0 27 * SkImage is an abstraction for drawing a rectagle of pixels, though the
michael@0 28 * particular type of image could be actually storing its data on the GPU, or
michael@0 29 * as drawing commands (picture or PDF or otherwise), ready to be played back
michael@0 30 * into another canvas.
michael@0 31 *
michael@0 32 * The content of SkImage is always immutable, though the actual storage may
michael@0 33 * change, if for example that image can be re-created via encoded data or
michael@0 34 * other means.
michael@0 35 */
michael@0 36 class SK_API SkImage : public SkRefCnt {
michael@0 37 public:
michael@0 38 SK_DECLARE_INST_COUNT(SkImage)
michael@0 39
michael@0 40 typedef SkImageInfo Info;
michael@0 41
michael@0 42 static SkImage* NewRasterCopy(const Info&, const void* pixels, size_t rowBytes);
michael@0 43 static SkImage* NewRasterData(const Info&, SkData* pixels, size_t rowBytes);
michael@0 44 static SkImage* NewEncodedData(SkData*);
michael@0 45
michael@0 46 /**
michael@0 47 * GrTexture is a more logical parameter for this factory, but its
michael@0 48 * interactions with scratch cache still has issues, so for now we take
michael@0 49 * SkBitmap instead. This will be changed in the future. skbug.com/1449
michael@0 50 */
michael@0 51 static SkImage* NewTexture(const SkBitmap&);
michael@0 52
michael@0 53 int width() const { return fWidth; }
michael@0 54 int height() const { return fHeight; }
michael@0 55 uint32_t uniqueID() const { return fUniqueID; }
michael@0 56
michael@0 57 /**
michael@0 58 * Return the GrTexture that stores the image pixels. Calling getTexture
michael@0 59 * does not affect the reference count of the GrTexture object.
michael@0 60 * Will return NULL if the image does not use a texture.
michael@0 61 */
michael@0 62 GrTexture* getTexture();
michael@0 63
michael@0 64 SkShader* newShaderClamp() const;
michael@0 65 SkShader* newShader(SkShader::TileMode, SkShader::TileMode) const;
michael@0 66
michael@0 67 void draw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*);
michael@0 68
michael@0 69 /**
michael@0 70 * Draw the image, cropped to the src rect, to the dst rect of a canvas.
michael@0 71 * If src is larger than the bounds of the image, the rest of the image is
michael@0 72 * filled with transparent black pixels.
michael@0 73 *
michael@0 74 * See SkCanvas::drawBitmapRectToRect for similar behavior.
michael@0 75 */
michael@0 76 void draw(SkCanvas*, const SkRect* src, const SkRect& dst, const SkPaint*);
michael@0 77
michael@0 78 /**
michael@0 79 * If the image has direct access to its pixels (i.e. they are in local
michael@0 80 * RAM) return the (const) address of those pixels, and if not null, return
michael@0 81 * the ImageInfo and rowBytes. The returned address is only valid while
michael@0 82 * the image object is in scope.
michael@0 83 *
michael@0 84 * On failure, returns NULL and the info and rowBytes parameters are
michael@0 85 * ignored.
michael@0 86 */
michael@0 87 const void* peekPixels(SkImageInfo* info, size_t* rowBytes) const;
michael@0 88
michael@0 89 /**
michael@0 90 * Encode the image's pixels and return the result as a new SkData, which
michael@0 91 * the caller must manage (i.e. call unref() when they are done).
michael@0 92 *
michael@0 93 * If the image type cannot be encoded, or the requested encoder type is
michael@0 94 * not supported, this will return NULL.
michael@0 95 */
michael@0 96 SkData* encode(SkImageEncoder::Type t = SkImageEncoder::kPNG_Type,
michael@0 97 int quality = 80) const;
michael@0 98
michael@0 99 protected:
michael@0 100 SkImage(int width, int height) :
michael@0 101 fWidth(width),
michael@0 102 fHeight(height),
michael@0 103 fUniqueID(NextUniqueID()) {
michael@0 104
michael@0 105 SkASSERT(width >= 0);
michael@0 106 SkASSERT(height >= 0);
michael@0 107 }
michael@0 108
michael@0 109 private:
michael@0 110 const int fWidth;
michael@0 111 const int fHeight;
michael@0 112 const uint32_t fUniqueID;
michael@0 113
michael@0 114 static uint32_t NextUniqueID();
michael@0 115
michael@0 116 typedef SkRefCnt INHERITED;
michael@0 117
michael@0 118 /**
michael@0 119 * Return a copy of the image's pixels, limiting them to the subset
michael@0 120 * rectangle's intersection wit the image bounds. If subset is NULL, then
michael@0 121 * the entire image will be considered.
michael@0 122 *
michael@0 123 * If the bitmap's pixels have already been allocated, then readPixels()
michael@0 124 * will succeed only if it can support converting the image's pixels into
michael@0 125 * the bitmap's ColorType/AlphaType. Any pixels in the bitmap that do not
michael@0 126 * intersect with the image's bounds and the subset (if not null) will be
michael@0 127 * left untouched.
michael@0 128 *
michael@0 129 * If the bitmap is initially empty/unallocated, then it will be allocated
michael@0 130 * using the default allocator, and the ColorType/AlphaType will be chosen
michael@0 131 * to most closely fit the image's configuration.
michael@0 132 *
michael@0 133 * On failure, false will be returned, and bitmap will unmodified.
michael@0 134 */
michael@0 135 // On ice for now:
michael@0 136 // - should it respect the particular colortype/alphatype of the src
michael@0 137 // - should it have separate entrypoints for preallocated and not bitmaps?
michael@0 138 // - isn't it enough to allow the caller to draw() the image into a canvas?
michael@0 139 bool readPixels(SkBitmap* bitmap, const SkIRect* subset = NULL) const;
michael@0 140 };
michael@0 141
michael@0 142 #endif

mercurial