Skip to content

Commit

Permalink
Only run display update passes for non-rooted CALayers when we're run…
Browse files Browse the repository at this point in the history
…ning as a framework.
  • Loading branch information
jaredhms authored and tadam-msft committed Sep 23, 2016
1 parent 90200b9 commit 80099e1
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 23 deletions.
37 changes: 21 additions & 16 deletions Frameworks/QuartzCore/CALayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2424,23 +2424,28 @@ - (void)_displayChanged {
^{
// If we have a valid non-dealloc'd object, run its display update pass
if (strongSuperLayer) {
strongSuperLayer->priv->_displayPending = false;

if (DEBUG_VERBOSE) {
TraceVerbose(
TAG,
L"Performing _displayChanged work for superlayer (%hs - 0x%p, %hs - 0x%p).",
object_getClassName(strongSuperLayer),
strongSuperLayer,
strongSuperLayer->priv->delegate ? object_getClassName(strongSuperLayer->priv->delegate) : "nil",
strongSuperLayer->priv->delegate);
// Only run the update pass for this superLayer if it's a 'root layer' - aka a UIWindow layer,
// or if we're running as a framework - aka for middleware scenarios - where the layer won't have
// a 'root' superlayer.
if (strongSuperLayer->priv->isRootLayer || GetCACompositor()->IsRunningAsFramework()) {
strongSuperLayer->priv->_displayPending = false;

if (DEBUG_VERBOSE) {
TraceVerbose(
TAG,
L"Performing _displayChanged work for superlayer (%hs - 0x%p, %hs - 0x%p).",
object_getClassName(strongSuperLayer),
strongSuperLayer,
strongSuperLayer->priv->delegate ? object_getClassName(strongSuperLayer->priv->delegate) : "nil",
strongSuperLayer->priv->delegate);
}

// Recalculate layouts
DoLayerLayouts(strongSuperLayer, true);

// Redisplay anything necessary
DoDisplayList(strongSuperLayer);
}

// Recalculate layouts
DoLayerLayouts(strongSuperLayer, true);

// Redisplay anything necessary
DoDisplayList(strongSuperLayer);
} else if (DEBUG_VERBOSE) {
TraceVerbose(TAG, L"Skipping _displayChanged work for currently-dealloc'd object (0x%p).", rawSuperLayerForLog);
}
Expand Down
7 changes: 7 additions & 0 deletions Frameworks/UIKit/StarboardXaml/CompositorInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ class DisplayNode;
class DisplayTexture;
class DisplayAnimation;

typedef enum {
CompositionModeDefault = 0,
CompositionModeLibrary = 1,
} CompositionMode;

void CreateXamlCompositor(winobjc::Id& root, CompositionMode compositionMode);

template <class T>
class RefCounted;

Expand Down
8 changes: 7 additions & 1 deletion Frameworks/UIKit/StarboardXaml/CompositorInterface.mm
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

@class RTObject;

CompositionMode g_compositionMode = CompositionModeDefault;
bool dxLandscape = false;

float screenWidth = 320.0f;
Expand Down Expand Up @@ -1609,9 +1610,14 @@ void DisableDisplaySyncNotification() override {
virtual void SetShouldRasterize(DisplayNode* node, bool rasterize) override {
node->SetShouldRasterize(rasterize);
}

virtual bool IsRunningAsFramework() override {
return g_compositionMode == CompositionModeLibrary;
}
};

void CreateXamlCompositor(winobjc::Id& root) {
void CreateXamlCompositor(winobjc::Id& root, CompositionMode compositionMode) {
g_compositionMode = compositionMode;
CGImageAddDestructionListener(UIReleaseDisplayTextureForCGImage);
static CAXamlCompositor* compIntr = new CAXamlCompositor();
SetCACompositor(compIntr);
Expand Down
2 changes: 1 addition & 1 deletion Frameworks/UIKit/StarboardXaml/StarboardXaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ void _ApplicationLaunch(ActivationType activationType, Platform::Object^ activat
auto rootFrame = ref new Xaml::Controls::Frame();
rootFrame->Content = uiElem;

SetXamlRoot(uiElem);
SetXamlRoot(uiElem, activationType);

if (activationType != ActivationTypeLibrary) {
Xaml::Window::Current->Content = rootFrame;
Expand Down
6 changes: 2 additions & 4 deletions Frameworks/UIKit/StarboardXaml/XamlCompositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,11 +624,9 @@ void SetScreenParameters(float width, float height, float magnification, float r
XamlCompositor::Controls::CALayerXaml::ApplyMagnificationFactor(windowCollection, magnification, rotation);
}

void CreateXamlCompositor(winobjc::Id& root);

extern "C" void SetXamlRoot(Windows::UI::Xaml::Controls::Grid^ grid) {
extern "C" void SetXamlRoot(Windows::UI::Xaml::Controls::Grid^ grid, ActivationType activationType) {
winobjc::Id gridObj((Platform::Object^)grid);
CreateXamlCompositor(gridObj);
CreateXamlCompositor(gridObj, ((activationType == ActivationTypeLibrary) ? CompositionModeLibrary : CompositionModeDefault));
}

void DispatchCompositorTransactions(
Expand Down
2 changes: 1 addition & 1 deletion Frameworks/UIKit/StarboardXaml/XamlCompositor.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
//******************************************************************************
#pragma once

extern "C" void SetXamlRoot(Windows::UI::Xaml::Controls::Grid ^ grid);
extern "C" void SetXamlRoot(Windows::UI::Xaml::Controls::Grid ^ grid, ActivationType activationType);
2 changes: 2 additions & 0 deletions Frameworks/include/CACompositor.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ class CACompositorInterface {
virtual void DisableDisplaySyncNotification() = 0;

virtual void SetShouldRasterize(DisplayNode* node, bool rasterize) = 0;

virtual bool IsRunningAsFramework() = 0;
};

extern CACompositorInterface* _globalCompositor;
Expand Down
4 changes: 4 additions & 0 deletions tests/unittests/UIKit/NullCompositor.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,8 @@ class NullCompositor : public CACompositorInterface {

virtual void SetShouldRasterize(DisplayNode* node, bool rasterize) override {
}

virtual bool IsRunningAsFramework() override {
return false;
}
};

0 comments on commit 80099e1

Please sign in to comment.