Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(384)

Side by Side Diff: gpu/command_buffer/common/gles2_cmd_utils.cc

Issue 455783002: GPU context creation code duplication cleanup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Fix even more build dependencies Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 is here so other GLES2 related files can have a common set of 5 // This file is here so other GLES2 related files can have a common set of
6 // includes where appropriate. 6 // includes where appropriate.
7 7
8 #include <sstream> 8 #include <sstream>
9 #include <GLES2/gl2.h> 9 #include <GLES2/gl2.h>
10 #include <GLES2/gl2ext.h> 10 #include <GLES2/gl2ext.h>
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 getting_array_location = true; 777 getting_array_location = true;
778 } 778 }
779 *getting_array = getting_array_location; 779 *getting_array = getting_array_location;
780 *element_index = index; 780 *element_index = index;
781 *array_pos = open_pos; 781 *array_pos = open_pos;
782 return true; 782 return true;
783 } 783 }
784 784
785 namespace { 785 namespace {
786 786
787 // WebGraphicsContext3DCommandBufferImpl configuration attributes. Those in
788 // the 16-bit range are the same as used by EGL. Those outside the 16-bit range
789 // are unique to Chromium. Attributes are matched using a closest fit algorithm.
790
787 // From <EGL/egl.h>. 791 // From <EGL/egl.h>.
788 const int32 kAlphaSize = 0x3021; // EGL_ALPHA_SIZE 792 const int32 kAlphaSize = 0x3021; // EGL_ALPHA_SIZE
789 const int32 kBlueSize = 0x3022; // EGL_BLUE_SIZE 793 const int32 kBlueSize = 0x3022; // EGL_BLUE_SIZE
790 const int32 kGreenSize = 0x3023; // EGL_GREEN_SIZE 794 const int32 kGreenSize = 0x3023; // EGL_GREEN_SIZE
791 const int32 kRedSize = 0x3024; // EGL_RED_SIZE 795 const int32 kRedSize = 0x3024; // EGL_RED_SIZE
792 const int32 kDepthSize = 0x3025; // EGL_DEPTH_SIZE 796 const int32 kDepthSize = 0x3025; // EGL_DEPTH_SIZE
793 const int32 kStencilSize = 0x3026; // EGL_STENCIL_SIZE 797 const int32 kStencilSize = 0x3026; // EGL_STENCIL_SIZE
794 const int32 kSamples = 0x3031; // EGL_SAMPLES 798 const int32 kSamples = 0x3031; // EGL_SAMPLES
795 const int32 kSampleBuffers = 0x3032; // EGL_SAMPLE_BUFFERS 799 const int32 kSampleBuffers = 0x3032; // EGL_SAMPLE_BUFFERS
796 const int32 kNone = 0x3038; // EGL_NONE 800 const int32 kNone = 0x3038; // EGL_NONE
797 const int32 kSwapBehavior = 0x3093; // EGL_SWAP_BEHAVIOR 801 const int32 kSwapBehavior = 0x3093; // EGL_SWAP_BEHAVIOR
798 const int32 kBufferPreserved = 0x3094; // EGL_BUFFER_PRESERVED 802 const int32 kBufferPreserved = 0x3094; // EGL_BUFFER_PRESERVED
799 const int32 kBufferDestroyed = 0x3095; // EGL_BUFFER_DESTROYED 803 const int32 kBufferDestroyed = 0x3095; // EGL_BUFFER_DESTROYED
800 804
801 // Chromium only. 805 // Chromium only.
802 const int32 kShareResources = 0x10000; 806 const int32 kBindGeneratesResource = 0x10000;
803 const int32 kBindGeneratesResource = 0x10001; 807 const int32 kFailIfMajorPerfCaveat = 0x10001;
804 const int32 kFailIfMajorPerfCaveat = 0x10002; 808 const int32 kLoseContextWhenOutOfMemory = 0x10002;
805 const int32 kLoseContextWhenOutOfMemory = 0x10003;
806 809
807 } // namespace 810 } // namespace
808 811
809 ContextCreationAttribHelper::ContextCreationAttribHelper() 812 ContextCreationAttribHelper::ContextCreationAttribHelper()
810 : alpha_size_(-1), 813 : alpha_size(-1),
811 blue_size_(-1), 814 blue_size(-1),
812 green_size_(-1), 815 green_size(-1),
813 red_size_(-1), 816 red_size(-1),
814 depth_size_(-1), 817 depth_size(-1),
815 stencil_size_(-1), 818 stencil_size(-1),
816 samples_(-1), 819 samples(-1),
817 sample_buffers_(-1), 820 sample_buffers(-1),
818 buffer_preserved_(true), 821 buffer_preserved(true),
819 share_resources_(false), 822 bind_generates_resource(true),
820 bind_generates_resource_(true), 823 fail_if_major_perf_caveat(false),
821 fail_if_major_perf_caveat_(false), 824 lose_context_when_out_of_memory(false) {}
822 lose_context_when_out_of_memory_(false) {}
823 825
824 void ContextCreationAttribHelper::Serialize(std::vector<int32>* attribs) { 826 void ContextCreationAttribHelper::Serialize(std::vector<int32>* attribs) const {
825 if (alpha_size_ != -1) { 827 if (alpha_size != -1) {
826 attribs->push_back(kAlphaSize); 828 attribs->push_back(kAlphaSize);
827 attribs->push_back(alpha_size_); 829 attribs->push_back(alpha_size);
828 } 830 }
829 if (blue_size_ != -1) { 831 if (blue_size != -1) {
830 attribs->push_back(kBlueSize); 832 attribs->push_back(kBlueSize);
831 attribs->push_back(blue_size_); 833 attribs->push_back(blue_size);
832 } 834 }
833 if (green_size_ != -1) { 835 if (green_size != -1) {
834 attribs->push_back(kGreenSize); 836 attribs->push_back(kGreenSize);
835 attribs->push_back(green_size_); 837 attribs->push_back(green_size);
836 } 838 }
837 if (red_size_ != -1) { 839 if (red_size != -1) {
838 attribs->push_back(kRedSize); 840 attribs->push_back(kRedSize);
839 attribs->push_back(red_size_); 841 attribs->push_back(red_size);
840 } 842 }
841 if (depth_size_ != -1) { 843 if (depth_size != -1) {
842 attribs->push_back(kDepthSize); 844 attribs->push_back(kDepthSize);
843 attribs->push_back(depth_size_); 845 attribs->push_back(depth_size);
844 } 846 }
845 if (stencil_size_ != -1) { 847 if (stencil_size != -1) {
846 attribs->push_back(kStencilSize); 848 attribs->push_back(kStencilSize);
847 attribs->push_back(stencil_size_); 849 attribs->push_back(stencil_size);
848 } 850 }
849 if (samples_ != -1) { 851 if (samples != -1) {
850 attribs->push_back(kSamples); 852 attribs->push_back(kSamples);
851 attribs->push_back(samples_); 853 attribs->push_back(samples);
852 } 854 }
853 if (sample_buffers_ != -1) { 855 if (sample_buffers != -1) {
854 attribs->push_back(kSampleBuffers); 856 attribs->push_back(kSampleBuffers);
855 attribs->push_back(sample_buffers_); 857 attribs->push_back(sample_buffers);
856 } 858 }
857 attribs->push_back(kSwapBehavior); 859 attribs->push_back(kSwapBehavior);
858 attribs->push_back(buffer_preserved_ ? kBufferPreserved : kBufferDestroyed); 860 attribs->push_back(buffer_preserved ? kBufferPreserved : kBufferDestroyed);
859 attribs->push_back(kShareResources);
860 attribs->push_back(share_resources_ ? 1 : 0);
861 attribs->push_back(kBindGeneratesResource); 861 attribs->push_back(kBindGeneratesResource);
862 attribs->push_back(bind_generates_resource_ ? 1 : 0); 862 attribs->push_back(bind_generates_resource ? 1 : 0);
863 attribs->push_back(kFailIfMajorPerfCaveat); 863 attribs->push_back(kFailIfMajorPerfCaveat);
864 attribs->push_back(fail_if_major_perf_caveat_ ? 1 : 0); 864 attribs->push_back(fail_if_major_perf_caveat ? 1 : 0);
865 attribs->push_back(kLoseContextWhenOutOfMemory); 865 attribs->push_back(kLoseContextWhenOutOfMemory);
866 attribs->push_back(lose_context_when_out_of_memory_ ? 1 : 0); 866 attribs->push_back(lose_context_when_out_of_memory ? 1 : 0);
867 attribs->push_back(kNone); 867 attribs->push_back(kNone);
868 } 868 }
869 869
870 bool ContextCreationAttribHelper::Parse(const std::vector<int32>& attribs) { 870 bool ContextCreationAttribHelper::Parse(const std::vector<int32>& attribs) {
871 for (size_t i = 0; i < attribs.size(); i += 2) { 871 for (size_t i = 0; i < attribs.size(); i += 2) {
872 const int32 attrib = attribs[i]; 872 const int32 attrib = attribs[i];
873 if (i + 1 >= attribs.size()) { 873 if (i + 1 >= attribs.size()) {
874 if (attrib == kNone) { 874 if (attrib == kNone) {
875 return true; 875 return true;
876 } 876 }
877 877
878 DLOG(ERROR) << "Missing value after context creation attribute: " 878 DLOG(ERROR) << "Missing value after context creation attribute: "
879 << attrib; 879 << attrib;
880 return false; 880 return false;
881 } 881 }
882 882
883 const int32 value = attribs[i+1]; 883 const int32 value = attribs[i+1];
884 switch (attrib) { 884 switch (attrib) {
885 case kAlphaSize: 885 case kAlphaSize:
886 alpha_size_ = value; 886 alpha_size = value;
887 break; 887 break;
888 case kBlueSize: 888 case kBlueSize:
889 blue_size_ = value; 889 blue_size = value;
890 break; 890 break;
891 case kGreenSize: 891 case kGreenSize:
892 green_size_ = value; 892 green_size = value;
893 break; 893 break;
894 case kRedSize: 894 case kRedSize:
895 red_size_ = value; 895 red_size = value;
896 break; 896 break;
897 case kDepthSize: 897 case kDepthSize:
898 depth_size_ = value; 898 depth_size = value;
899 break; 899 break;
900 case kStencilSize: 900 case kStencilSize:
901 stencil_size_ = value; 901 stencil_size = value;
902 break; 902 break;
903 case kSamples: 903 case kSamples:
904 samples_ = value; 904 samples = value;
905 break; 905 break;
906 case kSampleBuffers: 906 case kSampleBuffers:
907 sample_buffers_ = value; 907 sample_buffers = value;
908 break; 908 break;
909 case kSwapBehavior: 909 case kSwapBehavior:
910 buffer_preserved_ = value == kBufferPreserved; 910 buffer_preserved = value == kBufferPreserved;
911 break;
912 case kShareResources:
913 share_resources_ = value != 0;
914 break; 911 break;
915 case kBindGeneratesResource: 912 case kBindGeneratesResource:
916 bind_generates_resource_ = value != 0; 913 bind_generates_resource = value != 0;
917 break; 914 break;
918 case kFailIfMajorPerfCaveat: 915 case kFailIfMajorPerfCaveat:
919 fail_if_major_perf_caveat_ = value != 0; 916 fail_if_major_perf_caveat = value != 0;
920 break; 917 break;
921 case kLoseContextWhenOutOfMemory: 918 case kLoseContextWhenOutOfMemory:
922 lose_context_when_out_of_memory_ = value != 0; 919 lose_context_when_out_of_memory = value != 0;
923 break; 920 break;
924 case kNone: 921 case kNone:
925 // Terminate list, even if more attributes. 922 // Terminate list, even if more attributes.
926 return true; 923 return true;
927 default: 924 default:
928 DLOG(ERROR) << "Invalid context creation attribute: " << attrib; 925 DLOG(ERROR) << "Invalid context creation attribute: " << attrib;
929 return false; 926 return false;
930 } 927 }
931 } 928 }
932 929
933 return true; 930 return true;
934 } 931 }
935 932
936 #include "gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h" 933 #include "gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h"
937 934
938 } // namespace gles2 935 } // namespace gles2
939 } // namespace gpu 936 } // namespace gpu
940 937
OLDNEW
« no previous file with comments | « gpu/command_buffer/common/gles2_cmd_utils.h ('k') | gpu/command_buffer/service/gles2_cmd_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698