-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageRenderer.h
69 lines (57 loc) · 2.25 KB
/
ImageRenderer.h
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
//------------------------------------------------------------------------------
// <copyright file="ImageRenderer.h" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
// Manages the drawing of image data
#pragma once
#include <d2d1.h>
class ImageRenderer
{
public:
/// <summary>
/// Constructor
/// </summary>
ImageRenderer();
/// <summary>
/// Destructor
/// </summary>
virtual ~ImageRenderer();
/// <summary>
/// Set the window to draw to as well as the video format
/// Implied bits per pixel is 32
/// </summary>
/// <param name="hWnd">window to draw to</param>
/// <param name="pD2DFactory">already created D2D factory object</param>
/// <param name="sourceWidth">width (in pixels) of image data to be drawn</param>
/// <param name="sourceHeight">height (in pixels) of image data to be drawn</param>
/// <param name="sourceStride">length (in bytes) of a single scanline</param>
/// <returns>indicates success or failure</returns>
HRESULT Initialize(HWND hwnd, ID2D1Factory* pD2DFactory, int sourceWidth, int sourceHeight, int sourceStride);
/// <summary>
/// Draws a 32 bit per pixel image of previously specified width, height, and stride to the associated hwnd
/// </summary>
/// <param name="pImage">image data in RGBX format</param>
/// <param name="cbImage">size of image data in bytes</param>
/// <returns>indicates success or failure</returns>
HRESULT Draw(BYTE* pImage, unsigned long cbImage);
private:
HWND m_hWnd;
// Format information
UINT m_sourceHeight;
UINT m_sourceWidth;
LONG m_sourceStride;
// Direct2D
ID2D1Factory* m_pD2DFactory;
ID2D1HwndRenderTarget* m_pRenderTarget;
ID2D1Bitmap* m_pBitmap;
/// <summary>
/// Ensure necessary Direct2d resources are created
/// </summary>
/// <returns>indicates success or failure</returns>
HRESULT EnsureResources();
/// <summary>
/// Dispose of Direct2d resources
/// </summary>
void DiscardResources();
};