Merge pull request #7265 from visiblelight/beta_test

Fix the crash when capturing screen on WP8
This commit is contained in:
minggo 2014-07-01 16:19:45 +08:00
commit 6654bf1129
2 changed files with 34 additions and 2 deletions

View File

@ -72,19 +72,50 @@ void onCaptureScreen(const std::function<void(bool, const std::string&)>& afterC
}
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());
#endif
std::shared_ptr<GLubyte> flippedBuffer(new GLubyte[width * height * 4], [](GLubyte* p) { CC_SAFE_DELETE_ARRAY(p); });
if (!flippedBuffer)
{
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)
{
memcpy(flippedBuffer.get() + (height - row - 1) * width * 4, buffer.get() + row * width * 4, width * 4);
}
#endif
std::shared_ptr<Image> image(new Image);
if (image)
{

View File

@ -65,6 +65,7 @@ public:
const Mat4& getReverseOrientationMatrix () const {return m_reverseOrientationMatrix;};
Windows::Graphics::Display::DisplayOrientations getDeviceOrientation() {return m_orientation;};
Size getRenerTargetSize() const { return Size(m_width, m_height); }
virtual void setIMEKeyboardState(bool bOpen);
void ShowKeyboard(Windows::Foundation::Rect r);