OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include <vector> | 5 #include <vector> |
6 #include <string> | 6 #include <string> |
7 #include <map> | 7 #include <map> |
8 #include <build/build_config.h> | 8 #include <build/build_config.h> |
9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
10 #define GLES2_GPU_SERVICE 1 | 10 #define GLES2_GPU_SERVICE 1 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 case GLErrorBit::kInvalidFrameBufferOperation: | 133 case GLErrorBit::kInvalidFrameBufferOperation: |
134 return GL_INVALID_FRAMEBUFFER_OPERATION; | 134 return GL_INVALID_FRAMEBUFFER_OPERATION; |
135 default: | 135 default: |
136 DCHECK(false); | 136 DCHECK(false); |
137 return GL_NO_ERROR; | 137 return GL_NO_ERROR; |
138 } | 138 } |
139 } | 139 } |
140 | 140 |
141 } // anonymous namespace. | 141 } // anonymous namespace. |
142 | 142 |
143 #if defined(OS_LINUX) | 143 #if defined(UNIT_TEST) |
| 144 GLES2Decoder::GLES2Decoder() { |
| 145 #elif defined(OS_LINUX) |
144 GLES2Decoder::GLES2Decoder() | 146 GLES2Decoder::GLES2Decoder() |
145 : debug_(false), | 147 : debug_(false), |
146 window_(NULL) { | 148 window_(NULL) { |
147 #elif defined(OS_WIN) | 149 #elif defined(OS_WIN) |
148 GLES2Decoder::GLES2Decoder() | 150 GLES2Decoder::GLES2Decoder() |
149 : debug_(false), | 151 : debug_(false), |
150 hwnd_(NULL) { | 152 hwnd_(NULL) { |
151 #else | 153 #else |
152 GLES2Decoder::GLES2Decoder() { | 154 GLES2Decoder::GLES2Decoder() { |
153 #endif | 155 #endif |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 BufferInfoMap buffer_infos_; | 512 BufferInfoMap buffer_infos_; |
511 | 513 |
512 // Info for each "successfully linked" program by service side program Id. | 514 // Info for each "successfully linked" program by service side program Id. |
513 // TODO(gman): Choose a faster container. | 515 // TODO(gman): Choose a faster container. |
514 typedef std::map<GLuint, ProgramInfo> ProgramInfoMap; | 516 typedef std::map<GLuint, ProgramInfo> ProgramInfoMap; |
515 ProgramInfoMap program_infos_; | 517 ProgramInfoMap program_infos_; |
516 | 518 |
517 // The program in current use through glUseProgram. | 519 // The program in current use through glUseProgram. |
518 ProgramInfo* current_program_info_; | 520 ProgramInfo* current_program_info_; |
519 | 521 |
520 #if defined(OS_WIN) | 522 #if defined(UNIT_TEST) |
| 523 #elif defined(OS_WIN) |
521 HDC device_context_; | 524 HDC device_context_; |
522 HGLRC gl_context_; | 525 HGLRC gl_context_; |
523 #endif | 526 #endif |
524 | 527 |
525 bool anti_aliased_; | 528 bool anti_aliased_; |
526 | 529 |
527 DISALLOW_COPY_AND_ASSIGN(GLES2DecoderImpl); | 530 DISALLOW_COPY_AND_ASSIGN(GLES2DecoderImpl); |
528 }; | 531 }; |
529 | 532 |
530 GLES2Decoder* GLES2Decoder::Create() { | 533 GLES2Decoder* GLES2Decoder::Create() { |
531 return new GLES2DecoderImpl(); | 534 return new GLES2DecoderImpl(); |
532 } | 535 } |
533 | 536 |
534 GLES2DecoderImpl::GLES2DecoderImpl() | 537 GLES2DecoderImpl::GLES2DecoderImpl() |
535 : GLES2Decoder(), | 538 : GLES2Decoder(), |
536 error_bits_(0), | 539 error_bits_(0), |
537 util_(0), // TODO(gman): Set to actual num compress texture formats. | 540 util_(0), // TODO(gman): Set to actual num compress texture formats. |
538 pack_alignment_(4), | 541 pack_alignment_(4), |
539 unpack_alignment_(4), | 542 unpack_alignment_(4), |
540 bound_array_buffer_(0), | 543 bound_array_buffer_(0), |
541 bound_element_array_buffer_(0), | 544 bound_element_array_buffer_(0), |
542 max_vertex_attribs_(0), | 545 max_vertex_attribs_(0), |
543 current_program_info_(NULL), | 546 current_program_info_(NULL), |
544 #ifdef OS_WIN | 547 #if defined(UNIT_TEST) |
| 548 #elif defined(OS_WIN) |
545 device_context_(NULL), | 549 device_context_(NULL), |
546 gl_context_(NULL), | 550 gl_context_(NULL), |
547 #endif | 551 #endif |
548 anti_aliased_(false) { | 552 anti_aliased_(false) { |
549 } | 553 } |
550 | 554 |
551 bool GLES2DecoderImpl::Initialize() { | 555 bool GLES2DecoderImpl::Initialize() { |
552 if (!InitPlatformSpecific()) | 556 if (!InitPlatformSpecific()) |
553 return false; | 557 return false; |
554 if (!InitGlew()) | 558 if (!InitGlew()) |
555 return false; | 559 return false; |
556 CHECK_GL_ERROR(); | 560 CHECK_GL_ERROR(); |
557 | 561 |
558 // Lookup GL things we need to know. | 562 // Lookup GL things we need to know. |
559 GLint value; | 563 GLint value; |
560 glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &value); | 564 glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &value); |
561 max_vertex_attribs_ = value; | 565 max_vertex_attribs_ = value; |
562 | 566 |
563 DCHECK_GE(max_vertex_attribs_, 8u); | 567 DCHECK_GE(max_vertex_attribs_, 8u); |
564 | 568 |
565 vertex_attrib_infos_.reset(new VertexAttribInfo[max_vertex_attribs_]); | 569 vertex_attrib_infos_.reset(new VertexAttribInfo[max_vertex_attribs_]); |
566 memset(vertex_attrib_infos_.get(), 0, | 570 memset(vertex_attrib_infos_.get(), 0, |
567 sizeof(vertex_attrib_infos_[0]) * max_vertex_attribs_); | 571 sizeof(vertex_attrib_infos_[0]) * max_vertex_attribs_); |
568 | 572 |
569 //glBindFramebuffer(0, 0); | 573 //glBindFramebuffer(0, 0); |
570 return true; | 574 return true; |
571 } | 575 } |
572 | 576 |
573 #if defined(OS_WIN) | |
574 namespace { | 577 namespace { |
575 | 578 |
| 579 #if defined(UNIT_TEST) |
| 580 #elif defined(OS_WIN) |
| 581 |
576 const PIXELFORMATDESCRIPTOR kPixelFormatDescriptor = { | 582 const PIXELFORMATDESCRIPTOR kPixelFormatDescriptor = { |
577 sizeof(kPixelFormatDescriptor), // Size of structure. | 583 sizeof(kPixelFormatDescriptor), // Size of structure. |
578 1, // Default version. | 584 1, // Default version. |
579 PFD_DRAW_TO_WINDOW | // Window drawing support. | 585 PFD_DRAW_TO_WINDOW | // Window drawing support. |
580 PFD_SUPPORT_OPENGL | // OpenGL support. | 586 PFD_SUPPORT_OPENGL | // OpenGL support. |
581 PFD_DOUBLEBUFFER, // Double buffering support (not stereo). | 587 PFD_DOUBLEBUFFER, // Double buffering support (not stereo). |
582 PFD_TYPE_RGBA, // RGBA color mode (not indexed). | 588 PFD_TYPE_RGBA, // RGBA color mode (not indexed). |
583 24, // 24 bit color mode. | 589 24, // 24 bit color mode. |
584 0, 0, 0, 0, 0, 0, // Don't set RGB bits & shifts. | 590 0, 0, 0, 0, 0, 0, // Don't set RGB bits & shifts. |
585 8, 0, // 8 bit alpha | 591 8, 0, // 8 bit alpha |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 | 738 |
733 ::wglMakeCurrent(intermediate_dc, NULL); | 739 ::wglMakeCurrent(intermediate_dc, NULL); |
734 ::wglDeleteContext(gl_context); | 740 ::wglDeleteContext(gl_context); |
735 ::ReleaseDC(intermediate_window, intermediate_dc); | 741 ::ReleaseDC(intermediate_window, intermediate_dc); |
736 ::DestroyWindow(intermediate_window); | 742 ::DestroyWindow(intermediate_window); |
737 ::UnregisterClass(reinterpret_cast<wchar_t*>(class_registration), | 743 ::UnregisterClass(reinterpret_cast<wchar_t*>(class_registration), |
738 module_handle); | 744 module_handle); |
739 return true; | 745 return true; |
740 } | 746 } |
741 | 747 |
| 748 #endif // OS_WIN |
| 749 |
742 // These commands convert from c calls to local os calls. | 750 // These commands convert from c calls to local os calls. |
743 void GLGenBuffersHelper( | 751 void GLGenBuffersHelper( |
744 GLES2DecoderImpl*, GLsizei n, GLuint* ids) { | 752 GLES2DecoderImpl*, GLsizei n, GLuint* ids) { |
745 glGenBuffersARB(n, ids); | 753 glGenBuffersARB(n, ids); |
746 } | 754 } |
747 | 755 |
748 void GLGenFramebuffersHelper( | 756 void GLGenFramebuffersHelper( |
749 GLES2DecoderImpl*, GLsizei n, GLuint* ids) { | 757 GLES2DecoderImpl*, GLsizei n, GLuint* ids) { |
750 glGenFramebuffersEXT(n, ids); | 758 glGenFramebuffersEXT(n, ids); |
751 } | 759 } |
(...skipping 25 matching lines...) Expand all Loading... |
777 GLES2DecoderImpl*, GLsizei n, GLuint* ids) { | 785 GLES2DecoderImpl*, GLsizei n, GLuint* ids) { |
778 glDeleteRenderbuffersEXT(n, ids); | 786 glDeleteRenderbuffersEXT(n, ids); |
779 } | 787 } |
780 | 788 |
781 void GLDeleteTexturesHelper( | 789 void GLDeleteTexturesHelper( |
782 GLES2DecoderImpl*, GLsizei n, GLuint* ids) { | 790 GLES2DecoderImpl*, GLsizei n, GLuint* ids) { |
783 glDeleteTextures(n, ids); | 791 glDeleteTextures(n, ids); |
784 } | 792 } |
785 | 793 |
786 } // anonymous namespace | 794 } // anonymous namespace |
787 #endif | |
788 | 795 |
789 bool GLES2DecoderImpl::RegisterObjects( | 796 bool GLES2DecoderImpl::RegisterObjects( |
790 GLsizei n, const GLuint* client_ids, const GLuint* service_ids) { | 797 GLsizei n, const GLuint* client_ids, const GLuint* service_ids) { |
791 for (GLsizei ii = 0; ii < n; ++ii) { | 798 for (GLsizei ii = 0; ii < n; ++ii) { |
792 if (!id_map_.AddMapping(client_ids[ii], service_ids[ii])) { | 799 if (!id_map_.AddMapping(client_ids[ii], service_ids[ii])) { |
793 // TODO(gman): fail. | 800 // TODO(gman): fail. |
794 } | 801 } |
795 } | 802 } |
796 return true; | 803 return true; |
797 } | 804 } |
(...skipping 13 matching lines...) Expand all Loading... |
811 void GLES2DecoderImpl::RemoveBufferInfo(GLuint buffer_id) { | 818 void GLES2DecoderImpl::RemoveBufferInfo(GLuint buffer_id) { |
812 for (GLuint ii = 0; ii < max_vertex_attribs_; ++ii) { | 819 for (GLuint ii = 0; ii < max_vertex_attribs_; ++ii) { |
813 if (vertex_attrib_infos_[ii].buffer() == buffer_id) { | 820 if (vertex_attrib_infos_[ii].buffer() == buffer_id) { |
814 vertex_attrib_infos_[ii].Clear(); | 821 vertex_attrib_infos_[ii].Clear(); |
815 } | 822 } |
816 } | 823 } |
817 buffer_infos_.erase(buffer_id); | 824 buffer_infos_.erase(buffer_id); |
818 } | 825 } |
819 | 826 |
820 bool GLES2DecoderImpl::InitPlatformSpecific() { | 827 bool GLES2DecoderImpl::InitPlatformSpecific() { |
821 #if defined(OS_WIN) | 828 #if defined(UNIT_TEST) |
| 829 #elif defined(OS_WIN) |
822 device_context_ = ::GetDC(hwnd()); | 830 device_context_ = ::GetDC(hwnd()); |
823 | 831 |
824 int pixel_format; | 832 int pixel_format; |
825 | 833 |
826 if (!GetWindowsPixelFormat(hwnd(), | 834 if (!GetWindowsPixelFormat(hwnd(), |
827 anti_aliased_, | 835 anti_aliased_, |
828 &pixel_format)) { | 836 &pixel_format)) { |
829 DLOG(ERROR) << "Unable to determine optimal pixel format for GL context."; | 837 DLOG(ERROR) << "Unable to determine optimal pixel format for GL context."; |
830 return false; | 838 return false; |
831 } | 839 } |
(...skipping 19 matching lines...) Expand all Loading... |
851 if (!window()->Initialize()) | 859 if (!window()->Initialize()) |
852 return false; | 860 return false; |
853 if (!window()->MakeCurrent()) | 861 if (!window()->MakeCurrent()) |
854 return false; | 862 return false; |
855 #endif | 863 #endif |
856 | 864 |
857 return true; | 865 return true; |
858 } | 866 } |
859 | 867 |
860 bool GLES2DecoderImpl::InitGlew() { | 868 bool GLES2DecoderImpl::InitGlew() { |
| 869 #if !defined(UNIT_TEST) |
861 DLOG(INFO) << "Initializing GL and GLEW for GLES2Decoder."; | 870 DLOG(INFO) << "Initializing GL and GLEW for GLES2Decoder."; |
862 | 871 |
863 GLenum glew_error = glewInit(); | 872 GLenum glew_error = glewInit(); |
864 if (glew_error != GLEW_OK) { | 873 if (glew_error != GLEW_OK) { |
865 DLOG(ERROR) << "Unable to initialise GLEW : " | 874 DLOG(ERROR) << "Unable to initialise GLEW : " |
866 << ::glewGetErrorString(glew_error); | 875 << ::glewGetErrorString(glew_error); |
867 return false; | 876 return false; |
868 } | 877 } |
869 | 878 |
870 // Check to see that we can use the OpenGL vertex attribute APIs | 879 // Check to see that we can use the OpenGL vertex attribute APIs |
(...skipping 29 matching lines...) Expand all Loading... |
900 if (!GLEW_VERSION_1_4 && !GLEW_EXT_blend_func_separate) { | 909 if (!GLEW_VERSION_1_4 && !GLEW_EXT_blend_func_separate) { |
901 DLOG(ERROR) <<"Separate blend func extension missing."; | 910 DLOG(ERROR) <<"Separate blend func extension missing."; |
902 extensions_found = false; | 911 extensions_found = false; |
903 } | 912 } |
904 if (!GLEW_VERSION_2_0 && !GLEW_EXT_blend_equation_separate) { | 913 if (!GLEW_VERSION_2_0 && !GLEW_EXT_blend_equation_separate) { |
905 DLOG(ERROR) << "Separate blend function extension missing."; | 914 DLOG(ERROR) << "Separate blend function extension missing."; |
906 extensions_found = false; | 915 extensions_found = false; |
907 } | 916 } |
908 if (!extensions_found) | 917 if (!extensions_found) |
909 return false; | 918 return false; |
| 919 #endif |
910 | 920 |
911 return true; | 921 return true; |
912 } | 922 } |
913 | 923 |
914 void GLES2DecoderImpl::Destroy() { | 924 void GLES2DecoderImpl::Destroy() { |
915 #ifdef OS_LINUX | 925 #if defined(UNIT_TEST) |
| 926 #elif defined(OS_LINUX) |
916 DCHECK(window()); | 927 DCHECK(window()); |
917 window()->Destroy(); | 928 window()->Destroy(); |
918 #endif | 929 #endif |
919 } | 930 } |
920 | 931 |
921 const char* GLES2DecoderImpl::GetCommandName(unsigned int command_id) const { | 932 const char* GLES2DecoderImpl::GetCommandName(unsigned int command_id) const { |
922 if (command_id > kStartPoint && command_id < kNumCommands) { | 933 if (command_id > kStartPoint && command_id < kNumCommands) { |
923 return gles2::GetCommandName(static_cast<CommandId>(command_id)); | 934 return gles2::GetCommandName(static_cast<CommandId>(command_id)); |
924 } | 935 } |
925 return GetCommonCommandName(static_cast<cmd::CommandId>(command_id)); | 936 return GetCommonCommandName(static_cast<cmd::CommandId>(command_id)); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1066 RemoveProgramInfo(program); | 1077 RemoveProgramInfo(program); |
1067 SetGLError(error); | 1078 SetGLError(error); |
1068 } else { | 1079 } else { |
1069 UpdateProgramInfo(program); | 1080 UpdateProgramInfo(program); |
1070 } | 1081 } |
1071 }; | 1082 }; |
1072 | 1083 |
1073 // NOTE: If you need to know the results of SwapBuffers (like losing | 1084 // NOTE: If you need to know the results of SwapBuffers (like losing |
1074 // the context) then add a new command. Do NOT make SwapBuffers synchronous. | 1085 // the context) then add a new command. Do NOT make SwapBuffers synchronous. |
1075 void GLES2DecoderImpl::DoSwapBuffers() { | 1086 void GLES2DecoderImpl::DoSwapBuffers() { |
1076 #ifdef OS_WIN | 1087 #if defined(UNIT_TEST) |
| 1088 #elif defined(OS_WIN) |
1077 ::SwapBuffers(device_context_); | 1089 ::SwapBuffers(device_context_); |
1078 #endif | 1090 #elif defined(OS_LINUX) |
1079 | |
1080 #ifdef OS_LINUX | |
1081 DCHECK(window()); | 1091 DCHECK(window()); |
1082 window()->SwapBuffers(); | 1092 window()->SwapBuffers(); |
1083 #endif | 1093 #endif |
1084 } | 1094 } |
1085 | 1095 |
1086 void GLES2DecoderImpl::DoUseProgram(GLuint program) { | 1096 void GLES2DecoderImpl::DoUseProgram(GLuint program) { |
1087 ProgramInfo* info = GetProgramInfo(program); | 1097 ProgramInfo* info = GetProgramInfo(program); |
1088 if (!info) { | 1098 if (!info) { |
1089 // Program was not linked successfully. (ie, glLinkProgram) | 1099 // Program was not linked successfully. (ie, glLinkProgram) |
1090 SetGLError(GL_INVALID_OPERATION); | 1100 SetGLError(GL_INVALID_OPERATION); |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1706 } | 1716 } |
1707 | 1717 |
1708 // Include the auto-generated part of this file. We split this because it means | 1718 // Include the auto-generated part of this file. We split this because it means |
1709 // we can easily edit the non-auto generated parts right here in this file | 1719 // we can easily edit the non-auto generated parts right here in this file |
1710 // instead of having to edit some template or the code generator. | 1720 // instead of having to edit some template or the code generator. |
1711 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 1721 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
1712 | 1722 |
1713 } // namespace gles2 | 1723 } // namespace gles2 |
1714 } // namespace gpu | 1724 } // namespace gpu |
1715 | 1725 |
OLD | NEW |