comparison Framework/Viewport/SdlViewport.cpp @ 911:64e5f3ff6360 am-dev

Merge
author Alain Mazy <alain@mazy.be>
date Thu, 18 Jul 2019 10:50:59 +0200
parents 7a7e4e1f558f
children 1091b2adeb5a
comparison
equal deleted inserted replaced
903:ef6e425dc79f 911:64e5f3ff6360
24 24
25 #include <boost/make_shared.hpp> 25 #include <boost/make_shared.hpp>
26 26
27 namespace OrthancStone 27 namespace OrthancStone
28 { 28 {
29 SdlViewport::SdlViewport(const char* title, 29 SdlOpenGLViewport::SdlOpenGLViewport(const char* title,
30 unsigned int width, 30 unsigned int width,
31 unsigned int height, 31 unsigned int height,
32 bool allowDpiScaling) : 32 bool allowDpiScaling) :
33 ViewportBase(title), 33 SdlViewport(title),
34 context_(title, width, height, allowDpiScaling), 34 context_(title, width, height, allowDpiScaling),
35 compositor_(context_, GetScene()) 35 compositor_(context_, GetScene())
36 { 36 {
37 } 37 }
38 38
39 SdlViewport::SdlViewport(const char* title, 39 SdlOpenGLViewport::SdlOpenGLViewport(const char* title,
40 unsigned int width, 40 unsigned int width,
41 unsigned int height, 41 unsigned int height,
42 boost::shared_ptr<Scene2D>& scene, 42 boost::shared_ptr<Scene2D>& scene,
43 bool allowDpiScaling) : 43 bool allowDpiScaling) :
44 ViewportBase(title, scene), 44 SdlViewport(title, scene),
45 context_(title, width, height, allowDpiScaling), 45 context_(title, width, height, allowDpiScaling),
46 compositor_(context_, GetScene()) 46 compositor_(context_, GetScene())
47 { 47 {
48 } 48 }
49
50
51 SdlCairoViewport::SdlCairoViewport(const char* title,
52 unsigned int width,
53 unsigned int height,
54 bool allowDpiScaling) :
55 SdlViewport(title),
56 window_(title, width, height, false /* enable OpenGL */, allowDpiScaling),
57 compositor_(GetScene(), width, height)
58 {
59 UpdateSdlSurfaceSize(width, height);
60 }
61
62
63 SdlCairoViewport::~SdlCairoViewport()
64 {
65 if (sdlSurface_)
66 {
67 SDL_FreeSurface(sdlSurface_);
68 }
69 }
70
71
72 void SdlCairoViewport::Refresh()
73 {
74 GetCompositor().Refresh();
75 window_.Render(sdlSurface_);
76 }
77
78 void SdlCairoViewport::UpdateSize(unsigned int width,
79 unsigned int height)
80 {
81 compositor_.UpdateSize(width, height);
82 UpdateSdlSurfaceSize(width, height);
83 Refresh();
84 }
85
86
87 void SdlCairoViewport::UpdateSdlSurfaceSize(unsigned int width,
88 unsigned int height)
89 {
90 static const uint32_t rmask = 0x00ff0000;
91 static const uint32_t gmask = 0x0000ff00;
92 static const uint32_t bmask = 0x000000ff;
93
94 sdlSurface_ = SDL_CreateRGBSurfaceFrom((void*)(compositor_.GetCanvas().GetBuffer()), width, height, 32,
95 compositor_.GetCanvas().GetPitch(), rmask, gmask, bmask, 0);
96 if (!sdlSurface_)
97 {
98 LOG(ERROR) << "Cannot create a SDL surface from a Cairo surface";
99 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
100 }
101 }
102
49 } 103 }