Mercurial > hg > orthanc-stone
comparison Framework/Viewport/SdlViewport.cpp @ 905:88bf49aebc13
introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Wed, 17 Jul 2019 16:56:53 +0200 |
parents | 0c5201499af8 |
children | 722ee73e6ba2 |
comparison
equal
deleted
inserted
replaced
904:ecdb2ceaa925 | 905:88bf49aebc13 |
---|---|
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 static const uint32_t rmask = 0x00ff0000; | |
60 static const uint32_t gmask = 0x0000ff00; | |
61 static const uint32_t bmask = 0x000000ff; | |
62 | |
63 sdlSurface_ = SDL_CreateRGBSurfaceFrom((void*)(compositor_.GetCanvas().GetBuffer()), width, height, 32, | |
64 compositor_.GetCanvas().GetPitch(), rmask, gmask, bmask, 0); | |
65 if (!sdlSurface_) | |
66 { | |
67 LOG(ERROR) << "Cannot create a SDL surface from a Cairo surface"; | |
68 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
69 } | |
70 } | |
71 | |
72 | |
73 SdlCairoViewport::~SdlCairoViewport() | |
74 { | |
75 if (sdlSurface_) | |
76 { | |
77 SDL_FreeSurface(sdlSurface_); | |
78 } | |
79 } | |
80 | |
81 // void SdlCairoViewport::SetSize(unsigned int width, | |
82 // unsigned int height) | |
83 // { | |
84 // if (cairoSurface_.get() == NULL || | |
85 // cairoSurface_->GetWidth() != width || | |
86 // cairoSurface_->GetHeight() != height) | |
87 // { | |
88 // cairoSurface_.reset(new CairoSurface(width, height, false /* no alpha */)); | |
89 | |
90 // // TODO Big endian? | |
91 // static const uint32_t rmask = 0x00ff0000; | |
92 // static const uint32_t gmask = 0x0000ff00; | |
93 // static const uint32_t bmask = 0x000000ff; | |
94 | |
95 // if (sdlSurface_) | |
96 // { | |
97 // SDL_FreeSurface(sdlSurface_); | |
98 // } | |
99 | |
100 // sdlSurface_ = SDL_CreateRGBSurfaceFrom(cairoSurface_->GetBuffer(), width, height, 32, | |
101 // cairoSurface_->GetPitch(), rmask, gmask, bmask, 0); | |
102 // if (!sdlSurface_) | |
103 // { | |
104 // LOG(ERROR) << "Cannot create a SDL surface from a Cairo surface"; | |
105 // throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
106 // } | |
107 // } | |
108 // } | |
109 | |
110 | |
111 void SdlCairoViewport::Refresh() | |
112 { | |
113 GetCompositor().Refresh(); | |
114 window_.Render(sdlSurface_); | |
115 } | |
116 | |
117 | |
118 // void SdlCairoViewport::Render() | |
119 // { | |
120 // Orthanc::ImageAccessor target; | |
121 // compositor_.GetCanvas() cairoSurface_->GetWriteableAccessor(target); | |
122 | |
123 // if (viewport.Render(target)) | |
124 // { | |
125 // window_.Render(sdlSurface_); | |
126 // } | |
127 // } | |
128 | |
129 | |
49 } | 130 } |