gfx/skia/trunk/src/animator/SkDrawBitmap.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 /*
michael@0 3 * Copyright 2006 The Android Open Source Project
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9
michael@0 10 #include "SkDrawBitmap.h"
michael@0 11 #include "SkAnimateMaker.h"
michael@0 12 #include "SkCanvas.h"
michael@0 13 #include "SkImageDecoder.h"
michael@0 14 #include "SkPaint.h"
michael@0 15 #include "SkStream.h"
michael@0 16
michael@0 17 #if SK_USE_CONDENSED_INFO == 0
michael@0 18
michael@0 19 const SkMemberInfo SkBaseBitmap::fInfo[] = {
michael@0 20 SK_MEMBER(x, Float),
michael@0 21 SK_MEMBER(y, Float)
michael@0 22 };
michael@0 23
michael@0 24 #endif
michael@0 25
michael@0 26 DEFINE_GET_MEMBER(SkBaseBitmap);
michael@0 27
michael@0 28 SkBaseBitmap::SkBaseBitmap() : x(0), y(0) {
michael@0 29 }
michael@0 30
michael@0 31 SkBaseBitmap::~SkBaseBitmap() {
michael@0 32 }
michael@0 33
michael@0 34 bool SkBaseBitmap::draw(SkAnimateMaker& maker) {
michael@0 35 SkBoundableAuto boundable(this, maker);
michael@0 36 maker.fCanvas->drawBitmap(fBitmap, x, y, maker.fPaint);
michael@0 37 return false;
michael@0 38 }
michael@0 39
michael@0 40 enum SkDrawBitmap_Properties {
michael@0 41 SK_PROPERTY(erase)
michael@0 42 };
michael@0 43
michael@0 44 #if SK_USE_CONDENSED_INFO == 0
michael@0 45
michael@0 46 const SkMemberInfo SkDrawBitmap::fInfo[] = {
michael@0 47 SK_MEMBER_INHERITED,
michael@0 48 SK_MEMBER_PROPERTY(erase, ARGB),
michael@0 49 SK_MEMBER(format, BitmapFormat),
michael@0 50 SK_MEMBER(height, Int),
michael@0 51 SK_MEMBER(rowBytes, Int),
michael@0 52 SK_MEMBER(width, Int),
michael@0 53 };
michael@0 54
michael@0 55 #endif
michael@0 56
michael@0 57 DEFINE_GET_MEMBER(SkDrawBitmap);
michael@0 58
michael@0 59 SkDrawBitmap::SkDrawBitmap() : format((SkBitmap::Config) -1), height(-1),
michael@0 60 rowBytes(0), width(-1), fColor(0), fColorSet(false) {
michael@0 61 }
michael@0 62
michael@0 63 SkDrawBitmap::~SkDrawBitmap() {
michael@0 64 }
michael@0 65
michael@0 66 #ifdef SK_DUMP_ENABLED
michael@0 67 void SkDrawBitmap::dump(SkAnimateMaker* maker) {
michael@0 68 dumpBase(maker);
michael@0 69 dumpAttrs(maker);
michael@0 70 if (fColorSet)
michael@0 71 SkDebugf("erase=\"argb(%d,%d,%d,%d)\" ", SkColorGetA(fColor)/255, SkColorGetR(fColor),
michael@0 72 SkColorGetG(fColor), SkColorGetB(fColor));
michael@0 73 if (rowBytes > 0)
michael@0 74 SkDebugf("rowBytes=\"%d\" ", rowBytes);
michael@0 75 const char* formatName;
michael@0 76 switch (format) {
michael@0 77 case 0: formatName = "none"; break;
michael@0 78 case 1: formatName = "A8"; break;
michael@0 79 case 2: formatName = "Index8"; break;
michael@0 80 case 3: formatName = "RGB16"; break;
michael@0 81 case 4: formatName = "RGB32"; break;
michael@0 82 }
michael@0 83 SkDebugf("format=\"%s\" />\n", formatName);
michael@0 84 }
michael@0 85 #endif
michael@0 86
michael@0 87 void SkDrawBitmap::onEndElement(SkAnimateMaker&) {
michael@0 88 SkASSERT(width != -1);
michael@0 89 SkASSERT(height != -1);
michael@0 90 SkASSERT(rowBytes >= 0);
michael@0 91 fBitmap.setConfig((SkBitmap::Config) format, width, height, rowBytes);
michael@0 92 fBitmap.allocPixels();
michael@0 93 if (fColorSet)
michael@0 94 fBitmap.eraseColor(fColor);
michael@0 95 }
michael@0 96
michael@0 97 bool SkDrawBitmap::setProperty(int index, SkScriptValue& value)
michael@0 98 {
michael@0 99 switch (index) {
michael@0 100 case SK_PROPERTY(erase):
michael@0 101 SkASSERT(value.fType == SkType_ARGB);
michael@0 102 fColor = value.fOperand.fS32;
michael@0 103 fColorSet = true;
michael@0 104 break;
michael@0 105 default:
michael@0 106 SkASSERT(0);
michael@0 107 return false;
michael@0 108 }
michael@0 109 return true;
michael@0 110 }
michael@0 111
michael@0 112
michael@0 113 enum SkImageBaseBitmap_Properties {
michael@0 114 SK_PROPERTY(height),
michael@0 115 SK_PROPERTY(width)
michael@0 116 };
michael@0 117
michael@0 118 #if SK_USE_CONDENSED_INFO == 0
michael@0 119
michael@0 120 const SkMemberInfo SkImageBaseBitmap::fInfo[] = {
michael@0 121 SK_MEMBER_INHERITED,
michael@0 122 SK_MEMBER(base64, Base64),
michael@0 123 SK_MEMBER_PROPERTY(height, Int),
michael@0 124 SK_MEMBER(src, String),
michael@0 125 SK_MEMBER_PROPERTY(width, Int)
michael@0 126 };
michael@0 127
michael@0 128 #endif
michael@0 129
michael@0 130 DEFINE_GET_MEMBER(SkImageBaseBitmap);
michael@0 131
michael@0 132 SkImageBaseBitmap::SkImageBaseBitmap() : fDirty(true), fUriBase(NULL) {
michael@0 133 base64.fData = NULL;
michael@0 134 base64.fLength = 0;
michael@0 135 }
michael@0 136
michael@0 137 SkImageBaseBitmap::~SkImageBaseBitmap() {
michael@0 138 delete[] base64.fData;
michael@0 139 }
michael@0 140
michael@0 141 SkDisplayable* SkImageBaseBitmap::deepCopy(SkAnimateMaker* maker) {
michael@0 142 SkDisplayable* copy = INHERITED::deepCopy(maker);
michael@0 143 ((SkImageBaseBitmap*) copy)->fUriBase = ((SkImageBaseBitmap*) this)->fUriBase;
michael@0 144 return copy;
michael@0 145 }
michael@0 146
michael@0 147 void SkImageBaseBitmap::dirty() {
michael@0 148 fDirty = true;
michael@0 149 }
michael@0 150
michael@0 151 bool SkImageBaseBitmap::draw(SkAnimateMaker& maker) {
michael@0 152 if (fDirty)
michael@0 153 resolve();
michael@0 154 return INHERITED::draw(maker);
michael@0 155 }
michael@0 156
michael@0 157 bool SkImageBaseBitmap::getProperty(int index, SkScriptValue* value) const {
michael@0 158 if (fDirty)
michael@0 159 resolve();
michael@0 160 switch (index) {
michael@0 161 case SK_PROPERTY(height):
michael@0 162 value->fOperand.fS32 = fBitmap.height();
michael@0 163 break;
michael@0 164 case SK_PROPERTY(width):
michael@0 165 value->fOperand.fS32 = fBitmap.width();
michael@0 166 break;
michael@0 167 default:
michael@0 168 SkASSERT(0);
michael@0 169 return false;
michael@0 170 }
michael@0 171 value->fType = SkType_Int;
michael@0 172 return true;
michael@0 173 }
michael@0 174
michael@0 175 void SkImageBaseBitmap::onEndElement(SkAnimateMaker& maker) {
michael@0 176 fUriBase = maker.fPrefix.c_str();
michael@0 177 }
michael@0 178
michael@0 179 void SkImageBaseBitmap::resolve() {
michael@0 180 fDirty = false;
michael@0 181 if (base64.fData) {
michael@0 182 fBitmap.reset();
michael@0 183 SkImageDecoder::DecodeMemory(base64.fData, base64.fLength, &fBitmap);
michael@0 184 } else if (src.size()) {
michael@0 185 if (fLast.equals(src))
michael@0 186 return;
michael@0 187 fLast.set(src);
michael@0 188 fBitmap.reset();
michael@0 189
michael@0 190 //SkStream* stream = SkStream::GetURIStream(fUriBase, src.c_str());
michael@0 191 SkAutoTUnref<SkStreamAsset> stream(SkStream::NewFromFile(src.c_str()));
michael@0 192 if (stream.get()) {
michael@0 193 SkImageDecoder::DecodeStream(stream, &fBitmap);
michael@0 194 }
michael@0 195 }
michael@0 196 }

mercurial