OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #include "cc/resources/resource_provider.h" | 5 #include "cc/resources/resource_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 break; | 47 break; |
48 } | 48 } |
49 | 49 |
50 return storage_format; | 50 return storage_format; |
51 } | 51 } |
52 | 52 |
53 bool IsTextureFormatSupportedForStorage(GLenum format) { | 53 bool IsTextureFormatSupportedForStorage(GLenum format) { |
54 return (format == GL_RGBA || format == GL_BGRA_EXT); | 54 return (format == GL_RGBA || format == GL_BGRA_EXT); |
55 } | 55 } |
56 | 56 |
| 57 class ScopedSetActiveTexture { |
| 58 public: |
| 59 ScopedSetActiveTexture(WebGraphicsContext3D* context3d, GLenum unit) |
| 60 : context3d_(context3d), unit_(unit) { |
| 61 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(context3d_)); |
| 62 |
| 63 if (unit_ != GL_TEXTURE0) |
| 64 GLC(context3d_, context3d_->activeTexture(unit_)); |
| 65 } |
| 66 |
| 67 ~ScopedSetActiveTexture() { |
| 68 // Active unit being GL_TEXTURE0 is effectively the ground state. |
| 69 if (unit_ != GL_TEXTURE0) |
| 70 GLC(context3d_, context3d_->activeTexture(GL_TEXTURE0)); |
| 71 } |
| 72 |
| 73 private: |
| 74 WebGraphicsContext3D* context3d_; |
| 75 GLenum unit_; |
| 76 }; |
| 77 |
57 } // namespace | 78 } // namespace |
58 | 79 |
59 ResourceProvider::Resource::Resource() | 80 ResourceProvider::Resource::Resource() |
60 : gl_id(0), | 81 : gl_id(0), |
61 gl_pixel_buffer_id(0), | 82 gl_pixel_buffer_id(0), |
62 gl_upload_query_id(0), | 83 gl_upload_query_id(0), |
63 pixels(NULL), | 84 pixels(NULL), |
64 pixel_buffer(NULL), | 85 pixel_buffer(NULL), |
65 lock_for_read_count(0), | 86 lock_for_read_count(0), |
66 imported_count(0), | 87 imported_count(0), |
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1090 GLenum target, | 1111 GLenum target, |
1091 GLenum unit, | 1112 GLenum unit, |
1092 GLenum filter) { | 1113 GLenum filter) { |
1093 DCHECK(thread_checker_.CalledOnValidThread()); | 1114 DCHECK(thread_checker_.CalledOnValidThread()); |
1094 WebGraphicsContext3D* context3d = Context3d(); | 1115 WebGraphicsContext3D* context3d = Context3d(); |
1095 ResourceMap::iterator it = resources_.find(resource_id); | 1116 ResourceMap::iterator it = resources_.find(resource_id); |
1096 DCHECK(it != resources_.end()); | 1117 DCHECK(it != resources_.end()); |
1097 Resource* resource = &it->second; | 1118 Resource* resource = &it->second; |
1098 DCHECK(resource->lock_for_read_count); | 1119 DCHECK(resource->lock_for_read_count); |
1099 DCHECK(!resource->locked_for_write || resource->set_pixels_completion_forced); | 1120 DCHECK(!resource->locked_for_write || resource->set_pixels_completion_forced); |
1100 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(context3d)); | |
1101 | 1121 |
1102 if (unit != GL_TEXTURE0) | 1122 ScopedSetActiveTexture scoped_active_tex(context3d, unit); |
1103 GLC(context3d, context3d->activeTexture(unit)); | |
1104 GLC(context3d, context3d->bindTexture(target, resource->gl_id)); | 1123 GLC(context3d, context3d->bindTexture(target, resource->gl_id)); |
1105 if (filter != resource->filter) { | 1124 if (filter != resource->filter) { |
1106 GLC(context3d, context3d->texParameteri(target, | 1125 GLC(context3d, context3d->texParameteri(target, |
1107 GL_TEXTURE_MIN_FILTER, | 1126 GL_TEXTURE_MIN_FILTER, |
1108 filter)); | 1127 filter)); |
1109 GLC(context3d, context3d->texParameteri(target, | 1128 GLC(context3d, context3d->texParameteri(target, |
1110 GL_TEXTURE_MAG_FILTER, | 1129 GL_TEXTURE_MAG_FILTER, |
1111 filter)); | 1130 filter)); |
1112 resource->filter = filter; | 1131 resource->filter = filter; |
1113 } | 1132 } |
1114 | 1133 |
1115 if (resource->image_id) | 1134 if (resource->image_id) |
1116 context3d->bindTexImage2DCHROMIUM(target, resource->image_id); | 1135 context3d->bindTexImage2DCHROMIUM(target, resource->image_id); |
1117 | |
1118 // Active unit being GL_TEXTURE0 is effectively the ground state. | |
1119 if (unit != GL_TEXTURE0) | |
1120 GLC(context3d, context3d->activeTexture(GL_TEXTURE0)); | |
1121 } | 1136 } |
1122 | 1137 |
1123 void ResourceProvider::UnbindForSampling( | 1138 void ResourceProvider::UnbindForSampling( |
1124 ResourceProvider::ResourceId resource_id, GLenum target, GLenum unit) { | 1139 ResourceProvider::ResourceId resource_id, GLenum target, GLenum unit) { |
1125 DCHECK(thread_checker_.CalledOnValidThread()); | 1140 DCHECK(thread_checker_.CalledOnValidThread()); |
1126 ResourceMap::iterator it = resources_.find(resource_id); | 1141 ResourceMap::iterator it = resources_.find(resource_id); |
1127 DCHECK(it != resources_.end()); | 1142 DCHECK(it != resources_.end()); |
1128 Resource* resource = &it->second; | 1143 Resource* resource = &it->second; |
1129 | 1144 |
1130 if (!resource->image_id) | 1145 if (!resource->image_id) |
1131 return; | 1146 return; |
1132 | 1147 |
1133 WebGraphicsContext3D* context3d = Context3d(); | 1148 WebGraphicsContext3D* context3d = Context3d(); |
1134 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(context3d)); | 1149 ScopedSetActiveTexture scoped_active_tex(context3d, unit); |
1135 if (unit != GL_TEXTURE0) | |
1136 GLC(context3d, context3d->activeTexture(unit)); | |
1137 context3d->releaseTexImage2DCHROMIUM(target, resource->image_id); | 1150 context3d->releaseTexImage2DCHROMIUM(target, resource->image_id); |
1138 // Active unit being GL_TEXTURE0 is effectively the ground state. | |
1139 if (unit != GL_TEXTURE0) | |
1140 GLC(context3d, context3d->activeTexture(GL_TEXTURE0)); | |
1141 } | 1151 } |
1142 | 1152 |
1143 void ResourceProvider::BeginSetPixels(ResourceId id) { | 1153 void ResourceProvider::BeginSetPixels(ResourceId id) { |
1144 Resource* resource = GetResource(id); | 1154 Resource* resource = GetResource(id); |
1145 DCHECK(!resource->pending_set_pixels); | 1155 DCHECK(!resource->pending_set_pixels); |
1146 | 1156 |
1147 LazyCreate(resource); | 1157 LazyCreate(resource); |
1148 DCHECK(resource->gl_id || resource->allocated); | 1158 DCHECK(resource->gl_id || resource->allocated); |
1149 DCHECK(ReadLockFenceHasPassed(resource)); | 1159 DCHECK(ReadLockFenceHasPassed(resource)); |
1150 DCHECK(!resource->image_id); | 1160 DCHECK(!resource->image_id); |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1416 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); | 1426 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
1417 return active_unit; | 1427 return active_unit; |
1418 } | 1428 } |
1419 | 1429 |
1420 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { | 1430 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { |
1421 ContextProvider* context_provider = output_surface_->context_provider(); | 1431 ContextProvider* context_provider = output_surface_->context_provider(); |
1422 return context_provider ? context_provider->Context3d() : NULL; | 1432 return context_provider ? context_provider->Context3d() : NULL; |
1423 } | 1433 } |
1424 | 1434 |
1425 } // namespace cc | 1435 } // namespace cc |
OLD | NEW |