[videodb] remove unused seasons table from episode_view
[xbmc.git] / xbmc / rendering / gles / ScreenshotSurfaceGLES.cpp
blobd25da6cd65e1787a3d39bdfa873e37ba248e28f3
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "ScreenshotSurfaceGLES.h"
11 #include "ServiceBroker.h"
12 #include "guilib/GUIComponent.h"
13 #include "guilib/GUIWindowManager.h"
14 #include "utils/Screenshot.h"
15 #include "windowing/GraphicContext.h"
17 #include <memory>
18 #include <mutex>
19 #include <vector>
21 #include "system_gl.h"
23 void CScreenshotSurfaceGLES::Register()
25 CScreenShot::Register(CScreenshotSurfaceGLES::CreateSurface);
28 std::unique_ptr<IScreenshotSurface> CScreenshotSurfaceGLES::CreateSurface()
30 return std::make_unique<CScreenshotSurfaceGLES>();
33 bool CScreenshotSurfaceGLES::Capture()
35 CWinSystemBase* winsystem = CServiceBroker::GetWinSystem();
36 if (!winsystem)
37 return false;
39 CGUIComponent* gui = CServiceBroker::GetGUI();
40 if (!gui)
41 return false;
43 std::unique_lock<CCriticalSection> lock(winsystem->GetGfxContext());
44 gui->GetWindowManager().Render();
46 //get current viewport
47 GLint viewport[4];
48 glGetIntegerv(GL_VIEWPORT, viewport);
50 m_width = viewport[2] - viewport[0];
51 m_height = viewport[3] - viewport[1];
52 m_stride = m_width * 4;
53 std::vector<uint8_t> surface(m_stride * m_height);
55 //read pixels from the backbuffer
56 glReadPixels(viewport[0], viewport[1], viewport[2], viewport[3], GL_RGBA, GL_UNSIGNED_BYTE, static_cast<GLvoid*>(surface.data()));
58 //make a new buffer and copy the read image to it with the Y axis inverted
59 m_buffer = new unsigned char[m_stride * m_height];
60 for (int y = 0; y < m_height; y++)
62 // we need to save in BGRA order so XOR Swap RGBA -> BGRA
63 unsigned char* swap_pixels = surface.data() + (m_height - y - 1) * m_stride;
64 for (int x = 0; x < m_width; x++, swap_pixels += 4)
66 std::swap(swap_pixels[0], swap_pixels[2]);
69 memcpy(m_buffer + y * m_stride, surface.data() + (m_height - y - 1) * m_stride, m_stride);
72 return m_buffer != nullptr;