Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
smasherprog committed Aug 1, 2021
1 parent eb279a6 commit 80faf8e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 30 deletions.
7 changes: 7 additions & 0 deletions include/internal/SCCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ namespace Screen_Capture {
bool FirstRun = true;
};

class BaseMouseProcessor : public BaseFrameProcessor {
public:
std::unique_ptr<unsigned char[]> NewImageBuffer;
int Last_x = 0;
int Last_y = 0;
};

enum DUPL_RETURN { DUPL_RETURN_SUCCESS = 0, DUPL_RETURN_ERROR_EXPECTED = 1, DUPL_RETURN_ERROR_UNEXPECTED = 2 };
Monitor CreateMonitor(int index, int id, int h, int w, int ox, int oy, const std::string &n, float scale);
Monitor CreateMonitor(int index, int id, int adapter, int h, int w, int ox, int oy, const std::string &n, float scale);
Expand Down
5 changes: 1 addition & 4 deletions include/ios/NSMouseProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
namespace SL {
namespace Screen_Capture {

class NSMouseProcessor: public BaseFrameProcessor {
int Last_x =0;
int Last_y =0;
std::unique_ptr<unsigned char[]> OldImageBuffer;
class NSMouseProcessor : public BaseMouseProcessor {
public:
const int MaxCursurorSize=32;
DUPL_RETURN Init(std::shared_ptr<Thread_Data> data);
Expand Down
9 changes: 3 additions & 6 deletions include/linux/X11MouseProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
namespace SL {
namespace Screen_Capture {

class X11MouseProcessor: public BaseFrameProcessor {
Display* SelectedDisplay=nullptr;
std::unique_ptr<unsigned char[]> OldImageBuffer;
XID RootWindow;
int Last_x = 0;
int Last_y =0;
class X11MouseProcessor : public BaseMouseProcessor {
Display* SelectedDisplay=nullptr;
XID RootWindow;

public:
const int MaxCursurorSize =32;
Expand Down
11 changes: 3 additions & 8 deletions include/windows/GDIMouseProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,10 @@
namespace SL {
namespace Screen_Capture {

class GDIMouseProcessor : public BaseFrameProcessor {

class GDIMouseProcessor : public BaseMouseProcessor {
HDCWrapper MonitorDC;
HDCWrapper CaptureDC;
std::shared_ptr<Thread_Data> Data;
std::unique_ptr<unsigned char[]> NewImageBuffer;
int Last_x = 0;
int Last_y = 0;

HDCWrapper CaptureDC;

public:

const int MaxCursurorSize = 32;
Expand Down
2 changes: 1 addition & 1 deletion releasenotes.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Setting up build currently
Cleaned up mouse capture code
12 changes: 6 additions & 6 deletions src_cpp/ios/NSMouseProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ namespace Screen_Capture {
auto rawdatas = CGDataProviderCopyData(prov);
auto buf = CFDataGetBytePtr(rawdatas);
auto datalen = CFDataGetLength(rawdatas);
if (datalen > ImageBufferSize || !OldImageBuffer) {
if (datalen > ImageBufferSize || !ImageBuffer || !NewImageBuffer) {
NewImageBuffer = std::make_unique<unsigned char[]>(datalen);
ImageBuffer = std::make_unique<unsigned char[]>(datalen);
OldImageBuffer = std::make_unique<unsigned char[]>(datalen);
}

memcpy(ImageBuffer.get(), buf, datalen);
memcpy(NewImageBuffer.get(), buf, datalen);
CFRelease(rawdatas);

// this is not needed. It is freed when the image is released
Expand All @@ -54,7 +54,7 @@ namespace Screen_Capture {
imgrect.left = imgrect.top = 0;
imgrect.right = width;
imgrect.bottom = height;
auto wholeimgfirst = CreateImage(imgrect, bytesperrow, reinterpret_cast<const ImageBGRA *>(ImageBuffer.get()));
auto wholeimgfirst = CreateImage(imgrect, bytesperrow, reinterpret_cast<const ImageBGRA *>(NewImageBuffer.get()));

auto lastx = static_cast<int>(loc.x);
auto lasty = static_cast<int>(loc.y);
Expand All @@ -65,14 +65,14 @@ namespace Screen_Capture {

// if the mouse image is different, send the new image and swap the data

if (memcmp(ImageBuffer.get(), OldImageBuffer.get(), datalen) != 0) {
if (memcmp(NewImageBuffer.get(), ImageBuffer.get(), datalen) != 0) {
if (Data->ScreenCaptureData.OnMouseChanged) {
Data->ScreenCaptureData.OnMouseChanged(&wholeimgfirst, mousepoint);
}
if (Data->WindowCaptureData.OnMouseChanged) {
Data->WindowCaptureData.OnMouseChanged(&wholeimgfirst, mousepoint);
}
std::swap(ImageBuffer, OldImageBuffer);
std::swap(NewImageBuffer, OldImageBuffer);
}
else if (Last_x != lastx || Last_y != lasty) {
if (Data->ScreenCaptureData.OnMouseChanged) {
Expand Down
10 changes: 5 additions & 5 deletions src_cpp/linux/X11MouseProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ namespace Screen_Capture {
imgrect.right = img->width;
imgrect.bottom = img->height;
auto newsize = sizeof(ImageBGRA) * imgrect.right * imgrect.bottom;
if (static_cast<int>(newsize) > ImageBufferSize || !OldImageBuffer) {
ImageBuffer = std::make_unique<unsigned char[]>(sizeof(ImageBGRA) * imgrect.right * imgrect.bottom);
OldImageBuffer = std::make_unique<unsigned char[]>(sizeof(ImageBGRA) * imgrect.right * imgrect.bottom);
if (static_cast<int>(newsize) > ImageBufferSize || !ImageBuffer || !NewImageBuffer) {
NewImageBuffer = std::make_unique<unsigned char[]>(newsize);
ImageBuffer = std::make_unique<unsigned char[]>(newsize);
}

memcpy(ImageBuffer.get(), img->pixels, newsize);
Expand All @@ -69,14 +69,14 @@ namespace Screen_Capture {

auto wholeimg = CreateImage(imgrect, imgrect.right * sizeof(ImageBGRA), reinterpret_cast<const ImageBGRA *>(ImageBuffer.get()));
// if the mouse image is different, send the new image and swap the data
if (memcmp(ImageBuffer.get(), OldImageBuffer.get(), newsize) != 0) {
if (memcmp(ImageBuffer.get(), NewImageBuffer.get(), newsize) != 0) {
if (Data->ScreenCaptureData.OnMouseChanged) {
Data->ScreenCaptureData.OnMouseChanged(&wholeimg, mousepoint);
}
if (Data->WindowCaptureData.OnMouseChanged) {
Data->WindowCaptureData.OnMouseChanged(&wholeimg, mousepoint);
}
std::swap(ImageBuffer, OldImageBuffer);
std::swap(ImageBuffer, NewImageBuffer);
}
else if (Last_x != x || Last_y != y) {
if (Data->ScreenCaptureData.OnMouseChanged) {
Expand Down

0 comments on commit 80faf8e

Please sign in to comment.