OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file implements the NativeViewGLContext and PbufferGLContext classes. | 5 // This file implements the NativeViewGLContext and PbufferGLContext classes. |
6 | 6 |
7 #include "app/gfx/gl/gl_context.h" | 7 #include "app/gfx/gl/gl_context.h" |
8 | 8 |
9 #include <GL/osmesa.h> | 9 #include <GL/osmesa.h> |
10 | 10 |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 gfx::Size size = osmesa_context_.GetSize(); | 483 gfx::Size size = osmesa_context_.GetSize(); |
484 | 484 |
485 // Note: negating the height below causes GDI to treat the bitmap data as row | 485 // Note: negating the height below causes GDI to treat the bitmap data as row |
486 // 0 being at the top. | 486 // 0 being at the top. |
487 BITMAPV4HEADER info = { sizeof(BITMAPV4HEADER) }; | 487 BITMAPV4HEADER info = { sizeof(BITMAPV4HEADER) }; |
488 info.bV4Width = size.width(); | 488 info.bV4Width = size.width(); |
489 info.bV4Height = -size.height(); | 489 info.bV4Height = -size.height(); |
490 info.bV4Planes = 1; | 490 info.bV4Planes = 1; |
491 info.bV4BitCount = 32; | 491 info.bV4BitCount = 32; |
492 info.bV4V4Compression = BI_BITFIELDS; | 492 info.bV4V4Compression = BI_BITFIELDS; |
493 info.bV4RedMask = 0xFF000000; | 493 info.bV4RedMask = 0x000000FF; |
494 info.bV4GreenMask = 0x00FF0000; | 494 info.bV4GreenMask = 0x0000FF00; |
495 info.bV4BlueMask = 0x0000FF00; | 495 info.bV4BlueMask = 0x00FF0000; |
496 info.bV4AlphaMask = 0x000000FF; | 496 info.bV4AlphaMask = 0xFF000000; |
497 | 497 |
498 // Copy the back buffer to the window's device context. | 498 // Copy the back buffer to the window's device context. |
499 return StretchDIBits(device_context_, | 499 return StretchDIBits(device_context_, |
500 0, 0, size.width(), size.height(), | 500 0, 0, size.width(), size.height(), |
501 0, 0, size.width(), size.height(), | 501 0, 0, size.width(), size.height(), |
502 osmesa_context_.buffer(), | 502 osmesa_context_.buffer(), |
503 reinterpret_cast<BITMAPINFO*>(&info), | 503 reinterpret_cast<BITMAPINFO*>(&info), |
504 DIB_RGB_COLORS, | 504 DIB_RGB_COLORS, |
505 SRCCOPY) != 0; | 505 SRCCOPY) != 0; |
506 } | 506 } |
507 | 507 |
508 gfx::Size OSMesaViewGLContext::GetSize() { | 508 gfx::Size OSMesaViewGLContext::GetSize() { |
509 return osmesa_context_.GetSize(); | 509 return osmesa_context_.GetSize(); |
510 } | 510 } |
511 | 511 |
512 void* OSMesaViewGLContext::GetHandle() { | 512 void* OSMesaViewGLContext::GetHandle() { |
513 return osmesa_context_.GetHandle(); | 513 return osmesa_context_.GetHandle(); |
514 } | 514 } |
515 | 515 |
516 void OSMesaViewGLContext::SetSwapInterval(int interval) { | 516 void OSMesaViewGLContext::SetSwapInterval(int interval) { |
517 DCHECK(IsCurrent()); | 517 DCHECK(IsCurrent()); |
518 // Fail silently. It is legitimate to set the swap interval on a view context | 518 // Fail silently. It is legitimate to set the swap interval on a view context |
519 // but GDI does not have those semantics. | 519 // but GDI does not have those semantics. |
520 } | 520 } |
521 | 521 |
522 void OSMesaViewGLContext::UpdateSize() { | 522 void OSMesaViewGLContext::UpdateSize() { |
523 // Change back buffer size to that of window. | 523 // Change back buffer size to that of window. |
524 RECT rect; | 524 RECT rect; |
525 GetClientRect(window_, &rect); | 525 if (!GetClientRect(window_, &rect)) |
| 526 return; |
| 527 |
526 gfx::Size window_size = gfx::Size( | 528 gfx::Size window_size = gfx::Size( |
527 std::max(1, static_cast<int>(rect.right - rect.left)), | 529 std::max(1, static_cast<int>(rect.right - rect.left)), |
528 std::max(1, static_cast<int>(rect.bottom - rect.top))); | 530 std::max(1, static_cast<int>(rect.bottom - rect.top))); |
529 osmesa_context_.Resize(window_size); | 531 osmesa_context_.Resize(window_size); |
530 } | 532 } |
531 | 533 |
532 GLContext* GLContext::CreateViewGLContext(gfx::PluginWindowHandle window, | 534 GLContext* GLContext::CreateViewGLContext(gfx::PluginWindowHandle window, |
533 bool multisampled) { | 535 bool multisampled) { |
534 switch (GetGLImplementation()) { | 536 switch (GetGLImplementation()) { |
535 case kGLImplementationOSMesaGL: { | 537 case kGLImplementationOSMesaGL: { |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 } | 720 } |
719 case kGLImplementationMockGL: | 721 case kGLImplementationMockGL: |
720 return new StubGLContext; | 722 return new StubGLContext; |
721 default: | 723 default: |
722 NOTREACHED(); | 724 NOTREACHED(); |
723 return NULL; | 725 return NULL; |
724 } | 726 } |
725 } | 727 } |
726 | 728 |
727 } // namespace gfx | 729 } // namespace gfx |
OLD | NEW |