Skip to content

Commit 7006f01

Browse files
authored
Merge pull request #19480 from oltolm/comptr_misc
use ComPtr for misc. things
2 parents b73536f + 5c1412f commit 7006f01

12 files changed

+110
-126
lines changed

GPU/Common/Draw2D.h

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#pragma once
22

3+
#include "Data/Collections/Slice.h"
34
#include "GPU/GPU.h"
45
#include "Common/GPU/Shader.h"
6+
#include "GPU/thin3d.h"
57

68
// For framebuffer copies and similar things that just require passthrough.
79
struct Draw2DVertex {

UI/RemoteISOScreen.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
1717

1818
#include "ppsspp_config.h"
19-
#include <algorithm>
2019
#include <thread>
2120
#include <mutex>
2221

2322
#if PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP)
23+
#include <initguid.h>
2424
#include "Common/CommonWindows.h"
2525
#include <netfw.h>
26+
#include <wrl/client.h>
2627
#endif
2728

2829
// TODO: For text align flags, probably shouldn't be in gfx_es2/...
@@ -62,8 +63,8 @@ enum class ServerAllowStatus {
6263

6364
static ServerAllowStatus IsServerAllowed(int port) {
6465
#if PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP)
65-
INetFwMgr *fwMgr = nullptr;
66-
HRESULT hr = CoCreateInstance(__uuidof(NetFwMgr), nullptr, CLSCTX_INPROC_SERVER, __uuidof(INetFwMgr), (void **)&fwMgr);
66+
Microsoft::WRL::ComPtr<INetFwMgr> fwMgr;
67+
HRESULT hr = CoCreateInstance(__uuidof(NetFwMgr), nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&fwMgr));
6768
if (FAILED(hr)) {
6869
return ServerAllowStatus::UNKNOWN;
6970
}
@@ -80,7 +81,6 @@ static ServerAllowStatus IsServerAllowed(int port) {
8081
VariantInit(&allowedV);
8182
VariantInit(&restrictedV);
8283
hr = fwMgr->IsPortAllowed(&app[0], NET_FW_IP_VERSION_ANY, port, nullptr, NET_FW_IP_PROTOCOL_TCP, &allowedV, &restrictedV);
83-
fwMgr->Release();
8484

8585
if (FAILED(hr)) {
8686
return ServerAllowStatus::UNKNOWN;

Windows/BufferLock.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
#pragma once
1515

16+
#include "CaptureDevice.h"
17+
#include <wrl/client.h>
18+
1619

1720
//-------------------------------------------------------------------
1821
// VideoBufferLock class
@@ -27,17 +30,14 @@ class VideoBufferLock
2730
VideoBufferLock(IMFMediaBuffer *pBuffer) : m_p2DBuffer(NULL), m_bLocked(FALSE)
2831
{
2932
m_pBuffer = pBuffer;
30-
m_pBuffer->AddRef();
31-
33+
3234
// Query for the 2-D buffer interface. OK if this fails.
3335
(void)m_pBuffer->QueryInterface(IID_PPV_ARGS(&m_p2DBuffer));
3436
}
3537

3638
~VideoBufferLock()
3739
{
3840
UnlockBuffer();
39-
SafeRelease(&m_pBuffer);
40-
SafeRelease(&m_p2DBuffer);
4141
}
4242

4343
//-------------------------------------------------------------------
@@ -116,8 +116,8 @@ class VideoBufferLock
116116
}
117117

118118
private:
119-
IMFMediaBuffer *m_pBuffer;
120-
IMF2DBuffer *m_p2DBuffer;
119+
Microsoft::WRL::ComPtr<IMFMediaBuffer> m_pBuffer;
120+
Microsoft::WRL::ComPtr<IMF2DBuffer> m_p2DBuffer;
121121

122122
BOOL m_bLocked;
123123
};

Windows/CaptureDevice.cpp

+26-33
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
1717

1818
#include <shlwapi.h>
19+
#include <wrl/client.h>
1920

2021
#include "Common/Thread/ThreadUtil.h"
2122
#include "CaptureDevice.h"
@@ -25,6 +26,8 @@
2526
#include "Core/HLE/sceUsbCam.h"
2627
#include "Core/Config.h"
2728

29+
using Microsoft::WRL::ComPtr;
30+
2831
namespace MFAPI {
2932
HINSTANCE Mflib;
3033
HINSTANCE Mfplatlib;
@@ -142,7 +145,7 @@ HRESULT ReaderCallback::OnReadSample(
142145
LONGLONG llTimestamp,
143146
IMFSample *pSample) {
144147
HRESULT hr = S_OK;
145-
IMFMediaBuffer *pBuffer = nullptr;
148+
ComPtr<IMFMediaBuffer> pBuffer;
146149
std::lock_guard<std::mutex> lock(device->sdMutex);
147150
if (device->isShutDown())
148151
return hr;
@@ -173,7 +176,7 @@ HRESULT ReaderCallback::OnReadSample(
173176

174177
// pSample can be null, in this case ReadSample still should be called to request next frame.
175178
if (pSample) {
176-
videoBuffer = new VideoBufferLock(pBuffer);
179+
videoBuffer = new VideoBufferLock(pBuffer.Get());
177180
hr = videoBuffer->LockBuffer(device->deviceParam.default_stride, device->deviceParam.height, &pbScanline0, &lStride);
178181

179182
if (lStride > 0)
@@ -278,7 +281,6 @@ HRESULT ReaderCallback::OnReadSample(
278281
}
279282
}
280283

281-
SafeRelease(&pBuffer);
282284
return hr;
283285
}
284286

@@ -522,18 +524,15 @@ bool WindowsCaptureDevice::init() {
522524

523525
bool WindowsCaptureDevice::start(void *startParam) {
524526
HRESULT hr = S_OK;
525-
IMFAttributes *pAttributes = nullptr;
526-
IMFMediaType *pType = nullptr;
527+
ComPtr<IMFAttributes> pAttributes;
528+
ComPtr<IMFMediaType> pType;
527529
UINT32 selection = 0;
528530
UINT32 count = 0;
529531

530532
// Release old sources first(if any).
531-
SafeRelease(&m_pSource);
532-
SafeRelease(&m_pReader);
533-
if (m_pCallback) {
534-
delete m_pCallback;
535-
m_pCallback = nullptr;
536-
}
533+
m_pSource = nullptr;
534+
m_pReader = nullptr;
535+
m_pCallback = nullptr;
537536
// Need to re-enumerate the list,because old sources were released.
538537
std::vector<std::string> deviceList = getDeviceList(true);
539538

@@ -555,25 +554,24 @@ bool WindowsCaptureDevice::start(void *startParam) {
555554
}
556555
++count;
557556
}
558-
setSelction(selection);
557+
setSelection(selection);
559558
hr = param.ppDevices[param.selection]->ActivateObject(
560-
__uuidof(IMFMediaSource),
561-
(void**)&m_pSource);
559+
IID_PPV_ARGS(&m_pSource));
562560

563561
if (SUCCEEDED(hr))
564562
hr = MFCreateAttributes(&pAttributes, 2);
565563

566564
// Use async mode
567565
if (SUCCEEDED(hr))
568-
hr = pAttributes->SetUnknown(MF_SOURCE_READER_ASYNC_CALLBACK, m_pCallback);
566+
hr = pAttributes->SetUnknown(MF_SOURCE_READER_ASYNC_CALLBACK, m_pCallback.Get());
569567

570568
if (SUCCEEDED(hr))
571569
hr = pAttributes->SetUINT32(MF_READWRITE_DISABLE_CONVERTERS, TRUE);
572570

573571
if (SUCCEEDED(hr)) {
574572
hr = CreateSourceReaderFromMediaSource(
575-
m_pSource,
576-
pAttributes,
573+
m_pSource.Get(),
574+
pAttributes.Get(),
577575
&m_pReader
578576
);
579577
}
@@ -609,7 +607,7 @@ bool WindowsCaptureDevice::start(void *startParam) {
609607

610608
if (FAILED(hr)) { break; }
611609

612-
hr = setDeviceParam(pType);
610+
hr = setDeviceParam(pType.Get());
613611

614612
if (SUCCEEDED(hr))
615613
break;
@@ -654,7 +652,7 @@ bool WindowsCaptureDevice::start(void *startParam) {
654652

655653
if (FAILED(hr)) { break; }
656654

657-
hr = setDeviceParam(pType);
655+
hr = setDeviceParam(pType.Get());
658656

659657
if (SUCCEEDED(hr))
660658
break;
@@ -679,15 +677,11 @@ bool WindowsCaptureDevice::start(void *startParam) {
679677
setError(CAPTUREDEVIDE_ERROR_START_FAILED, "Cannot start");
680678
if(m_pSource)
681679
m_pSource->Shutdown();
682-
SafeRelease(&m_pSource);
683-
SafeRelease(&pAttributes);
684-
SafeRelease(&pType);
685-
SafeRelease(&m_pReader);
680+
m_pSource = nullptr;
681+
m_pReader = nullptr;
686682
return false;
687683
}
688684

689-
SafeRelease(&pAttributes);
690-
SafeRelease(&pType);
691685
updateState(CAPTUREDEVIDE_STATE::STARTED);
692686
break;
693687
case CAPTUREDEVIDE_STATE::LOST:
@@ -751,13 +745,13 @@ std::vector<std::string> WindowsCaptureDevice::getDeviceList(bool forceEnum, int
751745

752746
if (SUCCEEDED(hr)) {
753747
// Get the size needed first
754-
dwMinSize = WideCharToMultiByte(CP_UTF8, NULL, pwstrName, -1, nullptr, 0, nullptr, FALSE);
748+
dwMinSize = WideCharToMultiByte(CP_UTF8, 0, pwstrName, -1, nullptr, 0, nullptr, FALSE);
755749
if (dwMinSize == 0)
756750
hr = E_FAIL;
757751
}
758752
if (SUCCEEDED(hr)) {
759753
cstrName = new char[dwMinSize];
760-
WideCharToMultiByte(CP_UTF8, NULL, pwstrName, -1, cstrName, dwMinSize, NULL, FALSE);
754+
WideCharToMultiByte(CP_UTF8, 0, pwstrName, -1, cstrName, dwMinSize, NULL, FALSE);
761755
strName = cstrName;
762756
delete[] cstrName;
763757

@@ -937,9 +931,9 @@ void WindowsCaptureDevice::messageHandler() {
937931
stop();
938932

939933
std::lock_guard<std::mutex> lock(sdMutex);
940-
SafeRelease(&m_pSource);
941-
SafeRelease(&m_pReader);
942-
delete m_pCallback;
934+
m_pSource = nullptr;
935+
m_pReader = nullptr;
936+
m_pCallback = nullptr;
943937
unRegisterCMPTMFApis();
944938

945939
std::unique_lock<std::mutex> lock2(paramMutex);
@@ -957,7 +951,7 @@ void WindowsCaptureDevice::messageHandler() {
957951

958952
HRESULT WindowsCaptureDevice::enumDevices() {
959953
HRESULT hr = S_OK;
960-
IMFAttributes *pAttributes = nullptr;
954+
ComPtr<IMFAttributes> pAttributes;
961955

962956
hr = MFCreateAttributes(&pAttributes, 1);
963957
if (SUCCEEDED(hr)) {
@@ -982,10 +976,9 @@ HRESULT WindowsCaptureDevice::enumDevices() {
982976
}
983977
}
984978
if (SUCCEEDED(hr)) {
985-
hr = EnumDeviceSources(pAttributes, &param.ppDevices, &param.count);
979+
hr = EnumDeviceSources(pAttributes.Get(), &param.ppDevices, &param.count);
986980
}
987981

988-
SafeRelease(&pAttributes);
989982
return hr;
990983
}
991984

Windows/CaptureDevice.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <vector>
2626
#include <queue>
2727
#include <thread>
28+
#include <wrl/client.h>
2829

2930
#include "Core/HLE/sceUsbMic.h"
3031

@@ -193,7 +194,7 @@ class WindowsCaptureDevice {
193194
std::vector<std::string> getDeviceList(bool forceEnum = false, int *pActuallCount = nullptr);
194195

195196
void setError(const CAPTUREDEVIDE_ERROR &newError, const std::string &newErrorMessage) { error = newError; errorMessage = newErrorMessage; }
196-
void setSelction(const UINT32 &selection) { param.selection = selection; }
197+
void setSelection(const UINT32 &selection) { param.selection = selection; }
197198
HRESULT setDeviceParam(IMFMediaType *pType);
198199

199200
bool isShutDown() const { return state == CAPTUREDEVIDE_STATE::SHUTDOWN; }
@@ -226,9 +227,9 @@ class WindowsCaptureDevice {
226227
bool isDeviceChanged = false;
227228

228229
// MF interface.
229-
ReaderCallback *m_pCallback = nullptr;
230-
IMFSourceReader *m_pReader = nullptr;
231-
IMFMediaSource *m_pSource = nullptr;
230+
Microsoft::WRL::ComPtr<ReaderCallback> m_pCallback;
231+
Microsoft::WRL::ComPtr<IMFSourceReader> m_pReader;
232+
Microsoft::WRL::ComPtr<IMFMediaSource> m_pSource;
232233

233234
// Message loop.
234235
std::mutex mutex;

Windows/DSoundStream.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,21 @@ bool DSoundAudioBackend::CreateBuffer() {
7272
dsBuffer_->SetCurrentPosition(0);
7373
return true;
7474
} else {
75-
dsBuffer_ = NULL;
75+
dsBuffer_ = nullptr;
7676
return false;
7777
}
7878
}
7979

8080
int DSoundAudioBackend::RunThread() {
8181
if (FAILED(DirectSoundCreate8(0, &ds_, 0))) {
82-
ds_ = NULL;
82+
ds_ = nullptr;
8383
threadData_ = 2;
8484
return 1;
8585
}
8686

8787
ds_->SetCooperativeLevel(window_, DSSCL_PRIORITY);
8888
if (!CreateBuffer()) {
89-
ds_->Release();
90-
ds_ = NULL;
89+
ds_ = nullptr;
9190
threadData_ = 2;
9291
return 1;
9392
}
@@ -135,8 +134,8 @@ int DSoundAudioBackend::RunThread() {
135134
}
136135
dsBuffer_->Stop();
137136

138-
dsBuffer_->Release();
139-
ds_->Release();
137+
dsBuffer_ = nullptr;
138+
ds_ = nullptr;
140139

141140
threadData_ = 2;
142141
return 0;

Windows/DSoundStream.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
#include "WindowsAudio.h"
66
#include <mmreg.h>
7-
8-
struct IDirectSound8;
9-
struct IDirectSoundBuffer;
7+
#include <dsound.h>
8+
#include <wrl/client.h>
109

1110
class DSoundAudioBackend : public WindowsAudioBackend {
1211
public:
@@ -29,8 +28,8 @@ class DSoundAudioBackend : public WindowsAudioBackend {
2928

3029
StreamCallback callback_;
3130

32-
IDirectSound8 *ds_ = nullptr;
33-
IDirectSoundBuffer *dsBuffer_ = nullptr;
31+
Microsoft::WRL::ComPtr<IDirectSound8> ds_;
32+
Microsoft::WRL::ComPtr<IDirectSoundBuffer> dsBuffer_;
3433

3534
int bufferSize_ = 0; // bytes
3635
int totalRenderedBytes_ = 0;

0 commit comments

Comments
 (0)