Example #1
0
    IFACEMETHODIMP CanvasSwapChain::PresentWithSyncInterval(int32_t syncInterval)
    {
        return ExceptionBoundary(
            [&]
            {
                auto lock = GetResourceLock();
                auto& resource = GetResource();

                DXGI_PRESENT_PARAMETERS presentParameters = { 0 };
                ThrowIfFailed(resource->Present1(syncInterval, 0, &presentParameters));
            });
    }
Example #2
0
    IFACEMETHODIMP CanvasSwapChain::put_Rotation(CanvasSwapChainRotation value)
    {
        return ExceptionBoundary(
            [&]
            {
                auto lock = GetResourceLock();
                
                auto& resource = GetResource();

                ThrowIfFailed(resource->SetRotation(ToDxgiRotation(value)));
            });
    }
Example #3
0
    IFACEMETHODIMP CanvasSwapChain::get_Device(ICanvasDevice** value)
    {
        return ExceptionBoundary(
            [&]
            {
                CheckInPointer(value);

                auto& device = m_device.EnsureNotClosed();

                ThrowIfFailed(device.CopyTo(value));
            });
    }
Example #4
0
    IFACEMETHODIMP CanvasSwapChain::get_Format(DirectXPixelFormat* value)
    {
        return ExceptionBoundary(
            [&]
            {
                CheckInPointer(value);

                auto lock = GetResourceLock();
                auto desc = GetSwapChainDesc(lock);

                *value = static_cast<DirectXPixelFormat>(desc.Format);
            });
    }
Example #5
0
    IFACEMETHODIMP CanvasSwapChain::get_BufferCount(int32_t* value)
    {
        return ExceptionBoundary(
            [&]
            {
                CheckInPointer(value);

                auto lock = GetResourceLock();
                auto desc = GetSwapChainDesc(lock);

                *value = desc.BufferCount;
            });
    }
Example #6
0
    IFACEMETHODIMP CanvasSwapChain::get_AlphaMode(CanvasAlphaMode* value) 
    {
        return ExceptionBoundary(
            [&]
            {
                CheckInPointer(value);

                auto lock = GetResourceLock();
                auto desc = GetSwapChainDesc(lock);

                *value = FromDxgiAlphaMode(desc.AlphaMode);
            });
    }
    virtual IFACEMETHODIMP get_Dpi(float* value)
    {
        return ExceptionBoundary(
            [&]
            {
                EnsureValidResource();

                float pixelsPerDip;
                ThrowIfFailed(m_dwriteTextRenderer->GetPixelsPerDip(nullptr, &pixelsPerDip));

                *value = pixelsPerDip * DEFAULT_DPI;
            });
    }
    virtual IFACEMETHODIMP get_PixelSnappingDisabled(boolean* value)
    {
        return ExceptionBoundary(
            [&]
            {
                EnsureValidResource();

                BOOL isPixelSnappingDisabled;
                ThrowIfFailed(m_dwriteTextRenderer->IsPixelSnappingDisabled(nullptr, &isPixelSnappingDisabled));

                *value = !!isPixelSnappingDisabled;
            });
    }
Example #9
0
    IFACEMETHODIMP CanvasSwapChain::put_TransformMatrix(Matrix3x2 value)
    {
        return ExceptionBoundary(
            [&]
            {
                auto lock = GetResourceLock();

                // Insert additional scaling to account for display DPI.
                auto swapChain = As<IDXGISwapChain2>(GetResource());

                SetMatrixInternal(lock, swapChain, ReinterpretAs<DXGI_MATRIX_3X2_F*>(&value));
            });
    }
    virtual IFACEMETHODIMP get_Transform(Matrix3x2* value)
    {
        return ExceptionBoundary(
            [&]
            {
                EnsureValidResource();

                DWRITE_MATRIX transform;
                ThrowIfFailed(m_dwriteTextRenderer->GetCurrentTransform(nullptr, &transform));

                *value = *(ReinterpretAs<Matrix3x2*>(&transform));
            });
    }
Example #11
0
    IFACEMETHODIMP CanvasSwapChain::get_SizeInPixels(BitmapSize* value)
    {
        return ExceptionBoundary(
            [&]
            {
                CheckInPointer(value);

                auto lock = GetResourceLock();
                auto desc = GetSwapChainDesc(lock);

                *value = BitmapSize{ desc.Width, desc.Height };
            });
    }
    IFACEMETHODIMP DrawGlyphRun(
        Vector2 baselineOrigin,
        ICanvasFontFace* fontFace,
        float fontSize,
        uint32_t glyphCount,
        CanvasGlyph* glyphs,
        boolean isSideways,
        uint32_t bidiLevel,
        IInspectable* brush,
        CanvasTextMeasuringMode measuringMode,
        HSTRING locale,
        HSTRING text,
        uint32_t clusterMapIndicesCount,
        int* clusterMapIndices,
        unsigned int characterIndex,
        CanvasGlyphOrientation glyphOrientation) override
    {
        return ExceptionBoundary(
            [&]
            {
                EnsureValidResource();

                auto deviceContextLease = As<ICanvasDeviceInternal>(m_device)->GetResourceCreationDeviceContext();

                DrawGlyphRunHelper helper(
                    fontFace,
                    fontSize,
                    glyphCount,
                    glyphs,
                    isSideways,
                    bidiLevel,
                    brush,
                    measuringMode,
                    locale,
                    text,
                    clusterMapIndicesCount,
                    clusterMapIndices,
                    characterIndex,
                    deviceContextLease.Get());

                ThrowIfFailed(m_dwriteTextRenderer->DrawGlyphRun(
                    nullptr,
                    baselineOrigin.X,
                    baselineOrigin.Y,
                    ToDWriteGlyphOrientationAngle(glyphOrientation),
                    helper.MeasuringMode,
                    &helper.DWriteGlyphRun,
                    &helper.DWriteGlyphRunDescription,
                    helper.ClientDrawingEffect.Get())); 
            });
    }
Example #13
0
 HRESULT __declspec(nothrow) CanvasTextFormat::PropertyGet(T* value, ST const& shadowValue, FN realizedGetter)
 {
     return ExceptionBoundary(
         [&]
         {
             CheckInPointer(value);
             ThrowIfClosed();
             
             if (m_format)
                 SetFrom(value, realizedGetter());
             else
                 SetFrom(value, shadowValue);
         });
 }
Example #14
0
    IFACEMETHODIMP CanvasSwapChain::get_Size(Size* value)
    {
        return ExceptionBoundary(
            [&]
            {
                CheckInPointer(value);

                auto lock = GetResourceLock();
                auto desc = GetSwapChainDesc(lock);

                *value = Size{ PixelsToDips(desc.Width, m_dpi),
                               PixelsToDips(desc.Height, m_dpi) };
        });
    }
Example #15
0
    IFACEMETHODIMP CanvasTextFormatFactory::GetOrCreate(
        IUnknown* resource,
        IInspectable** wrapper)
    {
        return ExceptionBoundary(
            [&]
            {
                ComPtr<IDWriteTextFormat> dwriteTextFormat;
                ThrowIfFailed(resource->QueryInterface(dwriteTextFormat.GetAddressOf()));

                auto newCanvasTextFormat = Make<CanvasTextFormat>(dwriteTextFormat.Get());
                CheckMakeResult(newCanvasTextFormat);
                ThrowIfFailed(newCanvasTextFormat.CopyTo(wrapper));
            });
    }
Example #16
0
    IFACEMETHODIMP CanvasSwapChain::put_SourceSize(Size value)
    {
        return ExceptionBoundary(
            [&]
            {
                auto lock = GetResourceLock();
                
                uint32_t width = SizeDipsToPixels(value.Width, m_dpi);
                uint32_t height = SizeDipsToPixels(value.Height, m_dpi);

                auto swapChain = As<IDXGISwapChain2>(GetResource());

                ThrowIfFailed(swapChain->SetSourceSize(width, height));
            });
    }
Example #17
0
    IFACEMETHODIMP AddStreamSink(
        DWORD /*streamSinkIdentifier*/,
        _In_ IMFMediaType * /*mediaType*/,
        _COM_Outptr_ IMFStreamSink **streamSink
        )
    {
        return ExceptionBoundary([this, streamSink]()
        {
            _VerifyNotShutdown();

            CHKNULL(streamSink);
            *streamSink = nullptr;

            CHK(MF_E_STREAMSINKS_FIXED);
        });
    }
 IFACEMETHODIMP CanvasCommandListFactory::Create(
     ICanvasResourceCreator* resourceCreator,
     ICanvasCommandList** commandList)
 {
     return ExceptionBoundary(
         [&]
         {
             CheckInPointer(resourceCreator);
             
             ComPtr<ICanvasDevice> device;
             ThrowIfFailed(resourceCreator->get_Device(&device));
             
             auto cl = CanvasCommandList::CreateNew(device.Get());
             ThrowIfFailed(cl.CopyTo(commandList));
         });
 }
Example #19
0
    IFACEMETHODIMP CanvasSwapChain::get_TransformMatrix(Matrix3x2* value)
    {
        return ExceptionBoundary(
            [&]
            {
                CheckInPointer(value);

                auto lock = GetResourceLock();

                auto swapChain = As<IDXGISwapChain2>(GetResource());

                DXGI_MATRIX_3X2_F matrix = GetMatrixInternal(lock, swapChain);

                *value = *ReinterpretAs<Matrix3x2*>(&matrix);
            });
    }
Example #20
0
    IFACEMETHODIMP CanvasSwapChain::get_Rotation(CanvasSwapChainRotation* value)
    {
        return ExceptionBoundary(
            [&]
            {
                CheckInPointer(value);

                auto lock = GetResourceLock();

                auto& resource = GetResource();

                DXGI_MODE_ROTATION rotation;
                ThrowIfFailed(resource->GetRotation(&rotation));

                *value = FromDxgiRotation(rotation);
            });
    }
 IFACEMETHODIMP ImageControlMixIn::ArrangeOverride(
     Size finalSize, 
     Size* returnValue)
 {
     return ExceptionBoundary(
         [&]
         {
             //
             // Call Arrange on our children (in this case just the image control).
             //
             ThrowIfFailed(As<IUIElement>(m_imageControl)->Arrange(Rect{ 0, 0, finalSize.Width, finalSize.Height }));
             
             //
             // Reply that we're happy to accept the size chosen by the layout engine.
             //
             *returnValue = finalSize;
         });
 }
Example #22
0
    IFACEMETHODIMP CanvasTextFormat::put_Options(CanvasDrawTextOptions value)
    {
        return ExceptionBoundary(
            [&]
            {
                ThrowIfClosed();

                auto validOptions = 
                    CanvasDrawTextOptions::NoSnap |
                    CanvasDrawTextOptions::Clip |
                    CanvasDrawTextOptions::EnableColorFont;

                if ((value & ~validOptions) != CanvasDrawTextOptions::Default)
                    ThrowHR(E_INVALIDARG);

                m_drawTextOptions = value;
            });
    }
Example #23
0
    IFACEMETHODIMP CanvasSwapChain::ResizeBuffersWithWidthAndHeight(
        float newWidth,
        float newHeight)
    {
        return ExceptionBoundary(
            [&]
            {
                auto lock = GetResourceLock();
                auto desc = GetSwapChainDesc(lock);

                ResizeBuffersImpl(
                    lock,
                    newWidth,
                    newHeight,
                    m_dpi,
                    static_cast<DirectXPixelFormat>(desc.Format),
                    desc.BufferCount);
            });
    }
Example #24
0
    IFACEMETHODIMP CanvasSwapChain::get_SourceSize(Size* value)
    {
        return ExceptionBoundary(
            [&]
            {
                CheckInPointer(value);

                auto lock = GetResourceLock();

                auto swapChain = As<IDXGISwapChain2>(GetResource());

                uint32_t width;
                uint32_t height;
                ThrowIfFailed(swapChain->GetSourceSize(&width, &height));

                *value = Size{ PixelsToDips(width, m_dpi),
                               PixelsToDips(height, m_dpi) };
            });
    }
    IFACEMETHODIMP DrawUnderline(
        Vector2 baselineOrigin,
        float width,
        float thickness,
        float offset,
        float runHeight,
        CanvasTextDirection textDirection,
        IInspectable* brush,
        CanvasTextMeasuringMode measuringMode,
        HSTRING locale,
        CanvasGlyphOrientation glyphOrientation)
    {
        return ExceptionBoundary(
            [&]
            {
                EnsureValidResource();

                DWRITE_UNDERLINE underline{};
                underline.width = width;
                underline.thickness = thickness;
                underline.offset = offset;
                underline.runHeight = runHeight;

                auto textDirectionLookup = DWriteToCanvasTextDirection::Lookup(textDirection);
                underline.flowDirection = textDirectionLookup->FlowDirection;
                underline.readingDirection = textDirectionLookup->ReadingDirection;
                underline.measuringMode = ToDWriteMeasuringMode(measuringMode);

                auto deviceContextLease = As<ICanvasDeviceInternal>(m_device)->GetResourceCreationDeviceContext();

                if (locale)
                    underline.localeName = WindowsGetStringRawBuffer(locale, nullptr);

                ThrowIfFailed(m_dwriteTextRenderer->DrawUnderline(
                    nullptr,
                    baselineOrigin.X,
                    baselineOrigin.Y,
                    ToDWriteGlyphOrientationAngle(glyphOrientation),
                    &underline,
                    DrawGlyphRunHelper::GetClientDrawingEffect(brush, deviceContextLease.Get()).Get()));
            });
    }
IFACEMETHODIMP InternalDWriteTextRenderer::DrawInlineObject(
    void*,
    FLOAT baselineOriginX,
    FLOAT baselineOriginY,
    DWRITE_GLYPH_ORIENTATION_ANGLE orientationAngle,
    IDWriteInlineObject* inlineObject,
    BOOL isSideways,
    BOOL isRightToLeft,
    IUnknown* brush)
{
    return ExceptionBoundary(
        [&]
        {
            auto canvasInlineObject = GetCanvasInlineObjectFromDWriteInlineObject(inlineObject, false);

            auto customDrawingObjectInspectable = GetCustomDrawingObjectInspectable(m_device.Get(), brush);

            if (canvasInlineObject)
            {
                ThrowIfFailed(m_textRenderer->DrawInlineObject(
                    Vector2{ baselineOriginX, baselineOriginY },
                    canvasInlineObject.Get(),
                    !!isSideways,
                    !!isRightToLeft,
                    customDrawingObjectInspectable.Get(),
                    ToCanvasGlyphOrientation(orientationAngle)));
            }
            else
            {
                //
                // Inline objects may be implemented by the app. Or, they may be implemented by
                // DWrite, an important example of which being an ellipsis trimming sign. 
                // We've reached this spot if it's the latter.
                // 
                // In this case, we don't call into the app's custom renderer callback since
                // it doesn't know anything about the DWrite-implemented inline object.
                // We forward the Draw call along.
                //
                ThrowIfFailed(inlineObject->Draw(nullptr, this, baselineOriginX, baselineOriginY, isSideways, isRightToLeft, brush));
            }
        });
}
Example #27
0
 IFACEMETHODIMP CanvasSwapChain::ResizeBuffersWithAllOptions(
     float newWidth,
     float newHeight,
     float newDpi,
     DirectXPixelFormat newFormat,
     int32_t bufferCount)
 {
     return ExceptionBoundary(
         [&]
         {
             auto lock = GetResourceLock();
             ResizeBuffersImpl(
                 lock,
                 newWidth,
                 newHeight,
                 newDpi,
                 newFormat,
                 bufferCount);
         });
 }
Example #28
0
    IFACEMETHODIMP SetPresentationClock(_In_ IMFPresentationClock *clock)
    {
        return ExceptionBoundary([this, clock]()
        {
            auto lock = _lock.LockExclusive();

            _VerifyNotShutdown();

            if (_clock != nullptr)
            {
                CHK(_clock->RemoveClockStateSink(this));
                _clock = nullptr;
            }

            if (clock != nullptr)
            {
                CHK(clock->AddClockStateSink(this));
                _clock = clock;
            }
        });
    }
Example #29
0
    IFACEMETHODIMP GetStreamSinkByIndex(DWORD index, _COM_Outptr_ IMFStreamSink **streamSink)
    {
        return ExceptionBoundary([this, index, streamSink]()
        {
            auto lock = _lock.LockExclusive();

            CHKNULL(streamSink);
            *streamSink = nullptr;

            _VerifyNotShutdown();

            switch (index)
            {
            case 0:
                if (_audioStreamSink != nullptr)
                {
                    CHK(_audioStreamSink.CopyTo(streamSink));
                }
                else
                {
                    CHK(_videoStreamSink.CopyTo(streamSink));
                }
                break;

            case 1:
                if ((_audioStreamSink != nullptr) && (_videoStreamSink != nullptr))
                {
                    CHK(_videoStreamSink.CopyTo(streamSink));
                }
                else
                {
                    CHK(E_INVALIDARG);
                }
                break;

            default:
                CHK(E_INVALIDARG);
            }
        });
    }
 IFACEMETHODIMP ImageControlMixIn::MeasureOverride(
     Size availableSize, 
     Size* returnValue)
 {
     UNREFERENCED_PARAMETER(availableSize);
     
     return ExceptionBoundary(
         [&]
         {
             Size zeroSize{ 0, 0 };
             
             //
             // Call Measure on our children (in this case just the image control).
             //
             ThrowIfFailed(As<IUIElement>(m_imageControl)->Measure(zeroSize));
             
             //
             // Reply that we're happy to be sized however the layout engine wants to size us.
             //
             *returnValue = zeroSize;
         });
 }