コード例 #1
0
ファイル: CompositionTarget.cs プロジェクト: sososu/wpf
        //----------------------------------------------------------------------
        //
        //  Private Methods
        //
        //----------------------------------------------------------------------

        #region Private Methods

        /// <summary>
        /// The compile method transforms the Visual Scene Graph into the Composition Scene Graph.
        /// </summary>
        private void Compile(DUCE.Channel channel)
        {
            MediaContext mctx = MediaContext.From(Dispatcher);

            Invariant.Assert(_rootVisual.Value != null);

            // 1) Check if we have a cached render context.
            // 2) Initialize the render context.
            // 3) Call to render the scene graph (transforming it into the composition scene graph).
            // 4) Deinitalize the render context and cache it if possible.

            // ------------------------------------------------------------------------------------
            // 1) Get cached render context if possible.

            // For performance reasons the render context is cached between frames. Here we check if
            // we have a cached one. If we don't we just create a new one. If we do have one, we use
            // the render context. Note that we null out the _cachedRenderContext field. This means
            // that in failure cases we will always recreate the render context.

            RenderContext rc = null;

            Invariant.Assert(channel != null);
            if (_cachedRenderContext != null)
            {
                rc = _cachedRenderContext;
                _cachedRenderContext = null;
            }
            else
            {
                rc = new RenderContext();
            }

            // ------------------------------------------------------------------------------------
            // 2) Prepare the render context.

            rc.Initialize(channel, _contentRoot.GetHandle(channel));

            // ------------------------------------------------------------------------------------
            // 3) Compile the scene.

            if (mctx.IsConnected)
            {
                _rootVisual.Value.Render(rc, 0);
            }

            // ------------------------------------------------------------------------------------
            // 4) Cache the render context.

            Debug.Assert(_cachedRenderContext == null);
            _cachedRenderContext = rc;
        }
コード例 #2
0
        /// <summary>
        /// AddRefOnChannel
        /// </summary>
        DUCE.ResourceHandle DUCE.IResource.AddRefOnChannel(DUCE.Channel channel)
        {
            // reconsider the need for this lock
            using (CompositionEngineLock.Acquire())
            {
#if DEBUG
                // We assume that a multi-channel resource can only be multi-channel
                // if it is Frozen and does not have animated properties. In this case we know
                // the target resource has at least one animated property so we expect that this
                // independently animated property resource will only be added to the channel
                // associated with the MediaContext associated with the target object's Dispatcher.

                DependencyObject d = (DependencyObject)_dependencyObject.Target;

                // I'm not sure how our target animated DependencyObject would get garbage
                // collected before we call AddRefOnChannel on one of its animated property
                // resources, but if it happens it will be a bad thing.
                Debug.Assert(d != null);

                // Any animated DependencyObject must be associated with a Dispatcher because the
                // AnimationClocks doing the animating must be associated with a Dispatcher.
                Debug.Assert(d.Dispatcher != null);

                // Make sure the target belongs to this thread
                Debug.Assert(d.CheckAccess());
#endif

                if (_duceResource.CreateOrAddRefOnChannel(this, channel, ResourceType))
                {
                    _updateResourceHandler = new MediaContext.ResourcesUpdatedHandler(UpdateResource);

                    UpdateResourceCore(channel);
                }

                return(_duceResource.GetHandle(channel));
            }
        }