mirror of https://github.com/axmolengine/axmol.git
Merge pull request #7265 from visiblelight/beta_test
Fix the crash when capturing screen on WP8
This commit is contained in:
commit
6654bf1129
|
@ -72,7 +72,16 @@ void onCaptureScreen(const std::function<void(bool, const std::string&)>& afterC
|
||||||
}
|
}
|
||||||
|
|
||||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||||
|
|
||||||
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
|
||||||
|
// The frame buffer is always created with portrait orientation on WP8.
|
||||||
|
// So if the current device orientation is landscape, we need to rotate the frame buffer.
|
||||||
|
auto renderTargetSize = glView->getRenerTargetSize();
|
||||||
|
CCASSERT(width * height == static_cast<int>(renderTargetSize.width * renderTargetSize.height), "The frame size is not matched");
|
||||||
|
glReadPixels(0, 0, (int)renderTargetSize.width, (int)renderTargetSize.height, GL_RGBA, GL_UNSIGNED_BYTE, buffer.get());
|
||||||
|
#else
|
||||||
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer.get());
|
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer.get());
|
||||||
|
#endif
|
||||||
|
|
||||||
std::shared_ptr<GLubyte> flippedBuffer(new GLubyte[width * height * 4], [](GLubyte* p) { CC_SAFE_DELETE_ARRAY(p); });
|
std::shared_ptr<GLubyte> flippedBuffer(new GLubyte[width * height * 4], [](GLubyte* p) { CC_SAFE_DELETE_ARRAY(p); });
|
||||||
if (!flippedBuffer)
|
if (!flippedBuffer)
|
||||||
|
@ -80,10 +89,32 @@ void onCaptureScreen(const std::function<void(bool, const std::string&)>& afterC
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
|
||||||
|
if (width == static_cast<int>(renderTargetSize.width))
|
||||||
|
{
|
||||||
|
// The current device orientation is portrait.
|
||||||
|
for (int row = 0; row < height; ++row)
|
||||||
|
{
|
||||||
|
memcpy(flippedBuffer.get() + (height - row - 1) * width * 4, buffer.get() + row * width * 4, width * 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// The current device orientation is landscape.
|
||||||
|
for (int row = 0; row < width; ++row)
|
||||||
|
{
|
||||||
|
for (int col = 0; col < height; ++col)
|
||||||
|
{
|
||||||
|
*(int*)(flippedBuffer.get() + (height - col - 1) * width * 4 + row * 4) = *(int*)(buffer.get() + row * height * 4 + col * 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
for (int row = 0; row < height; ++row)
|
for (int row = 0; row < height; ++row)
|
||||||
{
|
{
|
||||||
memcpy(flippedBuffer.get() + (height - row - 1) * width * 4, buffer.get() + row * width * 4, width * 4);
|
memcpy(flippedBuffer.get() + (height - row - 1) * width * 4, buffer.get() + row * width * 4, width * 4);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
std::shared_ptr<Image> image(new Image);
|
std::shared_ptr<Image> image(new Image);
|
||||||
if (image)
|
if (image)
|
||||||
|
|
|
@ -65,6 +65,7 @@ public:
|
||||||
const Mat4& getReverseOrientationMatrix () const {return m_reverseOrientationMatrix;};
|
const Mat4& getReverseOrientationMatrix () const {return m_reverseOrientationMatrix;};
|
||||||
|
|
||||||
Windows::Graphics::Display::DisplayOrientations getDeviceOrientation() {return m_orientation;};
|
Windows::Graphics::Display::DisplayOrientations getDeviceOrientation() {return m_orientation;};
|
||||||
|
Size getRenerTargetSize() const { return Size(m_width, m_height); }
|
||||||
|
|
||||||
virtual void setIMEKeyboardState(bool bOpen);
|
virtual void setIMEKeyboardState(bool bOpen);
|
||||||
void ShowKeyboard(Windows::Foundation::Rect r);
|
void ShowKeyboard(Windows::Foundation::Rect r);
|
||||||
|
|
Loading…
Reference in New Issue