Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: sky/engine/platform/graphics/GraphicsLayer.cpp

Issue 758843004: Delete most of rendering/compositing. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 Vector<FloatRect> repaintRects; 419 Vector<FloatRect> repaintRects;
420 repaintRects.append(largestRepaintRect); 420 repaintRects.append(largestRepaintRect);
421 repaintRectMap().set(this, repaintRects); 421 repaintRectMap().set(this, repaintRects);
422 } else { 422 } else {
423 Vector<FloatRect>& repaintRects = repaintIt->value; 423 Vector<FloatRect>& repaintRects = repaintIt->value;
424 repaintRects.append(largestRepaintRect); 424 repaintRects.append(largestRepaintRect);
425 } 425 }
426 } 426 }
427 } 427 }
428 428
429 static bool compareFloatRects(const FloatRect& a, const FloatRect& b)
430 {
431 if (a.x() != b.x())
432 return a.x() > b.x();
433 if (a.y() != b.y())
434 return a.y() > b.y();
435 if (a.width() != b.width())
436 return a.width() > b.width();
437 return a.height() > b.height();
438 }
439
440 template <typename T>
441 static PassRefPtr<JSONArray> pointAsJSONArray(const T& point)
442 {
443 RefPtr<JSONArray> array = adoptRef(new JSONArray);
444 array->pushNumber(point.x());
445 array->pushNumber(point.y());
446 return array;
447 }
448
449 template <typename T>
450 static PassRefPtr<JSONArray> sizeAsJSONArray(const T& size)
451 {
452 RefPtr<JSONArray> array = adoptRef(new JSONArray);
453 array->pushNumber(size.width());
454 array->pushNumber(size.height());
455 return array;
456 }
457
458 template <typename T>
459 static PassRefPtr<JSONArray> rectAsJSONArray(const T& rect)
460 {
461 RefPtr<JSONArray> array = adoptRef(new JSONArray);
462 array->pushNumber(rect.x());
463 array->pushNumber(rect.y());
464 array->pushNumber(rect.width());
465 array->pushNumber(rect.height());
466 return array;
467 }
468
469 static double roundCloseToZero(double number)
470 {
471 return std::abs(number) < 1e-7 ? 0 : number;
472 }
473
474 static PassRefPtr<JSONArray> transformAsJSONArray(const TransformationMatrix& t)
475 {
476 RefPtr<JSONArray> array = adoptRef(new JSONArray);
477 {
478 RefPtr<JSONArray> row = adoptRef(new JSONArray);
479 row->pushNumber(roundCloseToZero(t.m11()));
480 row->pushNumber(roundCloseToZero(t.m12()));
481 row->pushNumber(roundCloseToZero(t.m13()));
482 row->pushNumber(roundCloseToZero(t.m14()));
483 array->pushArray(row);
484 }
485 {
486 RefPtr<JSONArray> row = adoptRef(new JSONArray);
487 row->pushNumber(roundCloseToZero(t.m21()));
488 row->pushNumber(roundCloseToZero(t.m22()));
489 row->pushNumber(roundCloseToZero(t.m23()));
490 row->pushNumber(roundCloseToZero(t.m24()));
491 array->pushArray(row);
492 }
493 {
494 RefPtr<JSONArray> row = adoptRef(new JSONArray);
495 row->pushNumber(roundCloseToZero(t.m31()));
496 row->pushNumber(roundCloseToZero(t.m32()));
497 row->pushNumber(roundCloseToZero(t.m33()));
498 row->pushNumber(roundCloseToZero(t.m34()));
499 array->pushArray(row);
500 }
501 {
502 RefPtr<JSONArray> row = adoptRef(new JSONArray);
503 row->pushNumber(roundCloseToZero(t.m41()));
504 row->pushNumber(roundCloseToZero(t.m42()));
505 row->pushNumber(roundCloseToZero(t.m43()));
506 row->pushNumber(roundCloseToZero(t.m44()));
507 array->pushArray(row);
508 }
509 return array;
510 }
511
512 static String pointerAsString(const void* ptr)
513 {
514 TextStream ts;
515 ts << ptr;
516 return ts.release();
517 }
518
519 PassRefPtr<JSONObject> GraphicsLayer::layerTreeAsJSON(LayerTreeFlags flags, Rend eringContextMap& renderingContextMap) const
520 {
521 RefPtr<JSONObject> json = adoptRef(new JSONObject);
522
523 if (flags & LayerTreeIncludesDebugInfo) {
524 json->setString("this", pointerAsString(this));
525 json->setString("debugName", m_client->debugName(this));
526 }
527
528 if (m_position != FloatPoint())
529 json->setArray("position", pointAsJSONArray(m_position));
530
531 if (m_hasTransformOrigin && m_transformOrigin != FloatPoint3D(m_size.width() * 0.5f, m_size.height() * 0.5f, 0))
532 json->setArray("transformOrigin", pointAsJSONArray(m_transformOrigin));
533
534 if (m_size != IntSize())
535 json->setArray("bounds", sizeAsJSONArray(m_size));
536
537 if (m_opacity != 1)
538 json->setNumber("opacity", m_opacity);
539
540 if (m_blendMode != WebBlendModeNormal)
541 json->setString("blendMode", compositeOperatorName(CompositeSourceOver, m_blendMode));
542
543 if (m_contentsOpaque)
544 json->setBoolean("contentsOpaque", m_contentsOpaque);
545
546 if (!m_shouldFlattenTransform)
547 json->setBoolean("shouldFlattenTransform", m_shouldFlattenTransform);
548
549 if (m_3dRenderingContext) {
550 RenderingContextMap::const_iterator it = renderingContextMap.find(m_3dRe nderingContext);
551 int contextId = renderingContextMap.size() + 1;
552 if (it == renderingContextMap.end())
553 renderingContextMap.set(m_3dRenderingContext, contextId);
554 else
555 contextId = it->value;
556
557 json->setNumber("3dRenderingContext", contextId);
558 }
559
560 if (m_drawsContent)
561 json->setBoolean("drawsContent", m_drawsContent);
562
563 if (!m_contentsVisible)
564 json->setBoolean("contentsVisible", m_contentsVisible);
565
566 if (!m_backfaceVisibility)
567 json->setString("backfaceVisibility", m_backfaceVisibility ? "visible" : "hidden");
568
569 if (flags & LayerTreeIncludesDebugInfo)
570 json->setString("client", pointerAsString(m_client));
571
572 if (m_backgroundColor.alpha())
573 json->setString("backgroundColor", m_backgroundColor.nameForRenderTreeAs Text());
574
575 if (!m_transform.isIdentity())
576 json->setArray("transform", transformAsJSONArray(m_transform));
577
578 if ((flags & LayerTreeIncludesPaintInvalidationRects) && repaintRectMap().co ntains(this) && !repaintRectMap().get(this).isEmpty()) {
579 Vector<FloatRect> repaintRectsCopy = repaintRectMap().get(this);
580 std::sort(repaintRectsCopy.begin(), repaintRectsCopy.end(), &compareFloa tRects);
581 RefPtr<JSONArray> repaintRectsJSON = adoptRef(new JSONArray);
582 for (size_t i = 0; i < repaintRectsCopy.size(); ++i) {
583 if (repaintRectsCopy[i].isEmpty())
584 continue;
585 repaintRectsJSON->pushArray(rectAsJSONArray(repaintRectsCopy[i]));
586 }
587 json->setArray("repaintRects", repaintRectsJSON);
588 }
589
590 if ((flags & LayerTreeIncludesPaintingPhases) && m_paintingPhase) {
591 RefPtr<JSONArray> paintingPhasesJSON = adoptRef(new JSONArray);
592 if (m_paintingPhase & GraphicsLayerPaintBackground)
593 paintingPhasesJSON->pushString("GraphicsLayerPaintBackground");
594 if (m_paintingPhase & GraphicsLayerPaintForeground)
595 paintingPhasesJSON->pushString("GraphicsLayerPaintForeground");
596 if (m_paintingPhase & GraphicsLayerPaintMask)
597 paintingPhasesJSON->pushString("GraphicsLayerPaintMask");
598 if (m_paintingPhase & GraphicsLayerPaintChildClippingMask)
599 paintingPhasesJSON->pushString("GraphicsLayerPaintChildClippingMask" );
600 if (m_paintingPhase & GraphicsLayerPaintOverflowContents)
601 paintingPhasesJSON->pushString("GraphicsLayerPaintOverflowContents") ;
602 json->setArray("paintingPhases", paintingPhasesJSON);
603 }
604
605 if (flags & LayerTreeIncludesClipAndScrollParents) {
606 if (m_hasScrollParent)
607 json->setBoolean("hasScrollParent", true);
608 if (m_hasClipParent)
609 json->setBoolean("hasClipParent", true);
610 }
611
612 if (flags & LayerTreeIncludesDebugInfo) {
613 RefPtr<JSONArray> compositingReasonsJSON = adoptRef(new JSONArray);
614 for (size_t i = 0; i < kNumberOfCompositingReasons; ++i) {
615 if (m_debugInfo.compositingReasons() & kCompositingReasonStringMap[i ].reason)
616 compositingReasonsJSON->pushString(kCompositingReasonStringMap[i ].description);
617 }
618 json->setArray("compositingReasons", compositingReasonsJSON);
619 }
620
621 if (m_children.size()) {
622 RefPtr<JSONArray> childrenJSON = adoptRef(new JSONArray);
623 for (size_t i = 0; i < m_children.size(); i++)
624 childrenJSON->pushObject(m_children[i]->layerTreeAsJSON(flags, rende ringContextMap));
625 json->setArray("children", childrenJSON);
626 }
627
628 return json;
629 }
630
631 String GraphicsLayer::layerTreeAsText(LayerTreeFlags flags) const
632 {
633 RenderingContextMap renderingContextMap;
634 RefPtr<JSONObject> json = layerTreeAsJSON(flags, renderingContextMap);
635 return json->toPrettyJSONString();
636 }
637
638 String GraphicsLayer::debugName(WebLayer* webLayer) const 429 String GraphicsLayer::debugName(WebLayer* webLayer) const
639 { 430 {
640 String name; 431 String name;
641 if (!m_client) 432 if (!m_client)
642 return name; 433 return name;
643 434
644 String highlightDebugName; 435 String highlightDebugName;
645 for (size_t i = 0; i < m_linkHighlights.size(); ++i) { 436 for (size_t i = 0; i < m_linkHighlights.size(); ++i) {
646 if (webLayer == m_linkHighlights[i]->layer()) { 437 if (webLayer == m_linkHighlights[i]->layer()) {
647 highlightDebugName = "LinkHighlight[" + String::number(i) + "] for " + m_client->debugName(this); 438 highlightDebugName = "LinkHighlight[" + String::number(i) + "] for " + m_client->debugName(this);
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 // Do nothing. 772 // Do nothing.
982 } 773 }
983 774
984 void GraphicsLayer::didScroll() 775 void GraphicsLayer::didScroll()
985 { 776 {
986 if (m_scrollableArea) 777 if (m_scrollableArea)
987 m_scrollableArea->scrollToOffsetWithoutAnimation(m_scrollableArea->minim umScrollPosition() + toIntSize(m_layer->layer()->scrollPosition())); 778 m_scrollableArea->scrollToOffsetWithoutAnimation(m_scrollableArea->minim umScrollPosition() + toIntSize(m_layer->layer()->scrollPosition()));
988 } 779 }
989 780
990 } // namespace blink 781 } // namespace blink
991
992 #ifndef NDEBUG
993 void showGraphicsLayerTree(const blink::GraphicsLayer* layer)
994 {
995 if (!layer)
996 return;
997
998 String output = layer->layerTreeAsText(blink::LayerTreeIncludesDebugInfo);
999 fprintf(stderr, "%s\n", output.utf8().data());
1000 }
1001 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698