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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/resource_provider.h" | 7 #include "cc/resource_provider.h" |
8 | 8 |
9 #include <limits.h> | 9 #include <limits.h> |
10 | 10 |
11 #include "IntRect.h" | |
12 #include "base/debug/alias.h" | 11 #include "base/debug/alias.h" |
13 #include "base/hash_tables.h" | 12 #include "base/hash_tables.h" |
14 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
15 #include "base/string_split.h" | 14 #include "base/string_split.h" |
16 #include "base/string_util.h" | 15 #include "base/string_util.h" |
17 #include "cc/gl_renderer.h" // For the GLC() macro. | 16 #include "cc/gl_renderer.h" // For the GLC() macro. |
18 #include "cc/proxy.h" | 17 #include "cc/proxy.h" |
19 #include "cc/texture_uploader.h" | 18 #include "cc/texture_uploader.h" |
20 #include "third_party/khronos/GLES2/gl2.h" | 19 #include "third_party/khronos/GLES2/gl2.h" |
21 #include "third_party/khronos/GLES2/gl2ext.h" | 20 #include "third_party/khronos/GLES2/gl2ext.h" |
| 21 #include "ui/gfx/rect.h" |
| 22 #include "ui/gfx/vector2d.h" |
22 | 23 |
23 #include <public/WebGraphicsContext3D.h> | 24 #include <public/WebGraphicsContext3D.h> |
24 | 25 |
25 using WebKit::WebGraphicsContext3D; | 26 using WebKit::WebGraphicsContext3D; |
26 | 27 |
27 namespace { | 28 namespace { |
28 // Temporary variables for debugging crashes in issue 151428 in canary. | 29 // Temporary variables for debugging crashes in issue 151428 in canary. |
29 // Do not use these! | 30 // Do not use these! |
30 const int g_debugMaxResourcesTracked = 64; | 31 const int g_debugMaxResourcesTracked = 64; |
31 unsigned int g_debugZone = 0; | 32 unsigned int g_debugZone = 0; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 , lockedForWrite(false) | 74 , lockedForWrite(false) |
74 , external(false) | 75 , external(false) |
75 , exported(false) | 76 , exported(false) |
76 , markedForDeletion(false) | 77 , markedForDeletion(false) |
77 , size() | 78 , size() |
78 , format(0) | 79 , format(0) |
79 , type(static_cast<ResourceType>(0)) | 80 , type(static_cast<ResourceType>(0)) |
80 { | 81 { |
81 } | 82 } |
82 | 83 |
83 ResourceProvider::Resource::Resource(unsigned textureId, int pool, const IntSize
& size, GLenum format) | 84 ResourceProvider::Resource::Resource(unsigned textureId, int pool, const gfx::Si
ze& size, GLenum format) |
84 : glId(textureId) | 85 : glId(textureId) |
85 , pixels(0) | 86 , pixels(0) |
86 , pool(pool) | 87 , pool(pool) |
87 , lockForReadCount(0) | 88 , lockForReadCount(0) |
88 , lockedForWrite(false) | 89 , lockedForWrite(false) |
89 , external(false) | 90 , external(false) |
90 , exported(false) | 91 , exported(false) |
91 , markedForDeletion(false) | 92 , markedForDeletion(false) |
92 , size(size) | 93 , size(size) |
93 , format(format) | 94 , format(format) |
94 , type(GLTexture) | 95 , type(GLTexture) |
95 { | 96 { |
96 } | 97 } |
97 | 98 |
98 ResourceProvider::Resource::Resource(uint8_t* pixels, int pool, const IntSize& s
ize, GLenum format) | 99 ResourceProvider::Resource::Resource(uint8_t* pixels, int pool, const gfx::Size&
size, GLenum format) |
99 : glId(0) | 100 : glId(0) |
100 , pixels(pixels) | 101 , pixels(pixels) |
101 , pool(pool) | 102 , pool(pool) |
102 , lockForReadCount(0) | 103 , lockForReadCount(0) |
103 , lockedForWrite(false) | 104 , lockedForWrite(false) |
104 , external(false) | 105 , external(false) |
105 , exported(false) | 106 , exported(false) |
106 , markedForDeletion(false) | 107 , markedForDeletion(false) |
107 , size(size) | 108 , size(size) |
108 , format(format) | 109 , format(format) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 144 |
144 bool ResourceProvider::inUseByConsumer(ResourceId id) | 145 bool ResourceProvider::inUseByConsumer(ResourceId id) |
145 { | 146 { |
146 DCHECK(Proxy::isImplThread()); | 147 DCHECK(Proxy::isImplThread()); |
147 ResourceMap::iterator it = m_resources.find(id); | 148 ResourceMap::iterator it = m_resources.find(id); |
148 CHECK(it != m_resources.end()); | 149 CHECK(it != m_resources.end()); |
149 Resource* resource = &it->second; | 150 Resource* resource = &it->second; |
150 return !!resource->lockForReadCount || resource->exported; | 151 return !!resource->lockForReadCount || resource->exported; |
151 } | 152 } |
152 | 153 |
153 ResourceProvider::ResourceId ResourceProvider::createResource(int pool, const In
tSize& size, GLenum format, TextureUsageHint hint) | 154 ResourceProvider::ResourceId ResourceProvider::createResource(int pool, const gf
x::Size& size, GLenum format, TextureUsageHint hint) |
154 { | 155 { |
155 switch (m_defaultResourceType) { | 156 switch (m_defaultResourceType) { |
156 case GLTexture: | 157 case GLTexture: |
157 return createGLTexture(pool, size, format, hint); | 158 return createGLTexture(pool, size, format, hint); |
158 case Bitmap: | 159 case Bitmap: |
159 DCHECK(format == GL_RGBA); | 160 DCHECK(format == GL_RGBA); |
160 return createBitmap(pool, size); | 161 return createBitmap(pool, size); |
161 } | 162 } |
162 | 163 |
163 CRASH(); | 164 CRASH(); |
164 return 0; | 165 return 0; |
165 } | 166 } |
166 | 167 |
167 ResourceProvider::ResourceId ResourceProvider::createGLTexture(int pool, const I
ntSize& size, GLenum format, TextureUsageHint hint) | 168 ResourceProvider::ResourceId ResourceProvider::createGLTexture(int pool, const g
fx::Size& size, GLenum format, TextureUsageHint hint) |
168 { | 169 { |
169 DCHECK(Proxy::isImplThread()); | 170 DCHECK(Proxy::isImplThread()); |
170 unsigned textureId = 0; | 171 unsigned textureId = 0; |
171 WebGraphicsContext3D* context3d = m_context->context3D(); | 172 WebGraphicsContext3D* context3d = m_context->context3D(); |
172 DCHECK(context3d); | 173 DCHECK(context3d); |
173 GLC(context3d, textureId = context3d->createTexture()); | 174 GLC(context3d, textureId = context3d->createTexture()); |
174 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); | 175 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); |
175 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_LINEAR)); | 176 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_LINEAR)); |
176 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_LINEAR)); | 177 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_LINEAR)); |
177 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL
_CLAMP_TO_EDGE)); | 178 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL
_CLAMP_TO_EDGE)); |
178 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL
_CLAMP_TO_EDGE)); | 179 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL
_CLAMP_TO_EDGE)); |
179 | 180 |
180 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) | 181 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) |
181 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_
ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); | 182 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_
ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); |
182 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { | 183 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { |
183 GLenum storageFormat = textureToStorageFormat(format); | 184 GLenum storageFormat = textureToStorageFormat(format); |
184 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma
t, size.width(), size.height())); | 185 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma
t, size.width(), size.height())); |
185 } else | 186 } else |
186 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt
h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0)); | 187 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt
h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0)); |
187 ResourceId id = m_nextId++; | 188 ResourceId id = m_nextId++; |
188 Resource resource(textureId, pool, size, format); | 189 Resource resource(textureId, pool, size, format); |
189 m_resources[id] = resource; | 190 m_resources[id] = resource; |
190 return id; | 191 return id; |
191 } | 192 } |
192 | 193 |
193 ResourceProvider::ResourceId ResourceProvider::createBitmap(int pool, const IntS
ize& size) | 194 ResourceProvider::ResourceId ResourceProvider::createBitmap(int pool, const gfx:
:Size& size) |
194 { | 195 { |
195 DCHECK(Proxy::isImplThread()); | 196 DCHECK(Proxy::isImplThread()); |
196 | 197 |
197 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; | 198 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; |
198 | 199 |
199 ResourceId id = m_nextId++; | 200 ResourceId id = m_nextId++; |
200 Resource resource(pixels, pool, size, GL_RGBA); | 201 Resource resource(pixels, pool, size, GL_RGBA); |
201 m_resources[id] = resource; | 202 m_resources[id] = resource; |
202 return id; | 203 return id; |
203 } | 204 } |
204 | 205 |
205 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture
(unsigned textureId) | 206 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture
(unsigned textureId) |
206 { | 207 { |
207 DCHECK(Proxy::isImplThread()); | 208 DCHECK(Proxy::isImplThread()); |
208 DCHECK(m_context->context3D()); | 209 DCHECK(m_context->context3D()); |
209 ResourceId id = m_nextId++; | 210 ResourceId id = m_nextId++; |
210 Resource resource(textureId, 0, IntSize(), 0); | 211 Resource resource(textureId, 0, gfx::Size(), 0); |
211 resource.external = true; | 212 resource.external = true; |
212 m_resources[id] = resource; | 213 m_resources[id] = resource; |
213 return id; | 214 return id; |
214 } | 215 } |
215 | 216 |
216 void ResourceProvider::deleteResource(ResourceId id) | 217 void ResourceProvider::deleteResource(ResourceId id) |
217 { | 218 { |
218 DCHECK(Proxy::isImplThread()); | 219 DCHECK(Proxy::isImplThread()); |
219 ResourceMap::iterator it = m_resources.find(id); | 220 ResourceMap::iterator it = m_resources.find(id); |
220 CHECK(it != m_resources.end()); | 221 CHECK(it != m_resources.end()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 } | 259 } |
259 | 260 |
260 ResourceProvider::ResourceType ResourceProvider::resourceType(ResourceId id) | 261 ResourceProvider::ResourceType ResourceProvider::resourceType(ResourceId id) |
261 { | 262 { |
262 ResourceMap::iterator it = m_resources.find(id); | 263 ResourceMap::iterator it = m_resources.find(id); |
263 CHECK(it != m_resources.end()); | 264 CHECK(it != m_resources.end()); |
264 Resource* resource = &it->second; | 265 Resource* resource = &it->second; |
265 return resource->type; | 266 return resource->type; |
266 } | 267 } |
267 | 268 |
268 void ResourceProvider::upload(ResourceId id, const uint8_t* image, const IntRect
& imageRect, const IntRect& sourceRect, const IntSize& destOffset) | 269 void ResourceProvider::upload(ResourceId id, const uint8_t* image, const gfx::Re
ct& imageRect, const gfx::Rect& sourceRect, const gfx::Vector2d& destOffset) |
269 { | 270 { |
270 DCHECK(Proxy::isImplThread()); | 271 DCHECK(Proxy::isImplThread()); |
271 ResourceMap::iterator it = m_resources.find(id); | 272 ResourceMap::iterator it = m_resources.find(id); |
272 CHECK(it != m_resources.end()); | 273 CHECK(it != m_resources.end()); |
273 Resource* resource = &it->second; | 274 Resource* resource = &it->second; |
274 DCHECK(!resource->lockedForWrite); | 275 DCHECK(!resource->lockedForWrite); |
275 DCHECK(!resource->lockForReadCount); | 276 DCHECK(!resource->lockForReadCount); |
276 DCHECK(!resource->external); | 277 DCHECK(!resource->external); |
277 DCHECK(!resource->exported); | 278 DCHECK(!resource->exported); |
278 | 279 |
(...skipping 14 matching lines...) Expand all Loading... |
293 SkBitmap srcFull; | 294 SkBitmap srcFull; |
294 srcFull.setConfig(SkBitmap::kARGB_8888_Config, imageRect.width(), imageR
ect.height()); | 295 srcFull.setConfig(SkBitmap::kARGB_8888_Config, imageRect.width(), imageR
ect.height()); |
295 srcFull.setPixels(const_cast<uint8_t*>(image)); | 296 srcFull.setPixels(const_cast<uint8_t*>(image)); |
296 SkBitmap srcSubset; | 297 SkBitmap srcSubset; |
297 SkIRect skSourceRect = SkIRect::MakeXYWH(sourceRect.x(), sourceRect.y(),
sourceRect.width(), sourceRect.height()); | 298 SkIRect skSourceRect = SkIRect::MakeXYWH(sourceRect.x(), sourceRect.y(),
sourceRect.width(), sourceRect.height()); |
298 skSourceRect.offset(-imageRect.x(), -imageRect.y()); | 299 skSourceRect.offset(-imageRect.x(), -imageRect.y()); |
299 srcFull.extractSubset(&srcSubset, skSourceRect); | 300 srcFull.extractSubset(&srcSubset, skSourceRect); |
300 | 301 |
301 ScopedWriteLockSoftware lock(this, id); | 302 ScopedWriteLockSoftware lock(this, id); |
302 SkCanvas* dest = lock.skCanvas(); | 303 SkCanvas* dest = lock.skCanvas(); |
303 dest->writePixels(srcSubset, destOffset.width(), destOffset.height()); | 304 dest->writePixels(srcSubset, destOffset.x(), destOffset.y()); |
304 } | 305 } |
305 } | 306 } |
306 | 307 |
307 size_t ResourceProvider::numBlockingUploads() | 308 size_t ResourceProvider::numBlockingUploads() |
308 { | 309 { |
309 if (!m_textureUploader) | 310 if (!m_textureUploader) |
310 return 0; | 311 return 0; |
311 | 312 |
312 return m_textureUploader->numBlockingUploads(); | 313 return m_textureUploader->numBlockingUploads(); |
313 } | 314 } |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 g_debugZone = zone; | 709 g_debugZone = zone; |
709 } | 710 } |
710 | 711 |
711 void ResourceProvider::debugNotifyLeaveZone() | 712 void ResourceProvider::debugNotifyLeaveZone() |
712 { | 713 { |
713 g_debugZone = 0; | 714 g_debugZone = 0; |
714 } | 715 } |
715 | 716 |
716 | 717 |
717 } | 718 } |
OLD | NEW |