deserialize
DE01:
353 LayerAndroid* deserializeLayer(int version, SkStream* stream) 354 { 355 int type = stream->readU8(); 356 if (type == LTNone) 357 return 0; 358 // Cast is to disambiguate between ctors. 359 LayerAndroid *layer; 360 if (type == LTLayerAndroid) 361 layer = new LayerAndroid((RenderLayer*) 0); 362 else if (type == LTScrollableLayerAndroid) 363 layer = new ScrollableLayerAndroid((RenderLayer*) 0); 364 else { 365 ALOGV("Unexpected layer type: %d, aborting!", type); 366 return 0; 367 } 368 369 // Layer fields 370 layer->setShouldInheritFromRootTransform(stream->readBool()); 371 layer->setOpacity(stream->readScalar()); 372 layer->setSize(stream->readScalar(), stream->readScalar()); 373 layer->setPosition(stream->readScalar(), stream->readScalar()); 374 layer->setAnchorPoint(stream->readScalar(), stream->readScalar()); 375 layer->setMatrix(readMatrix(stream)); 376 layer->setChildrenMatrix(readMatrix(stream)); 377 378 // LayerAndroid fields 379 layer->m_haveClip = stream->readBool(); 380 381 // Keep the legacy serialization/deserialization format... 382 bool isFixed = stream->readBool(); 383 384 layer->m_backgroundColorSet = stream->readBool(); 385 386 bool isIframe = stream->readBool(); 387 // If we are a scrollable layer android, we are an iframe content 388 if (isIframe && type == LTScrollableLayerAndroid) { 389 IFrameContentLayerAndroid* iframeContent = new IFrameContentLayerAndroid(*layer); 390 layer->unref(); 391 layer = iframeContent; 392 } else if (isIframe) { // otherwise we are just the iframe (we use it to compute offset) 393 IFrameLayerAndroid* iframe = new IFrameLayerAndroid(*layer); 394 layer->unref(); 395 layer = iframe; 396 } 397 398 if (isFixed) { 399 FixedPositioning* fixedPosition = new FixedPositioning(layer); 400 401 fixedPosition->m_fixedLeft = readSkLength(stream); 402 fixedPosition->m_fixedTop = readSkLength(stream); 403 fixedPosition->m_fixedRight = readSkLength(stream); 404 fixedPosition->m_fixedBottom = readSkLength(stream); 405 fixedPosition->m_fixedMarginLeft = readSkLength(stream); 406 fixedPosition->m_fixedMarginTop = readSkLength(stream); 407 fixedPosition->m_fixedMarginRight = readSkLength(stream); 408 fixedPosition->m_fixedMarginBottom = readSkLength(stream); 409 fixedPosition->m_fixedRect = readSkRect(stream); 410 fixedPosition->m_renderLayerPos.setX(stream->readS32()); 411 fixedPosition->m_renderLayerPos.setY(stream->readS32()); 412 413 layer->setFixedPosition(fixedPosition); 414 } else { 415 // Not a fixed element, bypass the values in the stream 416 readSkLength(stream); // fixedLeft 417 readSkLength(stream); // fixedTop 418 readSkLength(stream); // fixedRight 419 readSkLength(stream); // fixedBottom 420 readSkLength(stream); // fixedMarginLeft 421 readSkLength(stream); // fixedMarginTop 422 readSkLength(stream); // fixedMarginRight 423 readSkLength(stream); // fixedMarginBottom 424 readSkRect(stream); // fixedRect 425 stream->readS32(); // renderLayerPos.x() 426 stream->readS32(); // renderLayerPos.y() 427 } 428 429 layer->m_backfaceVisibility = stream->readBool(); 430 layer->m_visible = stream->readBool(); 431 layer->m_backgroundColor = stream->readU32(); 432 layer->m_preserves3D = stream->readBool(); 433 layer->m_anchorPointZ = stream->readScalar(); 434 layer->m_drawOpacity = stream->readScalar(); 435 bool hasContentsImage = stream->readBool(); 436 if (hasContentsImage) { 437 int size = stream->readU32(); 438 SkAutoMalloc storage(size); 439 stream->read(storage.get(), size); 440 SkFlattenableReadBuffer buffer(storage.get(), size); 441 SkBitmap contentsImage; 442 contentsImage.unflatten(buffer); 443 SkBitmapRef* imageRef = new SkBitmapRef(contentsImage); 444 layer->setContentsImage(imageRef); 445 delete imageRef; 446 } 447 bool hasRecordingPicture = stream->readBool(); 448 if (hasRecordingPicture) { 449 SkPicture* picture = new SkPicture(stream); => DE02へ 450 PictureLayerContent* content = new PictureLayerContent(picture); => DE03,DE04へ 451 layer->setContent(content); => DE06へ 452 SkSafeUnref(content); 453 SkSafeUnref(picture); 454 } 455 int animationCount = stream->readU32(); // TODO: Support (maybe?) 456 readTransformationMatrix(stream, layer->m_transform); 457 readTransformationMatrix(stream, layer->m_childrenTransform); 458 if (type == LTScrollableLayerAndroid) { 459 ScrollableLayerAndroid* scrollableLayer = 460 static_cast<ScrollableLayerAndroid*>(layer); 461 scrollableLayer->m_scrollLimits.set( 462 stream->readScalar(), 463 stream->readScalar(), 464 stream->readScalar(), 465 stream->readScalar()); 466 } 467 int childCount = stream->readU32(); 468 for (int i = 0; i < childCount; i++) { 469 LayerAndroid *childLayer = deserializeLayer(version, stream); 470 if (childLayer) 471 layer->addChild(childLayer); 472 } 473 ALOGV("Created layer with id %d", layer->uniqueId()); 474 return layer; 475 }
DE02:
194 SkPicture::SkPicture(SkStream* stream) : SkRefCnt() { 195 const uint32_t pictureVersion = stream->readU32(); 196 if (pictureVersion != PICTURE_VERSION_ICS && 197 pictureVersion != PICTURE_VERSION_JB) { 198 sk_throw(); 199 } 200 201 fWidth = stream->readU32(); 202 fHeight = stream->readU32(); 203 204 fRecord = NULL; 205 fPlayback = NULL; 206 207 if (stream->readBool()) { 208 fPlayback = SkNEW_ARGS(SkPicturePlayback, (stream, pictureVersion)); 209 } 210 }
DE03:
9 PictureLayerContent::PictureLayerContent(SkPicture* picture) 10 : m_picture(picture) 11 , m_checkedContent(false) 12 , m_hasText(true) 13 { 14 SkSafeRef(m_picture); 15 }
DE04:
26 #ifndef PictureLayerContent_h 27 #define PictureLayerContent_h 28 29 #include "LayerContent.h" <= DE05 30 31 namespace WebCore { 32 33 class PictureLayerContent : public LayerContent { 34 public: 35 PictureLayerContent(SkPicture* picture); 36 PictureLayerContent(const PictureLayerContent& content); 37 ~PictureLayerContent(); 38 39 virtual int width(); 40 virtual int height(); 41 virtual bool isEmpty(); 42 virtual void setCheckForOptimisations(bool check) { m_checkedContent = !check; } 43 virtual void checkForOptimisations(); 44 virtual bool hasText(); 45 virtual void draw(SkCanvas* canvas); 46 virtual void serialize(SkWStream* stream); 47 48 private: 49 SkPicture* m_picture; 50 bool m_checkedContent; 51 bool m_hasText; 52 }; 53 54 } // WebCore 55 56 #endif // PictureLayerContent_h
DE05:
26 #ifndef LayerContent_h 27 #define LayerContent_h 28 29 #include "IntRect.h" 30 #include "SkRefCnt.h" 31 #include <utils/threads.h> 32 33 class SkCanvas; 34 class SkPicture; 35 class SkWStream; 36 37 namespace WebCore { 38 39 class PrerenderedInval; 40 41 class LayerContent : public SkRefCnt { 42 public: 43 virtual int width() = 0; 44 virtual int height() = 0; 45 virtual bool isEmpty() { return !width() || !height(); } 46 virtual void setCheckForOptimisations(bool check) = 0; 47 virtual void checkForOptimisations() = 0; 48 virtual bool hasText() = 0; 49 virtual void draw(SkCanvas* canvas) = 0; 50 virtual PrerenderedInval* prerenderForRect(const IntRect& dirty) { return 0; } 51 virtual void clearPrerenders() { }; 52 53 virtual void serialize(SkWStream* stream) = 0; 54 55 protected: 56 // used to prevent parallel draws, as both SkPicture and PictureSet don't support them 57 android::Mutex m_drawLock; 58 }; 59 60 } // WebCore 61 62 #endif // LayerContent_h 63
DE06:
523 void LayerAndroid::setContent(LayerContent* content) 524 { 525 SkSafeRef(content); 526 SkSafeUnref(m_content); 527 m_content = content; 528 }