YSTest: ScreenBuffer.cpp 源文件

YSTest PreAlpha_b400_20130424 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
ScreenBuffer.cpp
浏览该文件的文档.
1 ﻿/*
2 Copyright by FrankHB 2013.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #include "ScreenBuffer.h"
29 #include "Helper/ShellHelper.h" // for YCL_DEBUG_PUTS, YSL_DEBUG_DECL_TIMER;
30
31 YSL_BEGIN
32
33 using namespace Drawing;
34
35 #if YCL_HOSTED
36 YSL_BEGIN_NAMESPACE(Host)
37 # if YCL_MINGW32
38 ScreenBuffer::ScreenBuffer(const Size& s)
39 : size(s), hBitmap([this]{
40 ::BITMAPINFO bmi{{sizeof(::BITMAPINFOHEADER), size.Width,
41 -size.Height - 1, 1, 32, BI_RGB,
42 sizeof(PixelType) * size.Width * size.Height, 0, 0, 0, 0}, {}};
43
44 return ::CreateDIBSection(nullptr, &bmi, DIB_RGB_COLORS,
45 &reinterpret_cast<void*&>(pBuffer), nullptr, 0);
46 }())
47 {}
48 ScreenBuffer::ScreenBuffer(ScreenBuffer&& sbuf) ynothrow
49 : size(sbuf.size), hBitmap(sbuf.hBitmap)
50 {
51 sbuf.hBitmap = nullptr;
52 }
53 ScreenBuffer::~ScreenBuffer()
54 {
55 ::DeleteObject(hBitmap);
56 }
57
58 void
59 ScreenBuffer::UpdateFrom(BitmapPtr buf) ynothrow
60 {
61 std::copy_n(buf, size.Width * size.Height, GetBufferPtr());
62 }
63
64
65 void
66 ScreenRegionBuffer::UpdateFrom(BitmapPtr buf) ynothrow
67 {
68 YSL_DEBUG_DECL_TIMER(tmr, "ScreenRegionBuffer::UpdateFrom")
69 std::lock_guard<std::mutex> lck(mtx);
70
71 ScreenBuffer::UpdateFrom(buf);
72 }
73
74 void
75 ScreenRegionBuffer::UpdateTo(::HWND h_wnd, const Point& pt) ynothrow
76 {
77 YSL_DEBUG_DECL_TIMER(tmr, "ScreenRegionBuffer::UpdateTo")
78 std::lock_guard<std::mutex> lck(mtx);
79 GSurface<> sf(h_wnd);
80
81 // std::this_thread::sleep_for(std::chrono::milliseconds(20));
82 sf.Update(*this, pt);
83 }
84
85
86 void
87 WindowMemorySurface::Update(ScreenBuffer& sbuf, const Point& pt) ynothrow
88 {
89 const auto h_old(::SelectObject(h_mem_dc, sbuf.GetNativeHandle()));
90 const auto& s(sbuf.GetSize());
91
92 // NOTE: Unlocked intentionally for performance.
93 ::BitBlt(h_owner_dc, pt.X, pt.Y, s.Width, s.Height, h_mem_dc, 0, 0,
94 SRCCOPY);
95 ::SelectObject(h_mem_dc, h_old);
96 }
97 # endif
98 YSL_END_NAMESPACE(Host)
99 #endif
100
101 YSL_END
102