gfx/skia/trunk/src/image/SkImage_Codec.cpp

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 #include "SkImageDecoder.h"
michael@0 9 #include "SkImage_Base.h"
michael@0 10 #include "SkBitmap.h"
michael@0 11 #include "SkCanvas.h"
michael@0 12 #include "SkData.h"
michael@0 13
michael@0 14 class SkImage_Codec : public SkImage_Base {
michael@0 15 public:
michael@0 16 static SkImage* NewEmpty();
michael@0 17
michael@0 18 SkImage_Codec(SkData* encodedData, int width, int height);
michael@0 19 virtual ~SkImage_Codec();
michael@0 20
michael@0 21 virtual void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) SK_OVERRIDE;
michael@0 22 virtual void onDrawRectToRect(SkCanvas*, const SkRect*, const SkRect&, const SkPaint*) SK_OVERRIDE;
michael@0 23
michael@0 24 private:
michael@0 25 SkData* fEncodedData;
michael@0 26 SkBitmap fBitmap;
michael@0 27
michael@0 28 typedef SkImage_Base INHERITED;
michael@0 29 };
michael@0 30
michael@0 31 ///////////////////////////////////////////////////////////////////////////////
michael@0 32
michael@0 33 SkImage_Codec::SkImage_Codec(SkData* data, int width, int height) : INHERITED(width, height) {
michael@0 34 fEncodedData = data;
michael@0 35 fEncodedData->ref();
michael@0 36 }
michael@0 37
michael@0 38 SkImage_Codec::~SkImage_Codec() {
michael@0 39 fEncodedData->unref();
michael@0 40 }
michael@0 41
michael@0 42 void SkImage_Codec::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) {
michael@0 43 if (!fBitmap.pixelRef()) {
michael@0 44 if (!SkImageDecoder::DecodeMemory(fEncodedData->bytes(), fEncodedData->size(),
michael@0 45 &fBitmap)) {
michael@0 46 return;
michael@0 47 }
michael@0 48 }
michael@0 49 canvas->drawBitmap(fBitmap, x, y, paint);
michael@0 50 }
michael@0 51
michael@0 52 void SkImage_Codec::onDrawRectToRect(SkCanvas* canvas, const SkRect* src,
michael@0 53 const SkRect& dst, const SkPaint* paint) {
michael@0 54 if (!fBitmap.pixelRef()) {
michael@0 55 if (!SkImageDecoder::DecodeMemory(fEncodedData->bytes(), fEncodedData->size(),
michael@0 56 &fBitmap)) {
michael@0 57 return;
michael@0 58 }
michael@0 59 }
michael@0 60 canvas->drawBitmapRectToRect(fBitmap, src, dst, paint);
michael@0 61 }
michael@0 62
michael@0 63 ///////////////////////////////////////////////////////////////////////////////
michael@0 64
michael@0 65 SkImage* SkImage::NewEncodedData(SkData* data) {
michael@0 66 if (NULL == data) {
michael@0 67 return NULL;
michael@0 68 }
michael@0 69
michael@0 70 SkBitmap bitmap;
michael@0 71 if (!SkImageDecoder::DecodeMemory(data->bytes(), data->size(), &bitmap,
michael@0 72 SkBitmap::kNo_Config,
michael@0 73 SkImageDecoder::kDecodeBounds_Mode)) {
michael@0 74 return NULL;
michael@0 75 }
michael@0 76
michael@0 77 return SkNEW_ARGS(SkImage_Codec, (data, bitmap.width(), bitmap.height()));
michael@0 78 }

mercurial