gfx/2d/RecordedEvent.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
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: 20; 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 "RecordedEvent.h"
michael@0 7 #include "PathRecording.h"
michael@0 8
michael@0 9 #include "Tools.h"
michael@0 10 #include "Filters.h"
michael@0 11
michael@0 12 namespace mozilla {
michael@0 13 namespace gfx {
michael@0 14
michael@0 15 using namespace std;
michael@0 16
michael@0 17 static std::string NameFromBackend(BackendType aType)
michael@0 18 {
michael@0 19 switch (aType) {
michael@0 20 case BackendType::NONE:
michael@0 21 return "None";
michael@0 22 case BackendType::DIRECT2D:
michael@0 23 return "Direct2D";
michael@0 24 default:
michael@0 25 return "Unknown";
michael@0 26 }
michael@0 27 }
michael@0 28
michael@0 29 #define LOAD_EVENT_TYPE(_typeenum, _class) \
michael@0 30 case _typeenum: return new _class(aStream)
michael@0 31
michael@0 32 RecordedEvent *
michael@0 33 RecordedEvent::LoadEventFromStream(std::istream &aStream, EventType aType)
michael@0 34 {
michael@0 35 switch (aType) {
michael@0 36 LOAD_EVENT_TYPE(DRAWTARGETCREATION, RecordedDrawTargetCreation);
michael@0 37 LOAD_EVENT_TYPE(DRAWTARGETDESTRUCTION, RecordedDrawTargetDestruction);
michael@0 38 LOAD_EVENT_TYPE(FILLRECT, RecordedFillRect);
michael@0 39 LOAD_EVENT_TYPE(STROKERECT, RecordedStrokeRect);
michael@0 40 LOAD_EVENT_TYPE(STROKELINE, RecordedStrokeLine);
michael@0 41 LOAD_EVENT_TYPE(CLEARRECT, RecordedClearRect);
michael@0 42 LOAD_EVENT_TYPE(COPYSURFACE, RecordedCopySurface);
michael@0 43 LOAD_EVENT_TYPE(SETTRANSFORM, RecordedSetTransform);
michael@0 44 LOAD_EVENT_TYPE(PUSHCLIPRECT, RecordedPushClipRect);
michael@0 45 LOAD_EVENT_TYPE(PUSHCLIP, RecordedPushClip);
michael@0 46 LOAD_EVENT_TYPE(POPCLIP, RecordedPopClip);
michael@0 47 LOAD_EVENT_TYPE(FILL, RecordedFill);
michael@0 48 LOAD_EVENT_TYPE(FILLGLYPHS, RecordedFillGlyphs);
michael@0 49 LOAD_EVENT_TYPE(MASK, RecordedMask);
michael@0 50 LOAD_EVENT_TYPE(STROKE, RecordedStroke);
michael@0 51 LOAD_EVENT_TYPE(DRAWSURFACE, RecordedDrawSurface);
michael@0 52 LOAD_EVENT_TYPE(DRAWSURFACEWITHSHADOW, RecordedDrawSurfaceWithShadow);
michael@0 53 LOAD_EVENT_TYPE(DRAWFILTER, RecordedDrawFilter);
michael@0 54 LOAD_EVENT_TYPE(PATHCREATION, RecordedPathCreation);
michael@0 55 LOAD_EVENT_TYPE(PATHDESTRUCTION, RecordedPathDestruction);
michael@0 56 LOAD_EVENT_TYPE(SOURCESURFACECREATION, RecordedSourceSurfaceCreation);
michael@0 57 LOAD_EVENT_TYPE(SOURCESURFACEDESTRUCTION, RecordedSourceSurfaceDestruction);
michael@0 58 LOAD_EVENT_TYPE(FILTERNODECREATION, RecordedFilterNodeCreation);
michael@0 59 LOAD_EVENT_TYPE(FILTERNODEDESTRUCTION, RecordedFilterNodeDestruction);
michael@0 60 LOAD_EVENT_TYPE(GRADIENTSTOPSCREATION, RecordedGradientStopsCreation);
michael@0 61 LOAD_EVENT_TYPE(GRADIENTSTOPSDESTRUCTION, RecordedGradientStopsDestruction);
michael@0 62 LOAD_EVENT_TYPE(SNAPSHOT, RecordedSnapshot);
michael@0 63 LOAD_EVENT_TYPE(SCALEDFONTCREATION, RecordedScaledFontCreation);
michael@0 64 LOAD_EVENT_TYPE(SCALEDFONTDESTRUCTION, RecordedScaledFontDestruction);
michael@0 65 LOAD_EVENT_TYPE(MASKSURFACE, RecordedMaskSurface);
michael@0 66 LOAD_EVENT_TYPE(FILTERNODESETATTRIBUTE, RecordedFilterNodeSetAttribute);
michael@0 67 LOAD_EVENT_TYPE(FILTERNODESETINPUT, RecordedFilterNodeSetInput);
michael@0 68 default:
michael@0 69 return nullptr;
michael@0 70 }
michael@0 71 }
michael@0 72
michael@0 73 string
michael@0 74 RecordedEvent::GetEventName(EventType aType)
michael@0 75 {
michael@0 76 switch (aType) {
michael@0 77 case DRAWTARGETCREATION:
michael@0 78 return "DrawTarget Creation";
michael@0 79 case DRAWTARGETDESTRUCTION:
michael@0 80 return "DrawTarget Destruction";
michael@0 81 case FILLRECT:
michael@0 82 return "FillRect";
michael@0 83 case STROKERECT:
michael@0 84 return "StrokeRect";
michael@0 85 case STROKELINE:
michael@0 86 return "StrokeLine";
michael@0 87 case CLEARRECT:
michael@0 88 return "ClearRect";
michael@0 89 case COPYSURFACE:
michael@0 90 return "CopySurface";
michael@0 91 case SETTRANSFORM:
michael@0 92 return "SetTransform";
michael@0 93 case PUSHCLIP:
michael@0 94 return "PushClip";
michael@0 95 case PUSHCLIPRECT:
michael@0 96 return "PushClipRect";
michael@0 97 case POPCLIP:
michael@0 98 return "PopClip";
michael@0 99 case FILL:
michael@0 100 return "Fill";
michael@0 101 case FILLGLYPHS:
michael@0 102 return "FillGlyphs";
michael@0 103 case MASK:
michael@0 104 return "Mask";
michael@0 105 case STROKE:
michael@0 106 return "Stroke";
michael@0 107 case DRAWSURFACE:
michael@0 108 return "DrawSurface";
michael@0 109 case DRAWSURFACEWITHSHADOW:
michael@0 110 return "DrawSurfaceWithShadow";
michael@0 111 case DRAWFILTER:
michael@0 112 return "DrawFilter";
michael@0 113 case PATHCREATION:
michael@0 114 return "PathCreation";
michael@0 115 case PATHDESTRUCTION:
michael@0 116 return "PathDestruction";
michael@0 117 case SOURCESURFACECREATION:
michael@0 118 return "SourceSurfaceCreation";
michael@0 119 case SOURCESURFACEDESTRUCTION:
michael@0 120 return "SourceSurfaceDestruction";
michael@0 121 case FILTERNODECREATION:
michael@0 122 return "FilterNodeCreation";
michael@0 123 case FILTERNODEDESTRUCTION:
michael@0 124 return "FilterNodeDestruction";
michael@0 125 case GRADIENTSTOPSCREATION:
michael@0 126 return "GradientStopsCreation";
michael@0 127 case GRADIENTSTOPSDESTRUCTION:
michael@0 128 return "GradientStopsDestruction";
michael@0 129 case SNAPSHOT:
michael@0 130 return "Snapshot";
michael@0 131 case SCALEDFONTCREATION:
michael@0 132 return "ScaledFontCreation";
michael@0 133 case SCALEDFONTDESTRUCTION:
michael@0 134 return "ScaledFontDestruction";
michael@0 135 case MASKSURFACE:
michael@0 136 return "MaskSurface";
michael@0 137 case FILTERNODESETATTRIBUTE:
michael@0 138 return "SetAttribute";
michael@0 139 case FILTERNODESETINPUT:
michael@0 140 return "SetInput";
michael@0 141 default:
michael@0 142 return "Unknown";
michael@0 143 }
michael@0 144 }
michael@0 145
michael@0 146 void
michael@0 147 RecordedEvent::RecordPatternData(std::ostream &aStream, const PatternStorage &aPattern) const
michael@0 148 {
michael@0 149 WriteElement(aStream, aPattern.mType);
michael@0 150
michael@0 151 switch (aPattern.mType) {
michael@0 152 case PatternType::COLOR:
michael@0 153 {
michael@0 154 WriteElement(aStream, *reinterpret_cast<const ColorPatternStorage*>(&aPattern.mStorage));
michael@0 155 return;
michael@0 156 }
michael@0 157 case PatternType::LINEAR_GRADIENT:
michael@0 158 {
michael@0 159 WriteElement(aStream, *reinterpret_cast<const LinearGradientPatternStorage*>(&aPattern.mStorage));
michael@0 160 return;
michael@0 161 }
michael@0 162 case PatternType::RADIAL_GRADIENT:
michael@0 163 {
michael@0 164 WriteElement(aStream, *reinterpret_cast<const RadialGradientPatternStorage*>(&aPattern.mStorage));
michael@0 165 return;
michael@0 166 }
michael@0 167 case PatternType::SURFACE:
michael@0 168 {
michael@0 169 WriteElement(aStream, *reinterpret_cast<const SurfacePatternStorage*>(&aPattern.mStorage));
michael@0 170 return;
michael@0 171 }
michael@0 172 default:
michael@0 173 return;
michael@0 174 }
michael@0 175 }
michael@0 176
michael@0 177 void
michael@0 178 RecordedEvent::ReadPatternData(std::istream &aStream, PatternStorage &aPattern) const
michael@0 179 {
michael@0 180 ReadElement(aStream, aPattern.mType);
michael@0 181
michael@0 182 switch (aPattern.mType) {
michael@0 183 case PatternType::COLOR:
michael@0 184 {
michael@0 185 ReadElement(aStream, *reinterpret_cast<ColorPatternStorage*>(&aPattern.mStorage));
michael@0 186 return;
michael@0 187 }
michael@0 188 case PatternType::LINEAR_GRADIENT:
michael@0 189 {
michael@0 190 ReadElement(aStream, *reinterpret_cast<LinearGradientPatternStorage*>(&aPattern.mStorage));
michael@0 191 return;
michael@0 192 }
michael@0 193 case PatternType::RADIAL_GRADIENT:
michael@0 194 {
michael@0 195 ReadElement(aStream, *reinterpret_cast<RadialGradientPatternStorage*>(&aPattern.mStorage));
michael@0 196 return;
michael@0 197 }
michael@0 198 case PatternType::SURFACE:
michael@0 199 {
michael@0 200 ReadElement(aStream, *reinterpret_cast<SurfacePatternStorage*>(&aPattern.mStorage));
michael@0 201 return;
michael@0 202 }
michael@0 203 default:
michael@0 204 return;
michael@0 205 }
michael@0 206 }
michael@0 207
michael@0 208 void
michael@0 209 RecordedEvent::StorePattern(PatternStorage &aDestination, const Pattern &aSource) const
michael@0 210 {
michael@0 211 aDestination.mType = aSource.GetType();
michael@0 212
michael@0 213 switch (aSource.GetType()) {
michael@0 214 case PatternType::COLOR:
michael@0 215 {
michael@0 216 reinterpret_cast<ColorPatternStorage*>(&aDestination.mStorage)->mColor =
michael@0 217 static_cast<const ColorPattern*>(&aSource)->mColor;
michael@0 218 return;
michael@0 219 }
michael@0 220 case PatternType::LINEAR_GRADIENT:
michael@0 221 {
michael@0 222 LinearGradientPatternStorage *store =
michael@0 223 reinterpret_cast<LinearGradientPatternStorage*>(&aDestination.mStorage);
michael@0 224 const LinearGradientPattern *pat =
michael@0 225 static_cast<const LinearGradientPattern*>(&aSource);
michael@0 226 store->mBegin = pat->mBegin;
michael@0 227 store->mEnd = pat->mEnd;
michael@0 228 store->mMatrix = pat->mMatrix;
michael@0 229 store->mStops = pat->mStops.get();
michael@0 230 return;
michael@0 231 }
michael@0 232 case PatternType::RADIAL_GRADIENT:
michael@0 233 {
michael@0 234 RadialGradientPatternStorage *store =
michael@0 235 reinterpret_cast<RadialGradientPatternStorage*>(&aDestination.mStorage);
michael@0 236 const RadialGradientPattern *pat =
michael@0 237 static_cast<const RadialGradientPattern*>(&aSource);
michael@0 238 store->mCenter1 = pat->mCenter1;
michael@0 239 store->mCenter2 = pat->mCenter2;
michael@0 240 store->mRadius1 = pat->mRadius1;
michael@0 241 store->mRadius2 = pat->mRadius2;
michael@0 242 store->mMatrix = pat->mMatrix;
michael@0 243 store->mStops = pat->mStops.get();
michael@0 244 return;
michael@0 245 }
michael@0 246 case PatternType::SURFACE:
michael@0 247 {
michael@0 248 SurfacePatternStorage *store =
michael@0 249 reinterpret_cast<SurfacePatternStorage*>(&aDestination.mStorage);
michael@0 250 const SurfacePattern *pat =
michael@0 251 static_cast<const SurfacePattern*>(&aSource);
michael@0 252 store->mExtend = pat->mExtendMode;
michael@0 253 store->mFilter = pat->mFilter;
michael@0 254 store->mMatrix = pat->mMatrix;
michael@0 255 store->mSurface = pat->mSurface;
michael@0 256 return;
michael@0 257 }
michael@0 258 }
michael@0 259 }
michael@0 260
michael@0 261 void
michael@0 262 RecordedEvent::RecordStrokeOptions(std::ostream &aStream, const StrokeOptions &aStrokeOptions) const
michael@0 263 {
michael@0 264 JoinStyle joinStyle = aStrokeOptions.mLineJoin;
michael@0 265 CapStyle capStyle = aStrokeOptions.mLineCap;
michael@0 266
michael@0 267 WriteElement(aStream, uint64_t(aStrokeOptions.mDashLength));
michael@0 268 WriteElement(aStream, aStrokeOptions.mDashOffset);
michael@0 269 WriteElement(aStream, aStrokeOptions.mLineWidth);
michael@0 270 WriteElement(aStream, aStrokeOptions.mMiterLimit);
michael@0 271 WriteElement(aStream, joinStyle);
michael@0 272 WriteElement(aStream, capStyle);
michael@0 273
michael@0 274 if (!aStrokeOptions.mDashPattern) {
michael@0 275 return;
michael@0 276 }
michael@0 277
michael@0 278 aStream.write((char*)aStrokeOptions.mDashPattern, sizeof(Float) * aStrokeOptions.mDashLength);
michael@0 279 }
michael@0 280
michael@0 281 void
michael@0 282 RecordedEvent::ReadStrokeOptions(std::istream &aStream, StrokeOptions &aStrokeOptions)
michael@0 283 {
michael@0 284 uint64_t dashLength;
michael@0 285 JoinStyle joinStyle;
michael@0 286 CapStyle capStyle;
michael@0 287
michael@0 288 ReadElement(aStream, dashLength);
michael@0 289 ReadElement(aStream, aStrokeOptions.mDashOffset);
michael@0 290 ReadElement(aStream, aStrokeOptions.mLineWidth);
michael@0 291 ReadElement(aStream, aStrokeOptions.mMiterLimit);
michael@0 292 ReadElement(aStream, joinStyle);
michael@0 293 ReadElement(aStream, capStyle);
michael@0 294 // On 32 bit we truncate the value of dashLength.
michael@0 295 // See also bug 811850 for history.
michael@0 296 aStrokeOptions.mDashLength = size_t(dashLength);
michael@0 297 aStrokeOptions.mLineJoin = joinStyle;
michael@0 298 aStrokeOptions.mLineCap = capStyle;
michael@0 299
michael@0 300 if (!aStrokeOptions.mDashLength) {
michael@0 301 return;
michael@0 302 }
michael@0 303
michael@0 304 mDashPatternStorage.resize(aStrokeOptions.mDashLength);
michael@0 305 aStrokeOptions.mDashPattern = &mDashPatternStorage.front();
michael@0 306 aStream.read((char*)aStrokeOptions.mDashPattern, sizeof(Float) * aStrokeOptions.mDashLength);
michael@0 307 }
michael@0 308
michael@0 309 void
michael@0 310 RecordedEvent::OutputSimplePatternInfo(const PatternStorage &aStorage, std::stringstream &aOutput) const
michael@0 311 {
michael@0 312 switch (aStorage.mType) {
michael@0 313 case PatternType::COLOR:
michael@0 314 {
michael@0 315 const Color color = reinterpret_cast<const ColorPatternStorage*>(&aStorage.mStorage)->mColor;
michael@0 316 aOutput << "Color: (" << color.r << ", " << color.g << ", " << color.b << ", " << color.a << ")";
michael@0 317 return;
michael@0 318 }
michael@0 319 case PatternType::LINEAR_GRADIENT:
michael@0 320 {
michael@0 321 const LinearGradientPatternStorage *store =
michael@0 322 reinterpret_cast<const LinearGradientPatternStorage*>(&aStorage.mStorage);
michael@0 323
michael@0 324 aOutput << "LinearGradient (" << store->mBegin.x << ", " << store->mBegin.y <<
michael@0 325 ") - (" << store->mEnd.x << ", " << store->mEnd.y << ") Stops: " << store->mStops;
michael@0 326 return;
michael@0 327 }
michael@0 328 case PatternType::RADIAL_GRADIENT:
michael@0 329 {
michael@0 330 const RadialGradientPatternStorage *store =
michael@0 331 reinterpret_cast<const RadialGradientPatternStorage*>(&aStorage.mStorage);
michael@0 332 aOutput << "RadialGradient (Center 1: (" << store->mCenter1.x << ", " <<
michael@0 333 store->mCenter2.y << ") Radius 2: " << store->mRadius2;
michael@0 334 return;
michael@0 335 }
michael@0 336 case PatternType::SURFACE:
michael@0 337 {
michael@0 338 const SurfacePatternStorage *store =
michael@0 339 reinterpret_cast<const SurfacePatternStorage*>(&aStorage.mStorage);
michael@0 340 aOutput << "Surface (0x" << store->mSurface << ")";
michael@0 341 return;
michael@0 342 }
michael@0 343 }
michael@0 344 }
michael@0 345
michael@0 346 RecordedDrawingEvent::RecordedDrawingEvent(EventType aType, std::istream &aStream)
michael@0 347 : RecordedEvent(aType)
michael@0 348 {
michael@0 349 ReadElement(aStream, mDT);
michael@0 350 }
michael@0 351
michael@0 352 void
michael@0 353 RecordedDrawingEvent::RecordToStream(ostream &aStream) const
michael@0 354 {
michael@0 355 WriteElement(aStream, mDT);
michael@0 356 }
michael@0 357
michael@0 358 ReferencePtr
michael@0 359 RecordedDrawingEvent::GetObjectRef() const
michael@0 360 {
michael@0 361 return mDT;
michael@0 362 }
michael@0 363
michael@0 364 void
michael@0 365 RecordedDrawTargetCreation::PlayEvent(Translator *aTranslator) const
michael@0 366 {
michael@0 367 RefPtr<DrawTarget> newDT =
michael@0 368 aTranslator->GetReferenceDrawTarget()->CreateSimilarDrawTarget(mSize, mFormat);
michael@0 369 aTranslator->AddDrawTarget(mRefPtr, newDT);
michael@0 370
michael@0 371 if (mHasExistingData) {
michael@0 372 Rect dataRect(0, 0, mExistingData->GetSize().width, mExistingData->GetSize().height);
michael@0 373 newDT->DrawSurface(mExistingData, dataRect, dataRect);
michael@0 374 }
michael@0 375 }
michael@0 376
michael@0 377 void
michael@0 378 RecordedDrawTargetCreation::RecordToStream(ostream &aStream) const
michael@0 379 {
michael@0 380 WriteElement(aStream, mRefPtr);
michael@0 381 WriteElement(aStream, mBackendType);
michael@0 382 WriteElement(aStream, mSize);
michael@0 383 WriteElement(aStream, mFormat);
michael@0 384 WriteElement(aStream, mHasExistingData);
michael@0 385
michael@0 386 if (mHasExistingData) {
michael@0 387 MOZ_ASSERT(mExistingData);
michael@0 388 MOZ_ASSERT(mExistingData->GetSize() == mSize);
michael@0 389 RefPtr<DataSourceSurface> dataSurf = mExistingData->GetDataSurface();
michael@0 390 for (int y = 0; y < mSize.height; y++) {
michael@0 391 aStream.write((const char*)dataSurf->GetData() + y * dataSurf->Stride(),
michael@0 392 BytesPerPixel(mFormat) * mSize.width);
michael@0 393 }
michael@0 394 }
michael@0 395 }
michael@0 396
michael@0 397 RecordedDrawTargetCreation::RecordedDrawTargetCreation(istream &aStream)
michael@0 398 : RecordedEvent(DRAWTARGETCREATION)
michael@0 399 {
michael@0 400 ReadElement(aStream, mRefPtr);
michael@0 401 ReadElement(aStream, mBackendType);
michael@0 402 ReadElement(aStream, mSize);
michael@0 403 ReadElement(aStream, mFormat);
michael@0 404 ReadElement(aStream, mHasExistingData);
michael@0 405
michael@0 406 if (mHasExistingData) {
michael@0 407 RefPtr<DataSourceSurface> dataSurf = Factory::CreateDataSourceSurface(mSize, mFormat);
michael@0 408 for (int y = 0; y < mSize.height; y++) {
michael@0 409 aStream.read((char*)dataSurf->GetData() + y * dataSurf->Stride(),
michael@0 410 BytesPerPixel(mFormat) * mSize.width);
michael@0 411 }
michael@0 412 mExistingData = dataSurf;
michael@0 413 }
michael@0 414 }
michael@0 415
michael@0 416 void
michael@0 417 RecordedDrawTargetCreation::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 418 {
michael@0 419 aStringStream << "[" << mRefPtr << "] DrawTarget Creation (Type: " << NameFromBackend(mBackendType) << ", Size: " << mSize.width << "x" << mSize.height << ")";
michael@0 420 }
michael@0 421
michael@0 422
michael@0 423 void
michael@0 424 RecordedDrawTargetDestruction::PlayEvent(Translator *aTranslator) const
michael@0 425 {
michael@0 426 aTranslator->RemoveDrawTarget(mRefPtr);
michael@0 427 }
michael@0 428
michael@0 429 void
michael@0 430 RecordedDrawTargetDestruction::RecordToStream(ostream &aStream) const
michael@0 431 {
michael@0 432 WriteElement(aStream, mRefPtr);
michael@0 433 }
michael@0 434
michael@0 435 RecordedDrawTargetDestruction::RecordedDrawTargetDestruction(istream &aStream)
michael@0 436 : RecordedEvent(DRAWTARGETDESTRUCTION)
michael@0 437 {
michael@0 438 ReadElement(aStream, mRefPtr);
michael@0 439 }
michael@0 440
michael@0 441 void
michael@0 442 RecordedDrawTargetDestruction::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 443 {
michael@0 444 aStringStream << "[" << mRefPtr << "] DrawTarget Destruction";
michael@0 445 }
michael@0 446
michael@0 447 struct GenericPattern
michael@0 448 {
michael@0 449 GenericPattern(const PatternStorage &aStorage, Translator *aTranslator)
michael@0 450 : mPattern(nullptr), mTranslator(aTranslator)
michael@0 451 {
michael@0 452 mStorage = const_cast<PatternStorage*>(&aStorage);
michael@0 453 }
michael@0 454
michael@0 455 ~GenericPattern() {
michael@0 456 if (mPattern) {
michael@0 457 mPattern->~Pattern();
michael@0 458 }
michael@0 459 }
michael@0 460
michael@0 461 operator Pattern*()
michael@0 462 {
michael@0 463 switch(mStorage->mType) {
michael@0 464 case PatternType::COLOR:
michael@0 465 return new (mColPat) ColorPattern(reinterpret_cast<ColorPatternStorage*>(&mStorage->mStorage)->mColor);
michael@0 466 case PatternType::SURFACE:
michael@0 467 {
michael@0 468 SurfacePatternStorage *storage = reinterpret_cast<SurfacePatternStorage*>(&mStorage->mStorage);
michael@0 469 mPattern =
michael@0 470 new (mSurfPat) SurfacePattern(mTranslator->LookupSourceSurface(storage->mSurface),
michael@0 471 storage->mExtend, storage->mMatrix, storage->mFilter);
michael@0 472 return mPattern;
michael@0 473 }
michael@0 474 case PatternType::LINEAR_GRADIENT:
michael@0 475 {
michael@0 476 LinearGradientPatternStorage *storage = reinterpret_cast<LinearGradientPatternStorage*>(&mStorage->mStorage);
michael@0 477 mPattern =
michael@0 478 new (mLinGradPat) LinearGradientPattern(storage->mBegin, storage->mEnd,
michael@0 479 mTranslator->LookupGradientStops(storage->mStops),
michael@0 480 storage->mMatrix);
michael@0 481 return mPattern;
michael@0 482 }
michael@0 483 case PatternType::RADIAL_GRADIENT:
michael@0 484 {
michael@0 485 RadialGradientPatternStorage *storage = reinterpret_cast<RadialGradientPatternStorage*>(&mStorage->mStorage);
michael@0 486 mPattern =
michael@0 487 new (mRadGradPat) RadialGradientPattern(storage->mCenter1, storage->mCenter2,
michael@0 488 storage->mRadius1, storage->mRadius2,
michael@0 489 mTranslator->LookupGradientStops(storage->mStops),
michael@0 490 storage->mMatrix);
michael@0 491 return mPattern;
michael@0 492 }
michael@0 493 default:
michael@0 494 return new (mColPat) ColorPattern(Color());
michael@0 495 }
michael@0 496
michael@0 497 return mPattern;
michael@0 498 }
michael@0 499
michael@0 500 union {
michael@0 501 char mColPat[sizeof(ColorPattern)];
michael@0 502 char mLinGradPat[sizeof(LinearGradientPattern)];
michael@0 503 char mRadGradPat[sizeof(RadialGradientPattern)];
michael@0 504 char mSurfPat[sizeof(SurfacePattern)];
michael@0 505 };
michael@0 506
michael@0 507 PatternStorage *mStorage;
michael@0 508 Pattern *mPattern;
michael@0 509 Translator *mTranslator;
michael@0 510 };
michael@0 511
michael@0 512 void
michael@0 513 RecordedFillRect::PlayEvent(Translator *aTranslator) const
michael@0 514 {
michael@0 515 aTranslator->LookupDrawTarget(mDT)->FillRect(mRect, *GenericPattern(mPattern, aTranslator), mOptions);
michael@0 516 }
michael@0 517
michael@0 518 void
michael@0 519 RecordedFillRect::RecordToStream(ostream &aStream) const
michael@0 520 {
michael@0 521 RecordedDrawingEvent::RecordToStream(aStream);
michael@0 522 WriteElement(aStream, mRect);
michael@0 523 WriteElement(aStream, mOptions);
michael@0 524 RecordPatternData(aStream, mPattern);
michael@0 525 }
michael@0 526
michael@0 527 RecordedFillRect::RecordedFillRect(istream &aStream)
michael@0 528 : RecordedDrawingEvent(FILLRECT, aStream)
michael@0 529 {
michael@0 530 ReadElement(aStream, mRect);
michael@0 531 ReadElement(aStream, mOptions);
michael@0 532 ReadPatternData(aStream, mPattern);
michael@0 533 }
michael@0 534
michael@0 535 void
michael@0 536 RecordedFillRect::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 537 {
michael@0 538 aStringStream << "[" << mDT << "] FillRect (" << mRect.x << ", " << mRect.y << " - " << mRect.width << " x " << mRect.height << ") ";
michael@0 539 OutputSimplePatternInfo(mPattern, aStringStream);
michael@0 540 }
michael@0 541
michael@0 542 void
michael@0 543 RecordedStrokeRect::PlayEvent(Translator *aTranslator) const
michael@0 544 {
michael@0 545 aTranslator->LookupDrawTarget(mDT)->StrokeRect(mRect, *GenericPattern(mPattern, aTranslator), mStrokeOptions, mOptions);
michael@0 546 }
michael@0 547
michael@0 548 void
michael@0 549 RecordedStrokeRect::RecordToStream(ostream &aStream) const
michael@0 550 {
michael@0 551 RecordedDrawingEvent::RecordToStream(aStream);
michael@0 552 WriteElement(aStream, mRect);
michael@0 553 WriteElement(aStream, mOptions);
michael@0 554 RecordPatternData(aStream, mPattern);
michael@0 555 RecordStrokeOptions(aStream, mStrokeOptions);
michael@0 556 }
michael@0 557
michael@0 558 RecordedStrokeRect::RecordedStrokeRect(istream &aStream)
michael@0 559 : RecordedDrawingEvent(STROKERECT, aStream)
michael@0 560 {
michael@0 561 ReadElement(aStream, mRect);
michael@0 562 ReadElement(aStream, mOptions);
michael@0 563 ReadPatternData(aStream, mPattern);
michael@0 564 ReadStrokeOptions(aStream, mStrokeOptions);
michael@0 565 }
michael@0 566
michael@0 567 void
michael@0 568 RecordedStrokeRect::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 569 {
michael@0 570 aStringStream << "[" << mDT << "] StrokeRect (" << mRect.x << ", " << mRect.y << " - " << mRect.width << " x " << mRect.height
michael@0 571 << ") LineWidth: " << mStrokeOptions.mLineWidth << "px ";
michael@0 572 OutputSimplePatternInfo(mPattern, aStringStream);
michael@0 573 }
michael@0 574
michael@0 575 void
michael@0 576 RecordedStrokeLine::PlayEvent(Translator *aTranslator) const
michael@0 577 {
michael@0 578 aTranslator->LookupDrawTarget(mDT)->StrokeLine(mBegin, mEnd, *GenericPattern(mPattern, aTranslator), mStrokeOptions, mOptions);
michael@0 579 }
michael@0 580
michael@0 581 void
michael@0 582 RecordedStrokeLine::RecordToStream(ostream &aStream) const
michael@0 583 {
michael@0 584 RecordedDrawingEvent::RecordToStream(aStream);
michael@0 585 WriteElement(aStream, mBegin);
michael@0 586 WriteElement(aStream, mEnd);
michael@0 587 WriteElement(aStream, mOptions);
michael@0 588 RecordPatternData(aStream, mPattern);
michael@0 589 RecordStrokeOptions(aStream, mStrokeOptions);
michael@0 590 }
michael@0 591
michael@0 592 RecordedStrokeLine::RecordedStrokeLine(istream &aStream)
michael@0 593 : RecordedDrawingEvent(STROKELINE, aStream)
michael@0 594 {
michael@0 595 ReadElement(aStream, mBegin);
michael@0 596 ReadElement(aStream, mEnd);
michael@0 597 ReadElement(aStream, mOptions);
michael@0 598 ReadPatternData(aStream, mPattern);
michael@0 599 ReadStrokeOptions(aStream, mStrokeOptions);
michael@0 600 }
michael@0 601
michael@0 602 void
michael@0 603 RecordedStrokeLine::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 604 {
michael@0 605 aStringStream << "[" << mDT << "] StrokeLine (" << mBegin.x << ", " << mBegin.y << " - " << mEnd.x << ", " << mEnd.y
michael@0 606 << ") LineWidth: " << mStrokeOptions.mLineWidth << "px ";
michael@0 607 OutputSimplePatternInfo(mPattern, aStringStream);
michael@0 608 }
michael@0 609
michael@0 610 void
michael@0 611 RecordedFill::PlayEvent(Translator *aTranslator) const
michael@0 612 {
michael@0 613 aTranslator->LookupDrawTarget(mDT)->Fill(aTranslator->LookupPath(mPath), *GenericPattern(mPattern, aTranslator), mOptions);
michael@0 614 }
michael@0 615
michael@0 616 RecordedFill::RecordedFill(istream &aStream)
michael@0 617 : RecordedDrawingEvent(FILL, aStream)
michael@0 618 {
michael@0 619 ReadElement(aStream, mPath);
michael@0 620 ReadElement(aStream, mOptions);
michael@0 621 ReadPatternData(aStream, mPattern);
michael@0 622 }
michael@0 623
michael@0 624 void
michael@0 625 RecordedFill::RecordToStream(ostream &aStream) const
michael@0 626 {
michael@0 627 RecordedDrawingEvent::RecordToStream(aStream);
michael@0 628 WriteElement(aStream, mPath);
michael@0 629 WriteElement(aStream, mOptions);
michael@0 630 RecordPatternData(aStream, mPattern);
michael@0 631 }
michael@0 632
michael@0 633 void
michael@0 634 RecordedFill::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 635 {
michael@0 636 aStringStream << "[" << mDT << "] Fill (" << mPath << ") ";
michael@0 637 OutputSimplePatternInfo(mPattern, aStringStream);
michael@0 638 }
michael@0 639
michael@0 640 RecordedFillGlyphs::~RecordedFillGlyphs()
michael@0 641 {
michael@0 642 delete [] mGlyphs;
michael@0 643 }
michael@0 644
michael@0 645 void
michael@0 646 RecordedFillGlyphs::PlayEvent(Translator *aTranslator) const
michael@0 647 {
michael@0 648 GlyphBuffer buffer;
michael@0 649 buffer.mGlyphs = mGlyphs;
michael@0 650 buffer.mNumGlyphs = mNumGlyphs;
michael@0 651 aTranslator->LookupDrawTarget(mDT)->FillGlyphs(aTranslator->LookupScaledFont(mScaledFont), buffer, *GenericPattern(mPattern, aTranslator), mOptions);
michael@0 652 }
michael@0 653
michael@0 654 RecordedFillGlyphs::RecordedFillGlyphs(istream &aStream)
michael@0 655 : RecordedDrawingEvent(FILLGLYPHS, aStream)
michael@0 656 {
michael@0 657 ReadElement(aStream, mScaledFont);
michael@0 658 ReadElement(aStream, mOptions);
michael@0 659 ReadPatternData(aStream, mPattern);
michael@0 660 ReadElement(aStream, mNumGlyphs);
michael@0 661 mGlyphs = new Glyph[mNumGlyphs];
michael@0 662 aStream.read((char*)mGlyphs, sizeof(Glyph) * mNumGlyphs);
michael@0 663 }
michael@0 664
michael@0 665 void
michael@0 666 RecordedFillGlyphs::RecordToStream(ostream &aStream) const
michael@0 667 {
michael@0 668 RecordedDrawingEvent::RecordToStream(aStream);
michael@0 669 WriteElement(aStream, mScaledFont);
michael@0 670 WriteElement(aStream, mOptions);
michael@0 671 RecordPatternData(aStream, mPattern);
michael@0 672 WriteElement(aStream, mNumGlyphs);
michael@0 673 aStream.write((char*)mGlyphs, sizeof(Glyph) * mNumGlyphs);
michael@0 674 }
michael@0 675
michael@0 676 void
michael@0 677 RecordedFillGlyphs::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 678 {
michael@0 679 aStringStream << "[" << mDT << "] FillGlyphs (" << mScaledFont << ") ";
michael@0 680 OutputSimplePatternInfo(mPattern, aStringStream);
michael@0 681 }
michael@0 682
michael@0 683 void
michael@0 684 RecordedMask::PlayEvent(Translator *aTranslator) const
michael@0 685 {
michael@0 686 aTranslator->LookupDrawTarget(mDT)->Mask(*GenericPattern(mSource, aTranslator), *GenericPattern(mMask, aTranslator), mOptions);
michael@0 687 }
michael@0 688
michael@0 689 RecordedMask::RecordedMask(istream &aStream)
michael@0 690 : RecordedDrawingEvent(MASK, aStream)
michael@0 691 {
michael@0 692 ReadElement(aStream, mOptions);
michael@0 693 ReadPatternData(aStream, mSource);
michael@0 694 ReadPatternData(aStream, mMask);
michael@0 695 }
michael@0 696
michael@0 697 void
michael@0 698 RecordedMask::RecordToStream(ostream &aStream) const
michael@0 699 {
michael@0 700 RecordedDrawingEvent::RecordToStream(aStream);
michael@0 701 WriteElement(aStream, mOptions);
michael@0 702 RecordPatternData(aStream, mSource);
michael@0 703 RecordPatternData(aStream, mMask);
michael@0 704 }
michael@0 705
michael@0 706 void
michael@0 707 RecordedMask::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 708 {
michael@0 709 aStringStream << "[" << mDT << "] Mask (Source: ";
michael@0 710 OutputSimplePatternInfo(mSource, aStringStream);
michael@0 711 aStringStream << " Mask: ";
michael@0 712 OutputSimplePatternInfo(mMask, aStringStream);
michael@0 713 }
michael@0 714
michael@0 715 void
michael@0 716 RecordedStroke::PlayEvent(Translator *aTranslator) const
michael@0 717 {
michael@0 718 aTranslator->LookupDrawTarget(mDT)->Stroke(aTranslator->LookupPath(mPath), *GenericPattern(mPattern, aTranslator), mStrokeOptions, mOptions);
michael@0 719 }
michael@0 720
michael@0 721 void
michael@0 722 RecordedStroke::RecordToStream(ostream &aStream) const
michael@0 723 {
michael@0 724 RecordedDrawingEvent::RecordToStream(aStream);
michael@0 725 WriteElement(aStream, mPath);
michael@0 726 WriteElement(aStream, mOptions);
michael@0 727 RecordPatternData(aStream, mPattern);
michael@0 728 RecordStrokeOptions(aStream, mStrokeOptions);
michael@0 729 }
michael@0 730
michael@0 731 RecordedStroke::RecordedStroke(istream &aStream)
michael@0 732 : RecordedDrawingEvent(STROKE, aStream)
michael@0 733 {
michael@0 734 ReadElement(aStream, mPath);
michael@0 735 ReadElement(aStream, mOptions);
michael@0 736 ReadPatternData(aStream, mPattern);
michael@0 737 ReadStrokeOptions(aStream, mStrokeOptions);
michael@0 738 }
michael@0 739
michael@0 740 void
michael@0 741 RecordedStroke::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 742 {
michael@0 743 aStringStream << "[" << mDT << "] Stroke ("<< mPath << ") LineWidth: " << mStrokeOptions.mLineWidth << "px ";
michael@0 744 OutputSimplePatternInfo(mPattern, aStringStream);
michael@0 745 }
michael@0 746
michael@0 747 void
michael@0 748 RecordedClearRect::PlayEvent(Translator *aTranslator) const
michael@0 749 {
michael@0 750 aTranslator->LookupDrawTarget(mDT)->ClearRect(mRect);
michael@0 751 }
michael@0 752
michael@0 753 void
michael@0 754 RecordedClearRect::RecordToStream(ostream &aStream) const
michael@0 755 {
michael@0 756 RecordedDrawingEvent::RecordToStream(aStream);
michael@0 757 WriteElement(aStream, mRect);
michael@0 758 }
michael@0 759
michael@0 760 RecordedClearRect::RecordedClearRect(istream &aStream)
michael@0 761 : RecordedDrawingEvent(CLEARRECT, aStream)
michael@0 762 {
michael@0 763 ReadElement(aStream, mRect);
michael@0 764 }
michael@0 765
michael@0 766 void
michael@0 767 RecordedClearRect::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 768 {
michael@0 769 aStringStream << "[" << mDT<< "] ClearRect (" << mRect.x << ", " << mRect.y << " - " << mRect.width << " x " << mRect.height << ") ";
michael@0 770 }
michael@0 771
michael@0 772 void
michael@0 773 RecordedCopySurface::PlayEvent(Translator *aTranslator) const
michael@0 774 {
michael@0 775 aTranslator->LookupDrawTarget(mDT)->CopySurface(aTranslator->LookupSourceSurface(mSourceSurface),
michael@0 776 mSourceRect, mDest);
michael@0 777 }
michael@0 778
michael@0 779 void
michael@0 780 RecordedCopySurface::RecordToStream(ostream &aStream) const
michael@0 781 {
michael@0 782 RecordedDrawingEvent::RecordToStream(aStream);
michael@0 783 WriteElement(aStream, mSourceSurface);
michael@0 784 WriteElement(aStream, mSourceRect);
michael@0 785 WriteElement(aStream, mDest);
michael@0 786 }
michael@0 787
michael@0 788 RecordedCopySurface::RecordedCopySurface(istream &aStream)
michael@0 789 : RecordedDrawingEvent(COPYSURFACE, aStream)
michael@0 790 {
michael@0 791 ReadElement(aStream, mSourceSurface);
michael@0 792 ReadElement(aStream, mSourceRect);
michael@0 793 ReadElement(aStream, mDest);
michael@0 794 }
michael@0 795
michael@0 796 void
michael@0 797 RecordedCopySurface::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 798 {
michael@0 799 aStringStream << "[" << mDT<< "] CopySurface (" << mSourceSurface << ")";
michael@0 800 }
michael@0 801
michael@0 802 void
michael@0 803 RecordedPushClip::PlayEvent(Translator *aTranslator) const
michael@0 804 {
michael@0 805 aTranslator->LookupDrawTarget(mDT)->PushClip(aTranslator->LookupPath(mPath));
michael@0 806 }
michael@0 807
michael@0 808 void
michael@0 809 RecordedPushClip::RecordToStream(ostream &aStream) const
michael@0 810 {
michael@0 811 RecordedDrawingEvent::RecordToStream(aStream);
michael@0 812 WriteElement(aStream, mPath);
michael@0 813 }
michael@0 814
michael@0 815 RecordedPushClip::RecordedPushClip(istream &aStream)
michael@0 816 : RecordedDrawingEvent(PUSHCLIP, aStream)
michael@0 817 {
michael@0 818 ReadElement(aStream, mPath);
michael@0 819 }
michael@0 820
michael@0 821 void
michael@0 822 RecordedPushClip::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 823 {
michael@0 824 aStringStream << "[" << mDT << "] PushClip (" << mPath << ") ";
michael@0 825 }
michael@0 826
michael@0 827 void
michael@0 828 RecordedPushClipRect::PlayEvent(Translator *aTranslator) const
michael@0 829 {
michael@0 830 aTranslator->LookupDrawTarget(mDT)->PushClipRect(mRect);
michael@0 831 }
michael@0 832
michael@0 833 void
michael@0 834 RecordedPushClipRect::RecordToStream(ostream &aStream) const
michael@0 835 {
michael@0 836 RecordedDrawingEvent::RecordToStream(aStream);
michael@0 837 WriteElement(aStream, mRect);
michael@0 838 }
michael@0 839
michael@0 840 RecordedPushClipRect::RecordedPushClipRect(istream &aStream)
michael@0 841 : RecordedDrawingEvent(PUSHCLIPRECT, aStream)
michael@0 842 {
michael@0 843 ReadElement(aStream, mRect);
michael@0 844 }
michael@0 845
michael@0 846 void
michael@0 847 RecordedPushClipRect::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 848 {
michael@0 849 aStringStream << "[" << mDT << "] PushClipRect (" << mRect.x << ", " << mRect.y << " - " << mRect.width << " x " << mRect.height << ") ";
michael@0 850 }
michael@0 851
michael@0 852 void
michael@0 853 RecordedPopClip::PlayEvent(Translator *aTranslator) const
michael@0 854 {
michael@0 855 aTranslator->LookupDrawTarget(mDT)->PopClip();
michael@0 856 }
michael@0 857
michael@0 858 void
michael@0 859 RecordedPopClip::RecordToStream(ostream &aStream) const
michael@0 860 {
michael@0 861 RecordedDrawingEvent::RecordToStream(aStream);
michael@0 862 }
michael@0 863
michael@0 864 RecordedPopClip::RecordedPopClip(istream &aStream)
michael@0 865 : RecordedDrawingEvent(POPCLIP, aStream)
michael@0 866 {
michael@0 867 }
michael@0 868
michael@0 869 void
michael@0 870 RecordedPopClip::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 871 {
michael@0 872 aStringStream << "[" << mDT << "] PopClip";
michael@0 873 }
michael@0 874
michael@0 875 void
michael@0 876 RecordedSetTransform::PlayEvent(Translator *aTranslator) const
michael@0 877 {
michael@0 878 aTranslator->LookupDrawTarget(mDT)->SetTransform(mTransform);
michael@0 879 }
michael@0 880
michael@0 881 void
michael@0 882 RecordedSetTransform::RecordToStream(ostream &aStream) const
michael@0 883 {
michael@0 884 RecordedDrawingEvent::RecordToStream(aStream);
michael@0 885 WriteElement(aStream, mTransform);
michael@0 886 }
michael@0 887
michael@0 888 RecordedSetTransform::RecordedSetTransform(istream &aStream)
michael@0 889 : RecordedDrawingEvent(SETTRANSFORM, aStream)
michael@0 890 {
michael@0 891 ReadElement(aStream, mTransform);
michael@0 892 }
michael@0 893
michael@0 894 void
michael@0 895 RecordedSetTransform::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 896 {
michael@0 897 aStringStream << "[" << mDT << "] SetTransform [ " << mTransform._11 << " " << mTransform._12 << " ; " <<
michael@0 898 mTransform._21 << " " << mTransform._22 << " ; " << mTransform._31 << " " << mTransform._32 << " ]";
michael@0 899 }
michael@0 900
michael@0 901 void
michael@0 902 RecordedDrawSurface::PlayEvent(Translator *aTranslator) const
michael@0 903 {
michael@0 904 aTranslator->LookupDrawTarget(mDT)->
michael@0 905 DrawSurface(aTranslator->LookupSourceSurface(mRefSource), mDest, mSource,
michael@0 906 mDSOptions, mOptions);
michael@0 907 }
michael@0 908
michael@0 909 void
michael@0 910 RecordedDrawSurface::RecordToStream(ostream &aStream) const
michael@0 911 {
michael@0 912 RecordedDrawingEvent::RecordToStream(aStream);
michael@0 913 WriteElement(aStream, mRefSource);
michael@0 914 WriteElement(aStream, mDest);
michael@0 915 WriteElement(aStream, mSource);
michael@0 916 WriteElement(aStream, mDSOptions);
michael@0 917 WriteElement(aStream, mOptions);
michael@0 918 }
michael@0 919
michael@0 920 RecordedDrawSurface::RecordedDrawSurface(istream &aStream)
michael@0 921 : RecordedDrawingEvent(DRAWSURFACE, aStream)
michael@0 922 {
michael@0 923 ReadElement(aStream, mRefSource);
michael@0 924 ReadElement(aStream, mDest);
michael@0 925 ReadElement(aStream, mSource);
michael@0 926 ReadElement(aStream, mDSOptions);
michael@0 927 ReadElement(aStream, mOptions);
michael@0 928 }
michael@0 929
michael@0 930 void
michael@0 931 RecordedDrawSurface::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 932 {
michael@0 933 aStringStream << "[" << mDT << "] DrawSurface (" << mRefSource << ")";
michael@0 934 }
michael@0 935
michael@0 936 void
michael@0 937 RecordedDrawFilter::PlayEvent(Translator *aTranslator) const
michael@0 938 {
michael@0 939 aTranslator->LookupDrawTarget(mDT)->
michael@0 940 DrawFilter(aTranslator->LookupFilterNode(mNode), mSourceRect,
michael@0 941 mDestPoint, mOptions);
michael@0 942 }
michael@0 943
michael@0 944 void
michael@0 945 RecordedDrawFilter::RecordToStream(ostream &aStream) const
michael@0 946 {
michael@0 947 RecordedDrawingEvent::RecordToStream(aStream);
michael@0 948 WriteElement(aStream, mNode);
michael@0 949 WriteElement(aStream, mSourceRect);
michael@0 950 WriteElement(aStream, mDestPoint);
michael@0 951 WriteElement(aStream, mOptions);
michael@0 952 }
michael@0 953
michael@0 954 RecordedDrawFilter::RecordedDrawFilter(istream &aStream)
michael@0 955 : RecordedDrawingEvent(DRAWFILTER, aStream)
michael@0 956 {
michael@0 957 ReadElement(aStream, mNode);
michael@0 958 ReadElement(aStream, mSourceRect);
michael@0 959 ReadElement(aStream, mDestPoint);
michael@0 960 ReadElement(aStream, mOptions);
michael@0 961 }
michael@0 962
michael@0 963 void
michael@0 964 RecordedDrawFilter::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 965 {
michael@0 966 aStringStream << "[" << mDT << "] DrawFilter (" << mNode << ")";
michael@0 967 }
michael@0 968
michael@0 969 void
michael@0 970 RecordedDrawSurfaceWithShadow::PlayEvent(Translator *aTranslator) const
michael@0 971 {
michael@0 972 aTranslator->LookupDrawTarget(mDT)->
michael@0 973 DrawSurfaceWithShadow(aTranslator->LookupSourceSurface(mRefSource),
michael@0 974 mDest, mColor, mOffset, mSigma, mOp);
michael@0 975 }
michael@0 976
michael@0 977 void
michael@0 978 RecordedDrawSurfaceWithShadow::RecordToStream(ostream &aStream) const
michael@0 979 {
michael@0 980 RecordedDrawingEvent::RecordToStream(aStream);
michael@0 981 WriteElement(aStream, mRefSource);
michael@0 982 WriteElement(aStream, mDest);
michael@0 983 WriteElement(aStream, mColor);
michael@0 984 WriteElement(aStream, mOffset);
michael@0 985 WriteElement(aStream, mSigma);
michael@0 986 WriteElement(aStream, mOp);
michael@0 987 }
michael@0 988
michael@0 989 RecordedDrawSurfaceWithShadow::RecordedDrawSurfaceWithShadow(istream &aStream)
michael@0 990 : RecordedDrawingEvent(DRAWSURFACEWITHSHADOW, aStream)
michael@0 991 {
michael@0 992 ReadElement(aStream, mRefSource);
michael@0 993 ReadElement(aStream, mDest);
michael@0 994 ReadElement(aStream, mColor);
michael@0 995 ReadElement(aStream, mOffset);
michael@0 996 ReadElement(aStream, mSigma);
michael@0 997 ReadElement(aStream, mOp);
michael@0 998 }
michael@0 999
michael@0 1000 void
michael@0 1001 RecordedDrawSurfaceWithShadow::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 1002 {
michael@0 1003 aStringStream << "[" << mDT << "] DrawSurfaceWithShadow (" << mRefSource << ") Color: (" <<
michael@0 1004 mColor.r << ", " << mColor.g << ", " << mColor.b << ", " << mColor.a << ")";
michael@0 1005 }
michael@0 1006
michael@0 1007 RecordedPathCreation::RecordedPathCreation(PathRecording *aPath)
michael@0 1008 : RecordedEvent(PATHCREATION), mRefPtr(aPath), mFillRule(aPath->mFillRule), mPathOps(aPath->mPathOps)
michael@0 1009 {
michael@0 1010 }
michael@0 1011
michael@0 1012 RecordedPathCreation::~RecordedPathCreation()
michael@0 1013 {
michael@0 1014 }
michael@0 1015
michael@0 1016 void
michael@0 1017 RecordedPathCreation::PlayEvent(Translator *aTranslator) const
michael@0 1018 {
michael@0 1019 RefPtr<PathBuilder> builder =
michael@0 1020 aTranslator->GetReferenceDrawTarget()->CreatePathBuilder(mFillRule);
michael@0 1021
michael@0 1022 for (size_t i = 0; i < mPathOps.size(); i++) {
michael@0 1023 const PathOp &op = mPathOps[i];
michael@0 1024 switch (op.mType) {
michael@0 1025 case PathOp::OP_MOVETO:
michael@0 1026 builder->MoveTo(op.mP1);
michael@0 1027 break;
michael@0 1028 case PathOp::OP_LINETO:
michael@0 1029 builder->LineTo(op.mP1);
michael@0 1030 break;
michael@0 1031 case PathOp::OP_BEZIERTO:
michael@0 1032 builder->BezierTo(op.mP1, op.mP2, op.mP3);
michael@0 1033 break;
michael@0 1034 case PathOp::OP_QUADRATICBEZIERTO:
michael@0 1035 builder->QuadraticBezierTo(op.mP1, op.mP2);
michael@0 1036 break;
michael@0 1037 case PathOp::OP_CLOSE:
michael@0 1038 builder->Close();
michael@0 1039 break;
michael@0 1040 }
michael@0 1041 }
michael@0 1042
michael@0 1043 RefPtr<Path> path = builder->Finish();
michael@0 1044 aTranslator->AddPath(mRefPtr, path);
michael@0 1045 }
michael@0 1046
michael@0 1047 void
michael@0 1048 RecordedPathCreation::RecordToStream(ostream &aStream) const
michael@0 1049 {
michael@0 1050 WriteElement(aStream, mRefPtr);
michael@0 1051 WriteElement(aStream, uint64_t(mPathOps.size()));
michael@0 1052 WriteElement(aStream, mFillRule);
michael@0 1053 typedef std::vector<PathOp> pathOpVec;
michael@0 1054 for (pathOpVec::const_iterator iter = mPathOps.begin(); iter != mPathOps.end(); iter++) {
michael@0 1055 WriteElement(aStream, iter->mType);
michael@0 1056 if (sPointCount[iter->mType] >= 1) {
michael@0 1057 WriteElement(aStream, iter->mP1);
michael@0 1058 }
michael@0 1059 if (sPointCount[iter->mType] >= 2) {
michael@0 1060 WriteElement(aStream, iter->mP2);
michael@0 1061 }
michael@0 1062 if (sPointCount[iter->mType] >= 3) {
michael@0 1063 WriteElement(aStream, iter->mP3);
michael@0 1064 }
michael@0 1065 }
michael@0 1066
michael@0 1067 }
michael@0 1068
michael@0 1069 RecordedPathCreation::RecordedPathCreation(istream &aStream)
michael@0 1070 : RecordedEvent(PATHCREATION)
michael@0 1071 {
michael@0 1072 uint64_t size;
michael@0 1073
michael@0 1074 ReadElement(aStream, mRefPtr);
michael@0 1075 ReadElement(aStream, size);
michael@0 1076 ReadElement(aStream, mFillRule);
michael@0 1077
michael@0 1078 for (uint64_t i = 0; i < size; i++) {
michael@0 1079 PathOp newPathOp;
michael@0 1080 ReadElement(aStream, newPathOp.mType);
michael@0 1081 if (sPointCount[newPathOp.mType] >= 1) {
michael@0 1082 ReadElement(aStream, newPathOp.mP1);
michael@0 1083 }
michael@0 1084 if (sPointCount[newPathOp.mType] >= 2) {
michael@0 1085 ReadElement(aStream, newPathOp.mP2);
michael@0 1086 }
michael@0 1087 if (sPointCount[newPathOp.mType] >= 3) {
michael@0 1088 ReadElement(aStream, newPathOp.mP3);
michael@0 1089 }
michael@0 1090
michael@0 1091 mPathOps.push_back(newPathOp);
michael@0 1092 }
michael@0 1093
michael@0 1094 }
michael@0 1095
michael@0 1096 void
michael@0 1097 RecordedPathCreation::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 1098 {
michael@0 1099 aStringStream << "[" << mRefPtr << "] Path created (OpCount: " << mPathOps.size() << ")";
michael@0 1100 }
michael@0 1101 void
michael@0 1102 RecordedPathDestruction::PlayEvent(Translator *aTranslator) const
michael@0 1103 {
michael@0 1104 aTranslator->RemovePath(mRefPtr);
michael@0 1105 }
michael@0 1106
michael@0 1107 void
michael@0 1108 RecordedPathDestruction::RecordToStream(ostream &aStream) const
michael@0 1109 {
michael@0 1110 WriteElement(aStream, mRefPtr);
michael@0 1111 }
michael@0 1112
michael@0 1113 RecordedPathDestruction::RecordedPathDestruction(istream &aStream)
michael@0 1114 : RecordedEvent(PATHDESTRUCTION)
michael@0 1115 {
michael@0 1116 ReadElement(aStream, mRefPtr);
michael@0 1117 }
michael@0 1118
michael@0 1119 void
michael@0 1120 RecordedPathDestruction::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 1121 {
michael@0 1122 aStringStream << "[" << mRefPtr << "] Path Destroyed";
michael@0 1123 }
michael@0 1124
michael@0 1125 RecordedSourceSurfaceCreation::~RecordedSourceSurfaceCreation()
michael@0 1126 {
michael@0 1127 if (mDataOwned) {
michael@0 1128 delete [] mData;
michael@0 1129 }
michael@0 1130 }
michael@0 1131
michael@0 1132 void
michael@0 1133 RecordedSourceSurfaceCreation::PlayEvent(Translator *aTranslator) const
michael@0 1134 {
michael@0 1135 RefPtr<SourceSurface> src = aTranslator->GetReferenceDrawTarget()->
michael@0 1136 CreateSourceSurfaceFromData(mData, mSize, mSize.width * BytesPerPixel(mFormat), mFormat);
michael@0 1137 aTranslator->AddSourceSurface(mRefPtr, src);
michael@0 1138 }
michael@0 1139
michael@0 1140 void
michael@0 1141 RecordedSourceSurfaceCreation::RecordToStream(ostream &aStream) const
michael@0 1142 {
michael@0 1143 WriteElement(aStream, mRefPtr);
michael@0 1144 WriteElement(aStream, mSize);
michael@0 1145 WriteElement(aStream, mFormat);
michael@0 1146 for (int y = 0; y < mSize.height; y++) {
michael@0 1147 aStream.write((const char*)mData + y * mStride, BytesPerPixel(mFormat) * mSize.width);
michael@0 1148 }
michael@0 1149 }
michael@0 1150
michael@0 1151 RecordedSourceSurfaceCreation::RecordedSourceSurfaceCreation(istream &aStream)
michael@0 1152 : RecordedEvent(SOURCESURFACECREATION), mDataOwned(true)
michael@0 1153 {
michael@0 1154 ReadElement(aStream, mRefPtr);
michael@0 1155 ReadElement(aStream, mSize);
michael@0 1156 ReadElement(aStream, mFormat);
michael@0 1157 mData = (uint8_t*)new char[mSize.width * mSize.height * BytesPerPixel(mFormat)];
michael@0 1158 aStream.read((char*)mData, mSize.width * mSize.height * BytesPerPixel(mFormat));
michael@0 1159 }
michael@0 1160
michael@0 1161 void
michael@0 1162 RecordedSourceSurfaceCreation::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 1163 {
michael@0 1164 aStringStream << "[" << mRefPtr << "] SourceSurface created (Size: " << mSize.width << "x" << mSize.height << ")";
michael@0 1165 }
michael@0 1166
michael@0 1167 void
michael@0 1168 RecordedSourceSurfaceDestruction::PlayEvent(Translator *aTranslator) const
michael@0 1169 {
michael@0 1170 aTranslator->RemoveSourceSurface(mRefPtr);
michael@0 1171 }
michael@0 1172
michael@0 1173 void
michael@0 1174 RecordedSourceSurfaceDestruction::RecordToStream(ostream &aStream) const
michael@0 1175 {
michael@0 1176 WriteElement(aStream, mRefPtr);
michael@0 1177 }
michael@0 1178
michael@0 1179 RecordedSourceSurfaceDestruction::RecordedSourceSurfaceDestruction(istream &aStream)
michael@0 1180 : RecordedEvent(SOURCESURFACEDESTRUCTION)
michael@0 1181 {
michael@0 1182 ReadElement(aStream, mRefPtr);
michael@0 1183 }
michael@0 1184
michael@0 1185 void
michael@0 1186 RecordedSourceSurfaceDestruction::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 1187 {
michael@0 1188 aStringStream << "[" << mRefPtr << "] SourceSurface Destroyed";
michael@0 1189 }
michael@0 1190
michael@0 1191 RecordedFilterNodeCreation::~RecordedFilterNodeCreation()
michael@0 1192 {
michael@0 1193 }
michael@0 1194
michael@0 1195 void
michael@0 1196 RecordedFilterNodeCreation::PlayEvent(Translator *aTranslator) const
michael@0 1197 {
michael@0 1198 RefPtr<FilterNode> node = aTranslator->GetReferenceDrawTarget()->
michael@0 1199 CreateFilter(mType);
michael@0 1200 aTranslator->AddFilterNode(mRefPtr, node);
michael@0 1201 }
michael@0 1202
michael@0 1203 void
michael@0 1204 RecordedFilterNodeCreation::RecordToStream(ostream &aStream) const
michael@0 1205 {
michael@0 1206 WriteElement(aStream, mRefPtr);
michael@0 1207 WriteElement(aStream, mType);
michael@0 1208 }
michael@0 1209
michael@0 1210 RecordedFilterNodeCreation::RecordedFilterNodeCreation(istream &aStream)
michael@0 1211 : RecordedEvent(FILTERNODECREATION)
michael@0 1212 {
michael@0 1213 ReadElement(aStream, mRefPtr);
michael@0 1214 ReadElement(aStream, mType);
michael@0 1215 }
michael@0 1216
michael@0 1217 void
michael@0 1218 RecordedFilterNodeCreation::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 1219 {
michael@0 1220 aStringStream << "[" << mRefPtr << "] FilterNode created (Type: " << int(mType) << ")";
michael@0 1221 }
michael@0 1222
michael@0 1223 void
michael@0 1224 RecordedFilterNodeDestruction::PlayEvent(Translator *aTranslator) const
michael@0 1225 {
michael@0 1226 aTranslator->RemoveFilterNode(mRefPtr);
michael@0 1227 }
michael@0 1228
michael@0 1229 void
michael@0 1230 RecordedFilterNodeDestruction::RecordToStream(ostream &aStream) const
michael@0 1231 {
michael@0 1232 WriteElement(aStream, mRefPtr);
michael@0 1233 }
michael@0 1234
michael@0 1235 RecordedFilterNodeDestruction::RecordedFilterNodeDestruction(istream &aStream)
michael@0 1236 : RecordedEvent(FILTERNODEDESTRUCTION)
michael@0 1237 {
michael@0 1238 ReadElement(aStream, mRefPtr);
michael@0 1239 }
michael@0 1240
michael@0 1241 void
michael@0 1242 RecordedFilterNodeDestruction::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 1243 {
michael@0 1244 aStringStream << "[" << mRefPtr << "] FilterNode Destroyed";
michael@0 1245 }
michael@0 1246
michael@0 1247 RecordedGradientStopsCreation::~RecordedGradientStopsCreation()
michael@0 1248 {
michael@0 1249 if (mDataOwned) {
michael@0 1250 delete [] mStops;
michael@0 1251 }
michael@0 1252 }
michael@0 1253
michael@0 1254 void
michael@0 1255 RecordedGradientStopsCreation::PlayEvent(Translator *aTranslator) const
michael@0 1256 {
michael@0 1257 RefPtr<GradientStops> src = aTranslator->GetReferenceDrawTarget()->
michael@0 1258 CreateGradientStops(mStops, mNumStops, mExtendMode);
michael@0 1259 aTranslator->AddGradientStops(mRefPtr, src);
michael@0 1260 }
michael@0 1261
michael@0 1262 void
michael@0 1263 RecordedGradientStopsCreation::RecordToStream(ostream &aStream) const
michael@0 1264 {
michael@0 1265 WriteElement(aStream, mRefPtr);
michael@0 1266 WriteElement(aStream, mExtendMode);
michael@0 1267 WriteElement(aStream, mNumStops);
michael@0 1268 aStream.write((const char*)mStops, mNumStops * sizeof(GradientStop));
michael@0 1269 }
michael@0 1270
michael@0 1271 RecordedGradientStopsCreation::RecordedGradientStopsCreation(istream &aStream)
michael@0 1272 : RecordedEvent(GRADIENTSTOPSCREATION), mDataOwned(true)
michael@0 1273 {
michael@0 1274 ReadElement(aStream, mRefPtr);
michael@0 1275 ReadElement(aStream, mExtendMode);
michael@0 1276 ReadElement(aStream, mNumStops);
michael@0 1277 mStops = new GradientStop[mNumStops];
michael@0 1278
michael@0 1279 aStream.read((char*)mStops, mNumStops * sizeof(GradientStop));
michael@0 1280 }
michael@0 1281
michael@0 1282 void
michael@0 1283 RecordedGradientStopsCreation::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 1284 {
michael@0 1285 aStringStream << "[" << mRefPtr << "] GradientStops created (Stops: " << mNumStops << ")";
michael@0 1286 }
michael@0 1287
michael@0 1288 void
michael@0 1289 RecordedGradientStopsDestruction::PlayEvent(Translator *aTranslator) const
michael@0 1290 {
michael@0 1291 aTranslator->RemoveGradientStops(mRefPtr);
michael@0 1292 }
michael@0 1293
michael@0 1294 void
michael@0 1295 RecordedGradientStopsDestruction::RecordToStream(ostream &aStream) const
michael@0 1296 {
michael@0 1297 WriteElement(aStream, mRefPtr);
michael@0 1298 }
michael@0 1299
michael@0 1300 RecordedGradientStopsDestruction::RecordedGradientStopsDestruction(istream &aStream)
michael@0 1301 : RecordedEvent(GRADIENTSTOPSDESTRUCTION)
michael@0 1302 {
michael@0 1303 ReadElement(aStream, mRefPtr);
michael@0 1304 }
michael@0 1305
michael@0 1306 void
michael@0 1307 RecordedGradientStopsDestruction::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 1308 {
michael@0 1309 aStringStream << "[" << mRefPtr << "] GradientStops Destroyed";
michael@0 1310 }
michael@0 1311
michael@0 1312 void
michael@0 1313 RecordedSnapshot::PlayEvent(Translator *aTranslator) const
michael@0 1314 {
michael@0 1315 RefPtr<SourceSurface> src = aTranslator->LookupDrawTarget(mDT)->Snapshot();
michael@0 1316 aTranslator->AddSourceSurface(mRefPtr, src);
michael@0 1317 }
michael@0 1318
michael@0 1319 void
michael@0 1320 RecordedSnapshot::RecordToStream(ostream &aStream) const
michael@0 1321 {
michael@0 1322 WriteElement(aStream, mRefPtr);
michael@0 1323 WriteElement(aStream, mDT);
michael@0 1324 }
michael@0 1325
michael@0 1326 RecordedSnapshot::RecordedSnapshot(istream &aStream)
michael@0 1327 : RecordedEvent(SNAPSHOT)
michael@0 1328 {
michael@0 1329 ReadElement(aStream, mRefPtr);
michael@0 1330 ReadElement(aStream, mDT);
michael@0 1331 }
michael@0 1332
michael@0 1333 void
michael@0 1334 RecordedSnapshot::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 1335 {
michael@0 1336 aStringStream << "[" << mRefPtr << "] Snapshot Created (DT: " << mDT << ")";
michael@0 1337 }
michael@0 1338
michael@0 1339 RecordedScaledFontCreation::~RecordedScaledFontCreation()
michael@0 1340 {
michael@0 1341 delete [] mData;
michael@0 1342 }
michael@0 1343
michael@0 1344 void
michael@0 1345 RecordedScaledFontCreation::PlayEvent(Translator *aTranslator) const
michael@0 1346 {
michael@0 1347 RefPtr<ScaledFont> scaledFont =
michael@0 1348 Factory::CreateScaledFontForTrueTypeData(mData, mSize, mIndex, mGlyphSize,
michael@0 1349 aTranslator->GetDesiredFontType());
michael@0 1350 aTranslator->AddScaledFont(mRefPtr, scaledFont);
michael@0 1351 }
michael@0 1352
michael@0 1353 void
michael@0 1354 RecordedScaledFontCreation::RecordToStream(std::ostream &aStream) const
michael@0 1355 {
michael@0 1356 WriteElement(aStream, mRefPtr);
michael@0 1357 WriteElement(aStream, mIndex);
michael@0 1358 WriteElement(aStream, mGlyphSize);
michael@0 1359 WriteElement(aStream, mSize);
michael@0 1360 aStream.write((const char*)mData, mSize);
michael@0 1361 }
michael@0 1362
michael@0 1363 void
michael@0 1364 RecordedScaledFontCreation::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 1365 {
michael@0 1366 aStringStream << "[" << mRefPtr << "] ScaledFont Created";
michael@0 1367 }
michael@0 1368
michael@0 1369 void
michael@0 1370 RecordedScaledFontCreation::SetFontData(const uint8_t *aData, uint32_t aSize, uint32_t aIndex, Float aGlyphSize)
michael@0 1371 {
michael@0 1372 mData = new uint8_t[aSize];
michael@0 1373 memcpy(mData, aData, aSize);
michael@0 1374 mSize = aSize;
michael@0 1375 mIndex = aIndex;
michael@0 1376 mGlyphSize = aGlyphSize;
michael@0 1377 }
michael@0 1378
michael@0 1379 RecordedScaledFontCreation::RecordedScaledFontCreation(istream &aStream)
michael@0 1380 : RecordedEvent(SCALEDFONTCREATION)
michael@0 1381 {
michael@0 1382 ReadElement(aStream, mRefPtr);
michael@0 1383 ReadElement(aStream, mIndex);
michael@0 1384 ReadElement(aStream, mGlyphSize);
michael@0 1385 ReadElement(aStream, mSize);
michael@0 1386 mData = new uint8_t[mSize];
michael@0 1387 aStream.read((char*)mData, mSize);
michael@0 1388 }
michael@0 1389
michael@0 1390 void
michael@0 1391 RecordedScaledFontDestruction::PlayEvent(Translator *aTranslator) const
michael@0 1392 {
michael@0 1393 aTranslator->RemoveScaledFont(mRefPtr);
michael@0 1394 }
michael@0 1395
michael@0 1396 void
michael@0 1397 RecordedScaledFontDestruction::RecordToStream(ostream &aStream) const
michael@0 1398 {
michael@0 1399 WriteElement(aStream, mRefPtr);
michael@0 1400 }
michael@0 1401
michael@0 1402 RecordedScaledFontDestruction::RecordedScaledFontDestruction(istream &aStream)
michael@0 1403 : RecordedEvent(SCALEDFONTDESTRUCTION)
michael@0 1404 {
michael@0 1405 ReadElement(aStream, mRefPtr);
michael@0 1406 }
michael@0 1407
michael@0 1408 void
michael@0 1409 RecordedScaledFontDestruction::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 1410 {
michael@0 1411 aStringStream << "[" << mRefPtr << "] ScaledFont Destroyed";
michael@0 1412 }
michael@0 1413
michael@0 1414 void
michael@0 1415 RecordedMaskSurface::PlayEvent(Translator *aTranslator) const
michael@0 1416 {
michael@0 1417 aTranslator->LookupDrawTarget(mDT)->
michael@0 1418 MaskSurface(*GenericPattern(mPattern, aTranslator),
michael@0 1419 aTranslator->LookupSourceSurface(mRefMask),
michael@0 1420 mOffset, mOptions);
michael@0 1421 }
michael@0 1422
michael@0 1423 void
michael@0 1424 RecordedMaskSurface::RecordToStream(ostream &aStream) const
michael@0 1425 {
michael@0 1426 RecordedDrawingEvent::RecordToStream(aStream);
michael@0 1427 RecordPatternData(aStream, mPattern);
michael@0 1428 WriteElement(aStream, mRefMask);
michael@0 1429 WriteElement(aStream, mOffset);
michael@0 1430 WriteElement(aStream, mOptions);
michael@0 1431 }
michael@0 1432
michael@0 1433 RecordedMaskSurface::RecordedMaskSurface(istream &aStream)
michael@0 1434 : RecordedDrawingEvent(MASKSURFACE, aStream)
michael@0 1435 {
michael@0 1436 ReadPatternData(aStream, mPattern);
michael@0 1437 ReadElement(aStream, mRefMask);
michael@0 1438 ReadElement(aStream, mOffset);
michael@0 1439 ReadElement(aStream, mOptions);
michael@0 1440 }
michael@0 1441
michael@0 1442 void
michael@0 1443 RecordedMaskSurface::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 1444 {
michael@0 1445 aStringStream << "[" << mDT << "] MaskSurface (" << mRefMask << ") Offset: (" << mOffset.x << "x" << mOffset.y << ") Pattern: ";
michael@0 1446 OutputSimplePatternInfo(mPattern, aStringStream);
michael@0 1447 }
michael@0 1448
michael@0 1449 template<typename T>
michael@0 1450 void
michael@0 1451 ReplaySetAttribute(FilterNode *aNode, uint32_t aIndex, T aValue)
michael@0 1452 {
michael@0 1453 aNode->SetAttribute(aIndex, aValue);
michael@0 1454 }
michael@0 1455
michael@0 1456 void
michael@0 1457 RecordedFilterNodeSetAttribute::PlayEvent(Translator *aTranslator) const
michael@0 1458 {
michael@0 1459 #define REPLAY_SET_ATTRIBUTE(type, argtype) \
michael@0 1460 case ARGTYPE_##argtype: \
michael@0 1461 ReplaySetAttribute(aTranslator->LookupFilterNode(mNode), mIndex, *(type*)&mPayload.front()); \
michael@0 1462 break
michael@0 1463
michael@0 1464 switch (mArgType) {
michael@0 1465 REPLAY_SET_ATTRIBUTE(bool, BOOL);
michael@0 1466 REPLAY_SET_ATTRIBUTE(uint32_t, UINT32);
michael@0 1467 REPLAY_SET_ATTRIBUTE(Float, FLOAT);
michael@0 1468 REPLAY_SET_ATTRIBUTE(Size, SIZE);
michael@0 1469 REPLAY_SET_ATTRIBUTE(IntSize, INTSIZE);
michael@0 1470 REPLAY_SET_ATTRIBUTE(IntPoint, INTPOINT);
michael@0 1471 REPLAY_SET_ATTRIBUTE(Rect, RECT);
michael@0 1472 REPLAY_SET_ATTRIBUTE(IntRect, INTRECT);
michael@0 1473 REPLAY_SET_ATTRIBUTE(Point, POINT);
michael@0 1474 REPLAY_SET_ATTRIBUTE(Matrix5x4, MATRIX5X4);
michael@0 1475 REPLAY_SET_ATTRIBUTE(Point3D, POINT3D);
michael@0 1476 REPLAY_SET_ATTRIBUTE(Color, COLOR);
michael@0 1477 case ARGTYPE_FLOAT_ARRAY:
michael@0 1478 aTranslator->LookupFilterNode(mNode)->SetAttribute(
michael@0 1479 mIndex,
michael@0 1480 reinterpret_cast<const Float*>(&mPayload.front()),
michael@0 1481 mPayload.size() / sizeof(Float));
michael@0 1482 break;
michael@0 1483 }
michael@0 1484 }
michael@0 1485
michael@0 1486 void
michael@0 1487 RecordedFilterNodeSetAttribute::RecordToStream(ostream &aStream) const
michael@0 1488 {
michael@0 1489 RecordedEvent::RecordToStream(aStream);
michael@0 1490 WriteElement(aStream, mNode);
michael@0 1491 WriteElement(aStream, mIndex);
michael@0 1492 WriteElement(aStream, mArgType);
michael@0 1493 WriteElement(aStream, uint64_t(mPayload.size()));
michael@0 1494 aStream.write((const char*)&mPayload.front(), mPayload.size());
michael@0 1495 }
michael@0 1496
michael@0 1497 RecordedFilterNodeSetAttribute::RecordedFilterNodeSetAttribute(istream &aStream)
michael@0 1498 : RecordedEvent(FILTERNODESETATTRIBUTE)
michael@0 1499 {
michael@0 1500 ReadElement(aStream, mNode);
michael@0 1501 ReadElement(aStream, mIndex);
michael@0 1502 ReadElement(aStream, mArgType);
michael@0 1503 uint64_t size;
michael@0 1504 ReadElement(aStream, size);
michael@0 1505 mPayload.resize(size_t(size));
michael@0 1506 aStream.read((char*)&mPayload.front(), size);
michael@0 1507 }
michael@0 1508
michael@0 1509 void
michael@0 1510 RecordedFilterNodeSetAttribute::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 1511 {
michael@0 1512 aStringStream << "[" << mNode << "] SetAttribute (" << mIndex << ")";
michael@0 1513 }
michael@0 1514
michael@0 1515 void
michael@0 1516 RecordedFilterNodeSetInput::PlayEvent(Translator *aTranslator) const
michael@0 1517 {
michael@0 1518 if (mInputFilter) {
michael@0 1519 aTranslator->LookupFilterNode(mNode)->SetInput(
michael@0 1520 mIndex, aTranslator->LookupFilterNode(mInputFilter));
michael@0 1521 } else {
michael@0 1522 aTranslator->LookupFilterNode(mNode)->SetInput(
michael@0 1523 mIndex, aTranslator->LookupSourceSurface(mInputSurface));
michael@0 1524 }
michael@0 1525 }
michael@0 1526
michael@0 1527 void
michael@0 1528 RecordedFilterNodeSetInput::RecordToStream(ostream &aStream) const
michael@0 1529 {
michael@0 1530 RecordedEvent::RecordToStream(aStream);
michael@0 1531 WriteElement(aStream, mNode);
michael@0 1532 WriteElement(aStream, mIndex);
michael@0 1533 WriteElement(aStream, mInputFilter);
michael@0 1534 WriteElement(aStream, mInputSurface);
michael@0 1535 }
michael@0 1536
michael@0 1537 RecordedFilterNodeSetInput::RecordedFilterNodeSetInput(istream &aStream)
michael@0 1538 : RecordedEvent(FILTERNODESETINPUT)
michael@0 1539 {
michael@0 1540 ReadElement(aStream, mNode);
michael@0 1541 ReadElement(aStream, mIndex);
michael@0 1542 ReadElement(aStream, mInputFilter);
michael@0 1543 ReadElement(aStream, mInputSurface);
michael@0 1544 }
michael@0 1545
michael@0 1546 void
michael@0 1547 RecordedFilterNodeSetInput::OutputSimpleEventInfo(stringstream &aStringStream) const
michael@0 1548 {
michael@0 1549 aStringStream << "[" << mNode << "] SetAttribute (" << mIndex << ", ";
michael@0 1550
michael@0 1551 if (mInputFilter) {
michael@0 1552 aStringStream << "Filter: " << mInputFilter;
michael@0 1553 } else {
michael@0 1554 aStringStream << "Surface: " << mInputSurface;
michael@0 1555 }
michael@0 1556
michael@0 1557 aStringStream << ")";
michael@0 1558 }
michael@0 1559
michael@0 1560 }
michael@0 1561 }

mercurial