Welcome to mirror list, hosted at ThFree Co, Russian Federation.

QT9AllocatorPresenter.cpp « VideoRenderers « renderer « filters « src - github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bd74d8d8d03205943ece6f7b12201435cf5747b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
 * (C) 2006-2014, 2016 see Authors.txt
 *
 * This file is part of MPC-HC.
 *
 * MPC-HC is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * MPC-HC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "stdafx.h"
#include "QT9AllocatorPresenter.h"
#include "../../../DSUtil/vd.h"

using namespace DSObjects;

//
// CQT9AllocatorPresenter
//

CQT9AllocatorPresenter::CQT9AllocatorPresenter(HWND hWnd, bool bFullscreen, HRESULT& hr, CString& _Error)
    : CDX9AllocatorPresenter(hWnd, bFullscreen, hr, false, _Error)
{
}

STDMETHODIMP CQT9AllocatorPresenter::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
    CheckPointer(ppv, E_POINTER);

    return
        QI(IQTVideoSurface)
        __super::NonDelegatingQueryInterface(riid, ppv);
}

HRESULT CQT9AllocatorPresenter::AllocSurfaces()
{
    CheckPointer(m_pD3DDev, E_POINTER);

    HRESULT hr;

    m_pVideoSurfaceOff = nullptr;

    if (FAILED(hr = m_pD3DDev->CreateOffscreenPlainSurface(
                        m_nativeVideoSize.cx, m_nativeVideoSize.cy, D3DFMT_X8R8G8B8,
                        D3DPOOL_DEFAULT, &m_pVideoSurfaceOff, nullptr))) {
        return hr;
    }

    return __super::AllocSurfaces();
}

void CQT9AllocatorPresenter::DeleteSurfaces()
{
    m_pVideoSurfaceOff = nullptr;

    __super::DeleteSurfaces();
}

// IQTVideoSurface

STDMETHODIMP CQT9AllocatorPresenter::BeginBlt(const BITMAP& bm)
{
    CAutoLock cAutoLock(this);
    CAutoLock cRenderLock(&m_RenderLock);
    DeleteSurfaces();
    SetVideoSize(CSize(bm.bmWidth, abs(bm.bmHeight)));
    if (FAILED(AllocSurfaces())) {
        return E_FAIL;
    }
    return S_OK;
}

STDMETHODIMP CQT9AllocatorPresenter::DoBlt(const BITMAP& bm)
{
    if (!m_pVideoSurface[m_nCurSurface] || !m_pVideoSurfaceOff) {
        return E_FAIL;
    }

    bool fOk = false;

    D3DSURFACE_DESC desc;
    ZeroMemory(&desc, sizeof(desc));
    if (FAILED(m_pVideoSurfaceOff->GetDesc(&desc))) {
        return E_FAIL;
    }

    UINT w = (UINT)bm.bmWidth;
    UINT h = abs(bm.bmHeight);
    int bpp = bm.bmBitsPixel;
    int dbpp =
        desc.Format == D3DFMT_R8G8B8 || desc.Format == D3DFMT_X8R8G8B8 || desc.Format == D3DFMT_A8R8G8B8 ? 32 :
        desc.Format == D3DFMT_R5G6B5 ? 16 : 0;

    if ((bpp == 16 || bpp == 24 || bpp == 32) && w == desc.Width && h == desc.Height) {
        D3DLOCKED_RECT r;
        if (SUCCEEDED(m_pVideoSurfaceOff->LockRect(&r, nullptr, 0))) {
            BitBltFromRGBToRGB(
                w, h,
                (BYTE*)r.pBits, r.Pitch, dbpp,
                (BYTE*)bm.bmBits, bm.bmWidthBytes, bm.bmBitsPixel);
            m_pVideoSurfaceOff->UnlockRect();
            fOk = true;
        }
    }

    if (!fOk) {
        m_pD3DDev->ColorFill(m_pVideoSurfaceOff, nullptr, 0);

        HDC hDC;
        if (SUCCEEDED(m_pVideoSurfaceOff->GetDC(&hDC))) {
            CString str;
            str.Format(_T("Sorry, this color format is not supported"));

            SetBkColor(hDC, 0);
            SetTextColor(hDC, 0x404040);
            TextOut(hDC, 10, 10, str, str.GetLength());

            m_pVideoSurfaceOff->ReleaseDC(hDC);
        }
    }

    m_pD3DDev->StretchRect(m_pVideoSurfaceOff, nullptr, m_pVideoSurface[m_nCurSurface], nullptr, D3DTEXF_NONE);

    Paint(true);

    return S_OK;
}