Changeset 64872 in webkit
- Timestamp:
- Aug 6, 2010 2:58:55 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r64870 r64872 1 2010-08-06 James Robinson <jamesr@chromium.org> 2 3 Reviewed by Dimitri Glazkov. 4 5 [chromium] Implement GLES2Canvas/Texture in terms of GraphicsContext3D instead of direct OpenGL calls 6 https://bugs.webkit.org/show_bug.cgi?id=43608 7 8 This converts all OpenGL calls in GLES2(Canvas|Texture) to calls on the corresponding GraphicsContext3D 9 API, due to feedback on https://bugs.webkit.org/show_bug.cgi?id=43362. Nearly all the changes are 10 applying the regex s/gl([A-Z])/m_context->%1</ and removing unnecessary makeCurrent() calls. 11 Other changes hilighted below. 12 13 * platform/graphics/chromium/GLES2Canvas.cpp: 14 (WebCore::affineTo3x3): 15 (WebCore::GLES2Canvas::GLES2Canvas): 16 (WebCore::GLES2Canvas::~GLES2Canvas): 17 (WebCore::GLES2Canvas::clearRect): 18 (WebCore::GLES2Canvas::fillRect): 19 (WebCore::GLES2Canvas::drawTexturedRect): 20 (WebCore::GLES2Canvas::applyCompositeOperator): 21 (WebCore::GLES2Canvas::getQuadVertices): 22 (WebCore::GLES2Canvas::getQuadIndices): 23 - use new typed XXArray classes for buffer uploads 24 (WebCore::loadShader): 25 (WebCore::GLES2Canvas::getSimpleProgram): 26 (WebCore::GLES2Canvas::getTexProgram): 27 (WebCore::GLES2Canvas::createTexture): 28 (WebCore::GLES2Canvas::checkGLError): 29 * platform/graphics/chromium/GLES2Canvas.h: 30 (WebCore::GLES2Canvas::context): 31 * platform/graphics/chromium/GLES2Texture.cpp: 32 (WebCore::GLES2Texture::GLES2Texture): 33 (WebCore::GLES2Texture::~GLES2Texture): 34 (WebCore::GLES2Texture::create): 35 (WebCore::convertFormat): 36 (WebCore::GLES2Texture::load): 37 (WebCore::GLES2Texture::bind): 38 * platform/graphics/chromium/GLES2Texture.h: 39 * platform/graphics/skia/GraphicsContextSkia.cpp: 40 (WebCore::GraphicsContext::fillRect): 41 - add a missing restore() call to the H/W path 42 * platform/graphics/skia/ImageSkia.cpp: 43 (WebCore::drawBitmapGLES2): 44 * platform/graphics/skia/PlatformContextSkia.cpp: 45 (WebCore::PlatformContextSkia::setGraphicsContext3D): 46 (WebCore::PlatformContextSkia::uploadSoftwareToHardware): 47 - avoid applying CTM to uploads 48 (WebCore::PlatformContextSkia::readbackHardwareToSoftware): 49 * platform/graphics/skia/PlatformContextSkia.h: 50 1 51 2010-08-06 James Robinson <jamesr@chromium.org> 2 52 -
trunk/WebCore/platform/graphics/chromium/GLES2Canvas.cpp
r64374 r64872 35 35 #include "GLES2Canvas.h" 36 36 37 #include "Float32Array.h" 37 38 #include "FloatRect.h" 38 #include "GLES2Context.h"39 39 #include "GLES2Texture.h" 40 41 #include <GLES2/gl2.h> 40 #include "GraphicsContext3D.h" 41 #include "PlatformString.h" 42 #include "Uint16Array.h" 42 43 43 44 #define _USE_MATH_DEFINES 44 45 #include <math.h> 45 46 47 #include <wtf/text/CString.h> 46 48 #include <wtf/OwnArrayPtr.h> 47 49 48 50 namespace WebCore { 49 51 50 static inline void affineTo3x3(const AffineTransform& transform, GLfloat mat[9])52 static inline void affineTo3x3(const AffineTransform& transform, float mat[9]) 51 53 { 52 54 mat[0] = transform.a(); … … 74 76 }; 75 77 76 GLES2Canvas::GLES2Canvas(G LES2Context* context, const IntSize& size)77 : m_ gles2Context(context)78 GLES2Canvas::GLES2Canvas(GraphicsContext3D* context, const IntSize& size) 79 : m_context(context) 78 80 , m_quadVertices(0) 79 81 , m_quadIndices(0) … … 93 95 m_flipMatrix.scale(2.0f / size.width(), -2.0f / size.height()); 94 96 95 m_gles2Context->makeCurrent(); 96 m_gles2Context->resizeOffscreenContent(size); 97 m_gles2Context->swapBuffers(); 98 glViewport(0, 0, size.width(), size.height()); 97 m_context->reshape(size.width(), size.height()); 98 m_context->viewport(0, 0, size.width(), size.height()); 99 99 100 100 m_stateStack.append(State()); … … 108 108 GLES2Canvas::~GLES2Canvas() 109 109 { 110 m_gles2Context->makeCurrent(); 111 if (m_simpleProgram) 112 glDeleteProgram(m_simpleProgram); 113 if (m_texProgram) 114 glDeleteProgram(m_texProgram); 115 if (m_quadVertices) 116 glDeleteBuffers(1, &m_quadVertices); 117 if (m_quadIndices) 118 glDeleteBuffers(1, &m_quadVertices); 110 m_context->deleteProgram(m_simpleProgram); 111 m_context->deleteProgram(m_texProgram); 112 m_context->deleteBuffer(m_quadVertices); 113 m_context->deleteBuffer(m_quadIndices); 119 114 } 120 115 121 116 void GLES2Canvas::clearRect(const FloatRect& rect) 122 117 { 123 m_gles2Context->makeCurrent(); 124 125 glScissor(rect.x(), rect.y(), rect.width(), rect.height()); 126 glEnable(GL_SCISSOR_TEST); 127 glClear(GL_COLOR_BUFFER_BIT); 128 glDisable(GL_SCISSOR_TEST); 118 m_context->scissor(rect.x(), rect.y(), rect.width(), rect.height()); 119 m_context->enable(GraphicsContext3D::SCISSOR_TEST); 120 m_context->clear(GraphicsContext3D::COLOR_BUFFER_BIT); 121 m_context->disable(GraphicsContext3D::SCISSOR_TEST); 129 122 } 130 123 131 124 void GLES2Canvas::fillRect(const FloatRect& rect, const Color& color, ColorSpace colorSpace) 132 125 { 133 m_gles2Context->makeCurrent(); 134 135 glBindBuffer(GL_ARRAY_BUFFER, getQuadVertices()); 136 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, getQuadIndices()); 126 m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, getQuadVertices()); 127 m_context->bindBuffer(GraphicsContext3D::ELEMENT_ARRAY_BUFFER, getQuadIndices()); 137 128 138 129 float rgba[4]; 139 130 color.getRGBA(rgba[0], rgba[1], rgba[2], rgba[3]); 140 glUniform4f(m_simpleColorLocation, rgba[0] * rgba[3], rgba[1] * rgba[3], rgba[2] * rgba[3], rgba[3]);141 142 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);131 m_context->uniform4f(m_simpleColorLocation, rgba[0] * rgba[3], rgba[1] * rgba[3], rgba[2] * rgba[3], rgba[3]); 132 133 m_context->drawElements(GraphicsContext3D::TRIANGLES, 6, GraphicsContext3D::UNSIGNED_SHORT, 0); 143 134 } 144 135 145 136 void GLES2Canvas::fillRect(const FloatRect& rect) 146 137 { 147 m_gles2Context->makeCurrent();148 149 138 applyCompositeOperator(m_state->m_compositeOp); 150 139 151 glBindBuffer(GL_ARRAY_BUFFER, getQuadVertices());152 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, getQuadIndices());153 154 glUseProgram(getSimpleProgram());140 m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, getQuadVertices()); 141 m_context->bindBuffer(GraphicsContext3D::ELEMENT_ARRAY_BUFFER, getQuadIndices()); 142 143 m_context->useProgram(getSimpleProgram()); 155 144 156 145 float rgba[4]; 157 146 m_state->m_fillColor.getRGBA(rgba[0], rgba[1], rgba[2], rgba[3]); 158 glUniform4f(m_simpleColorLocation, rgba[0] * rgba[3], rgba[1] * rgba[3], rgba[2] * rgba[3], rgba[3]);147 m_context->uniform4f(m_simpleColorLocation, rgba[0] * rgba[3], rgba[1] * rgba[3], rgba[2] * rgba[3], rgba[3]); 159 148 160 149 AffineTransform matrix(m_flipMatrix); … … 162 151 matrix.translate(rect.x(), rect.y()); 163 152 matrix.scale(rect.width(), rect.height()); 164 GLfloat mat[9];153 float mat[9]; 165 154 affineTo3x3(matrix, mat); 166 glUniformMatrix3fv(m_simpleMatrixLocation, 1, GL_FALSE, mat);167 168 glVertexAttribPointer(m_simplePositionLocation, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(0));169 170 glEnableVertexAttribArray(m_simplePositionLocation);171 172 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);155 m_context->uniformMatrix3fv(m_simpleMatrixLocation, false /*transpose*/, mat, 1 /*count*/); 156 157 m_context->vertexAttribPointer(m_simplePositionLocation, 3, GraphicsContext3D::FLOAT, false, 0, 0); 158 159 m_context->enableVertexAttribArray(m_simplePositionLocation); 160 161 m_context->drawElements(GraphicsContext3D::TRIANGLES, 6, GraphicsContext3D::UNSIGNED_SHORT, 0); 173 162 } 174 163 … … 223 212 void GLES2Canvas::drawTexturedRect(GLES2Texture* texture, const FloatRect& srcRect, const FloatRect& dstRect, const AffineTransform& transform, float alpha, ColorSpace colorSpace, CompositeOperator compositeOp) 224 213 { 225 m_gles2Context->makeCurrent();226 227 214 applyCompositeOperator(compositeOp); 228 215 229 glBindBuffer(GL_ARRAY_BUFFER, getQuadVertices());230 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, getQuadIndices());216 m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, getQuadVertices()); 217 m_context->bindBuffer(GraphicsContext3D::ELEMENT_ARRAY_BUFFER, getQuadIndices()); 231 218 checkGLError("glBindBuffer"); 232 219 233 glUseProgram(getTexProgram());220 m_context->useProgram(getTexProgram()); 234 221 checkGLError("glUseProgram"); 235 222 236 glActiveTexture(GL_TEXTURE0);223 m_context->activeTexture(GraphicsContext3D::TEXTURE0); 237 224 texture->bind(); 238 225 239 glUniform1i(m_texSamplerLocation, 0);226 m_context->uniform1i(m_texSamplerLocation, 0); 240 227 checkGLError("glUniform1i"); 241 228 242 glUniform1f(m_texAlphaLocation, alpha);229 m_context->uniform1f(m_texAlphaLocation, alpha); 243 230 checkGLError("glUniform1f for alpha"); 244 231 … … 247 234 matrix.translate(dstRect.x(), dstRect.y()); 248 235 matrix.scale(dstRect.width(), dstRect.height()); 249 GLfloat mat[9];236 float mat[9]; 250 237 affineTo3x3(matrix, mat); 251 glUniformMatrix3fv(m_texMatrixLocation, 1, GL_FALSE, mat);238 m_context->uniformMatrix3fv(m_texMatrixLocation, false /*transpose*/, mat, 1 /*count*/); 252 239 checkGLError("glUniformMatrix3fv"); 253 240 … … 256 243 texMatrix.translate(srcRect.x(), srcRect.y()); 257 244 texMatrix.scale(srcRect.width(), srcRect.height()); 258 GLfloat texMat[9];245 float texMat[9]; 259 246 affineTo3x3(texMatrix, texMat); 260 glUniformMatrix3fv(m_texTexMatrixLocation, 1, GL_FALSE, texMat);247 m_context->uniformMatrix3fv(m_texTexMatrixLocation, false /*transpose*/, texMat, 1 /*count*/); 261 248 checkGLError("glUniformMatrix3fv"); 262 249 263 glVertexAttribPointer(m_texPositionLocation, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(0));264 265 glEnableVertexAttribArray(m_texPositionLocation);266 267 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);250 m_context->vertexAttribPointer(m_texPositionLocation, 3, GraphicsContext3D::FLOAT, false, 0, 0); 251 252 m_context->enableVertexAttribArray(m_texPositionLocation); 253 254 m_context->drawElements(GraphicsContext3D::TRIANGLES, 6, GraphicsContext3D::UNSIGNED_SHORT, 0); 268 255 checkGLError("glDrawElements"); 269 256 } … … 281 268 switch (op) { 282 269 case CompositeClear: 283 glEnable(GL_BLEND);284 glBlendFunc(GL_ZERO, GL_ZERO);270 m_context->enable(GraphicsContext3D::BLEND); 271 m_context->blendFunc(GraphicsContext3D::ZERO, GraphicsContext3D::ZERO); 285 272 break; 286 273 case CompositeCopy: 287 glDisable(GL_BLEND);274 m_context->disable(GraphicsContext3D::BLEND); 288 275 break; 289 276 case CompositeSourceOver: 290 glEnable(GL_BLEND);291 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);277 m_context->enable(GraphicsContext3D::BLEND); 278 m_context->blendFunc(GraphicsContext3D::ONE, GraphicsContext3D::ONE_MINUS_SRC_ALPHA); 292 279 break; 293 280 case CompositeSourceIn: 294 glEnable(GL_BLEND);295 glBlendFunc(GL_DST_ALPHA, GL_ZERO);281 m_context->enable(GraphicsContext3D::BLEND); 282 m_context->blendFunc(GraphicsContext3D::DST_ALPHA, GraphicsContext3D::ZERO); 296 283 break; 297 284 case CompositeSourceOut: 298 glEnable(GL_BLEND);299 glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ZERO);285 m_context->enable(GraphicsContext3D::BLEND); 286 m_context->blendFunc(GraphicsContext3D::ONE_MINUS_DST_ALPHA, GraphicsContext3D::ZERO); 300 287 break; 301 288 case CompositeSourceAtop: 302 glEnable(GL_BLEND);303 glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA);289 m_context->enable(GraphicsContext3D::BLEND); 290 m_context->blendFunc(GraphicsContext3D::DST_ALPHA, GraphicsContext3D::ONE_MINUS_SRC_ALPHA); 304 291 break; 305 292 case CompositeDestinationOver: 306 glEnable(GL_BLEND);307 glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE);293 m_context->enable(GraphicsContext3D::BLEND); 294 m_context->blendFunc(GraphicsContext3D::ONE_MINUS_DST_ALPHA, GraphicsContext3D::ONE); 308 295 break; 309 296 case CompositeDestinationIn: 310 glEnable(GL_BLEND);311 glBlendFunc(GL_ZERO, GL_SRC_ALPHA);297 m_context->enable(GraphicsContext3D::BLEND); 298 m_context->blendFunc(GraphicsContext3D::ZERO, GraphicsContext3D::SRC_ALPHA); 312 299 break; 313 300 case CompositeDestinationOut: 314 glEnable(GL_BLEND);315 glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);301 m_context->enable(GraphicsContext3D::BLEND); 302 m_context->blendFunc(GraphicsContext3D::ZERO, GraphicsContext3D::ONE_MINUS_SRC_ALPHA); 316 303 break; 317 304 case CompositeDestinationAtop: 318 glEnable(GL_BLEND);319 glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA);305 m_context->enable(GraphicsContext3D::BLEND); 306 m_context->blendFunc(GraphicsContext3D::ONE_MINUS_DST_ALPHA, GraphicsContext3D::SRC_ALPHA); 320 307 break; 321 308 case CompositeXOR: 322 glEnable(GL_BLEND);323 glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA);309 m_context->enable(GraphicsContext3D::BLEND); 310 m_context->blendFunc(GraphicsContext3D::ONE_MINUS_DST_ALPHA, GraphicsContext3D::ONE_MINUS_SRC_ALPHA); 324 311 break; 325 312 case CompositePlusDarker: 326 313 case CompositeHighlight: 327 314 // unsupported 328 glDisable(GL_BLEND);315 m_context->disable(GraphicsContext3D::BLEND); 329 316 break; 330 317 case CompositePlusLighter: 331 glEnable(GL_BLEND);332 glBlendFunc(GL_ONE, GL_ONE);318 m_context->enable(GraphicsContext3D::BLEND); 319 m_context->blendFunc(GraphicsContext3D::ONE, GraphicsContext3D::ONE); 333 320 break; 334 321 } … … 339 326 { 340 327 if (!m_quadVertices) { 341 GLfloat vertices[] = { 0.0f, 0.0f, 1.0f, 342 1.0f, 0.0f, 1.0f, 343 1.0f, 1.0f, 1.0f, 344 0.0f, 1.0f, 1.0f }; 345 glGenBuffers(1, &m_quadVertices); 346 glBindBuffer(GL_ARRAY_BUFFER, m_quadVertices); 347 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); 328 float vertices[] = { 0.0f, 0.0f, 1.0f, 329 1.0f, 0.0f, 1.0f, 330 1.0f, 1.0f, 1.0f, 331 0.0f, 1.0f, 1.0f }; 332 m_quadVertices = m_context->createBuffer(); 333 RefPtr<Float32Array> vertexArray = Float32Array::create(vertices, sizeof(vertices) / sizeof(float)); 334 m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, m_quadVertices); 335 m_context->bufferData(GraphicsContext3D::ARRAY_BUFFER, vertexArray.get(), GraphicsContext3D::STATIC_DRAW); 348 336 } 349 337 return m_quadVertices; … … 354 342 { 355 343 if (!m_quadIndices) { 356 GLushort indices[] = { 0, 1, 2, 0, 2, 3}; 357 358 glGenBuffers(1, &m_quadIndices); 359 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_quadIndices); 360 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); 344 unsigned short indices[] = { 0, 1, 2, 0, 2, 3}; 345 346 m_quadIndices = m_context->createBuffer(); 347 RefPtr<Uint16Array> indexArray = Uint16Array::create(indices, sizeof(indices) / sizeof(unsigned short)); 348 m_context->bindBuffer(GraphicsContext3D::ELEMENT_ARRAY_BUFFER, m_quadIndices); 349 m_context->bufferData(GraphicsContext3D::ELEMENT_ARRAY_BUFFER, indexArray.get(), GraphicsContext3D::STATIC_DRAW); 361 350 } 362 351 return m_quadIndices; 363 352 } 364 353 365 static GLuint loadShader(GLenumtype, const char* shaderSource)366 { 367 GLuint shader = glCreateShader(type);354 static unsigned loadShader(GraphicsContext3D* context, unsigned type, const char* shaderSource) 355 { 356 unsigned shader = context->createShader(type); 368 357 if (!shader) 369 358 return 0; 370 359 371 glShaderSource(shader, 1, &shaderSource, 0); 372 glCompileShader(shader); 373 GLint compileStatus; 374 glGetShaderiv(shader, GL_COMPILE_STATUS, &compileStatus); 360 String shaderSourceStr(shaderSource); 361 context->shaderSource(shader, shaderSourceStr); 362 context->compileShader(shader); 363 int compileStatus; 364 context->getShaderiv(shader, GraphicsContext3D::COMPILE_STATUS, &compileStatus); 375 365 if (!compileStatus) { 376 int length; 377 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length); 378 OwnArrayPtr<char> log(new char[length]); 379 glGetShaderInfoLog(shader, length, 0, log.get()); 380 LOG_ERROR(log.get()); 381 glDeleteShader(shader); 366 String infoLog = context->getShaderInfoLog(shader); 367 LOG_ERROR(infoLog.utf8().data()); 368 context->deleteShader(shader); 382 369 return 0; 383 370 } … … 388 375 { 389 376 if (!m_simpleProgram) { 390 GLuint vertexShader = loadShader(GL_VERTEX_SHADER,377 unsigned vertexShader = loadShader(m_context, GraphicsContext3D::VERTEX_SHADER, 391 378 "uniform mat3 matrix;\n" 392 379 "uniform vec4 color;\n" … … 397 384 if (!vertexShader) 398 385 return 0; 399 GLuint fragmentShader = loadShader(GL_FRAGMENT_SHADER,386 unsigned fragmentShader = loadShader(m_context, GraphicsContext3D::FRAGMENT_SHADER, 400 387 "precision mediump float;\n" 401 388 "uniform mat3 matrix;\n" … … 406 393 if (!fragmentShader) 407 394 return 0; 408 m_simpleProgram = glCreateProgram();395 m_simpleProgram = m_context->createProgram(); 409 396 if (!m_simpleProgram) 410 397 return 0; 411 glAttachShader(m_simpleProgram, vertexShader);412 glAttachShader(m_simpleProgram, fragmentShader);413 glLinkProgram(m_simpleProgram);414 GLint linkStatus;415 glGetProgramiv(m_simpleProgram, GL_LINK_STATUS, &linkStatus);398 m_context->attachShader(m_simpleProgram, vertexShader); 399 m_context->attachShader(m_simpleProgram, fragmentShader); 400 m_context->linkProgram(m_simpleProgram); 401 int linkStatus; 402 m_context->getProgramiv(m_simpleProgram, GraphicsContext3D::LINK_STATUS, &linkStatus); 416 403 if (!linkStatus) { 417 glDeleteProgram(m_simpleProgram);404 m_context->deleteProgram(m_simpleProgram); 418 405 m_simpleProgram = 0; 419 406 } 420 glDeleteShader(vertexShader);421 glDeleteShader(fragmentShader);422 m_simplePositionLocation = glGetAttribLocation(m_simpleProgram, "position");423 m_simpleMatrixLocation = glGetUniformLocation(m_simpleProgram, "matrix");424 m_simpleColorLocation = glGetUniformLocation(m_simpleProgram, "color");407 m_context->deleteShader(vertexShader); 408 m_context->deleteShader(fragmentShader); 409 m_simplePositionLocation = m_context->getAttribLocation(m_simpleProgram, "position"); 410 m_simpleMatrixLocation = m_context->getUniformLocation(m_simpleProgram, "matrix"); 411 m_simpleColorLocation = m_context->getUniformLocation(m_simpleProgram, "color"); 425 412 } 426 413 return m_simpleProgram; … … 430 417 { 431 418 if (!m_texProgram) { 432 GLuint vertexShader = loadShader(GL_VERTEX_SHADER,419 unsigned vertexShader = loadShader(m_context, GraphicsContext3D::VERTEX_SHADER, 433 420 "uniform mat3 matrix;\n" 434 421 "uniform mat3 texMatrix;\n" … … 441 428 if (!vertexShader) 442 429 return 0; 443 GLuint fragmentShader = loadShader(GL_FRAGMENT_SHADER,430 unsigned fragmentShader = loadShader(m_context, GraphicsContext3D::FRAGMENT_SHADER, 444 431 "precision mediump float;\n" 445 432 "uniform sampler2D sampler;\n" … … 451 438 if (!fragmentShader) 452 439 return 0; 453 m_texProgram = glCreateProgram();440 m_texProgram = m_context->createProgram(); 454 441 if (!m_texProgram) 455 442 return 0; 456 glAttachShader(m_texProgram, vertexShader);457 glAttachShader(m_texProgram, fragmentShader);458 glLinkProgram(m_texProgram);459 GLint linkStatus;460 glGetProgramiv(m_texProgram, GL_LINK_STATUS, &linkStatus);443 m_context->attachShader(m_texProgram, vertexShader); 444 m_context->attachShader(m_texProgram, fragmentShader); 445 m_context->linkProgram(m_texProgram); 446 int linkStatus; 447 m_context->getProgramiv(m_texProgram, GraphicsContext3D::LINK_STATUS, &linkStatus); 461 448 if (!linkStatus) { 462 glDeleteProgram(m_texProgram);449 m_context->deleteProgram(m_texProgram); 463 450 m_texProgram = 0; 464 451 } 465 glDeleteShader(vertexShader);466 glDeleteShader(fragmentShader);467 m_texMatrixLocation = glGetUniformLocation(m_texProgram, "matrix");468 m_texSamplerLocation = glGetUniformLocation(m_texProgram, "sampler");469 m_texTexMatrixLocation = glGetUniformLocation(m_texProgram, "texMatrix");470 m_texPositionLocation = glGetAttribLocation(m_texProgram, "position");471 m_texAlphaLocation = glGetUniformLocation(m_texProgram, "alpha");452 m_context->deleteShader(vertexShader); 453 m_context->deleteShader(fragmentShader); 454 m_texMatrixLocation = m_context->getUniformLocation(m_texProgram, "matrix"); 455 m_texSamplerLocation = m_context->getUniformLocation(m_texProgram, "sampler"); 456 m_texTexMatrixLocation = m_context->getUniformLocation(m_texProgram, "texMatrix"); 457 m_texPositionLocation = m_context->getAttribLocation(m_texProgram, "position"); 458 m_texAlphaLocation = m_context->getUniformLocation(m_texProgram, "alpha"); 472 459 } 473 460 return m_texProgram; … … 480 467 return texture.get(); 481 468 482 texture = GLES2Texture::create( format, width, height);469 texture = GLES2Texture::create(m_context, format, width, height); 483 470 GLES2Texture* t = texture.get(); 484 471 m_textures.set(ptr, texture); … … 495 482 { 496 483 #ifndef NDEBUG 497 GLenumerr;498 while ((err = glGetError()) != GL_NO_ERROR) {484 unsigned err; 485 while ((err = m_context->getError()) != GraphicsContext3D::NO_ERROR) { 499 486 const char* errorStr = "*** UNKNOWN ERROR ***"; 500 487 switch (err) { 501 case G L_INVALID_ENUM:502 errorStr = "G L_INVALID_ENUM";488 case GraphicsContext3D::INVALID_ENUM: 489 errorStr = "GraphicsContext3D::INVALID_ENUM"; 503 490 break; 504 case G L_INVALID_VALUE:505 errorStr = "G L_INVALID_VALUE";491 case GraphicsContext3D::INVALID_VALUE: 492 errorStr = "GraphicsContext3D::INVALID_VALUE"; 506 493 break; 507 case G L_INVALID_OPERATION:508 errorStr = "G L_INVALID_OPERATION";494 case GraphicsContext3D::INVALID_OPERATION: 495 errorStr = "GraphicsContext3D::INVALID_OPERATION"; 509 496 break; 510 case G L_INVALID_FRAMEBUFFER_OPERATION:511 errorStr = "G L_INVALID_FRAMEBUFFER_OPERATION";497 case GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION: 498 errorStr = "GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION"; 512 499 break; 513 case G L_OUT_OF_MEMORY:514 errorStr = "G L_OUT_OF_MEMORY";500 case GraphicsContext3D::OUT_OF_MEMORY: 501 errorStr = "GraphicsContext3D::OUT_OF_MEMORY"; 515 502 break; 516 503 } -
trunk/WebCore/platform/graphics/chromium/GLES2Canvas.h
r64374 r64872 47 47 namespace WebCore { 48 48 49 class Color; 49 50 class FloatRect; 50 class Color; 51 class GLES2Context; 51 class GraphicsContext3D; 52 52 53 53 typedef HashMap<NativeImagePtr, RefPtr<GLES2Texture> > TextureHashMap; … … 55 55 class GLES2Canvas : public Noncopyable { 56 56 public: 57 GLES2Canvas(G LES2Context*, const IntSize&);57 GLES2Canvas(GraphicsContext3D*, const IntSize&); 58 58 ~GLES2Canvas(); 59 59 … … 77 77 void drawTexturedRect(GLES2Texture*, const FloatRect& srcRect, const FloatRect& dstRect, const AffineTransform&, float alpha, ColorSpace, CompositeOperator); 78 78 void drawTexturedRect(GLES2Texture*, const FloatRect& srcRect, const FloatRect& dstRect, ColorSpace, CompositeOperator); 79 G LES2Context* gles2Context() { return m_gles2Context; }79 GraphicsContext3D* context() { return m_context; } 80 80 GLES2Texture* createTexture(NativeImagePtr, GLES2Texture::Format, int width, int height); 81 81 GLES2Texture* getTexture(NativeImagePtr); … … 89 89 unsigned getTexProgram(); 90 90 91 G LES2Context* m_gles2Context;91 GraphicsContext3D* m_context; 92 92 struct State; 93 93 WTF::Vector<State> m_stateStack; -
trunk/WebCore/platform/graphics/chromium/GLES2Texture.cpp
r64046 r64872 35 35 #include "GLES2Texture.h" 36 36 37 #include <GLES2/gl2.h>37 #include "GraphicsContext3D.h" 38 38 39 39 #include <wtf/OwnArrayPtr.h> … … 41 41 namespace WebCore { 42 42 43 GLES2Texture::GLES2Texture(unsigned int textureId, Format format, int width, int height) 44 : m_textureId(textureId) 43 GLES2Texture::GLES2Texture(GraphicsContext3D* context, unsigned textureId, Format format, int width, int height) 44 : m_context(context) 45 , m_textureId(textureId) 45 46 , m_format(format) 46 47 , m_width(width) … … 51 52 GLES2Texture::~GLES2Texture() 52 53 { 53 glDeleteTextures(1, &m_textureId);54 m_context->deleteTexture(m_textureId); 54 55 } 55 56 56 PassRefPtr<GLES2Texture> GLES2Texture::create( Format format, int width, int height)57 PassRefPtr<GLES2Texture> GLES2Texture::create(GraphicsContext3D* context, Format format, int width, int height) 57 58 { 58 GLuint textureId; 59 glGenTextures(1, &textureId); 59 int max; 60 context->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &max); 61 if (width > max || height > max) { 62 ASSERT(!"texture too big"); 63 return 0; 64 } 65 66 unsigned textureId = context->createTexture(); 60 67 if (!textureId) 61 68 return 0; 62 69 63 glBindTexture(GL_TEXTURE_2D, textureId);64 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);70 context->bindTexture(GraphicsContext3D::TEXTURE_2D, textureId); 71 context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D::RGBA, width, height, 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, 0); 65 72 66 int max; 67 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max); 68 if (width > max || height > max) 69 ASSERT(!"texture too big"); 70 71 return adoptRef(new GLES2Texture(textureId, format, width, height)); 73 return adoptRef(new GLES2Texture(context, textureId, format, width, height)); 72 74 } 73 75 … … 77 79 switch (format) { 78 80 case GLES2Texture::RGBA8: 79 *glFormat = G L_RGBA;80 *glType = G L_UNSIGNED_BYTE;81 *glFormat = GraphicsContext3D::RGBA; 82 *glType = GraphicsContext3D::UNSIGNED_BYTE; 81 83 break; 82 84 case GLES2Texture::BGRA8: 83 85 // FIXME: Once we have support for extensions, we should check for EXT_texture_format_BGRA8888, 84 86 // and use that if present. 85 *glFormat = G L_RGBA;86 *glType = G L_UNSIGNED_BYTE;87 *glFormat = GraphicsContext3D::RGBA; 88 *glType = GraphicsContext3D::UNSIGNED_BYTE; 87 89 *swizzle = true; 88 90 break; … … 98 100 bool swizzle; 99 101 convertFormat(m_format, &glFormat, &glType, &swizzle); 100 glBindTexture(GL_TEXTURE_2D, m_textureId);102 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureId); 101 103 if (swizzle) { 102 ASSERT(glFormat == G L_RGBA && glType == GL_UNSIGNED_BYTE);104 ASSERT(glFormat == GraphicsContext3D::RGBA && glType == GraphicsContext3D::UNSIGNED_BYTE); 103 105 // FIXME: This could use PBO's to save doing an extra copy here. 104 106 int size = m_width * m_height; … … 110 112 bufptr[i] = pixel & 0xFF00FF00 | ((pixel & 0x00FF0000) >> 16) | ((pixel & 0x000000FF) << 16); 111 113 } 112 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_width, m_height, glFormat, glType, buf.get());114 m_context->texSubImage2D(GraphicsContext3D::TEXTURE_2D, 0, 0, 0, m_width, m_height, glFormat, glType, buf.get()); 113 115 } else 114 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_width, m_height, glFormat, glType, pixels);116 m_context->texSubImage2D(GraphicsContext3D::TEXTURE_2D, 0, 0, 0, m_width, m_height, glFormat, glType, pixels); 115 117 } 116 118 117 119 void GLES2Texture::bind() 118 120 { 119 glBindTexture(GL_TEXTURE_2D, m_textureId);120 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);121 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);122 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);123 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);121 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureId); 122 m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR); 123 m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR); 124 m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE); 125 m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE); 124 126 } 125 127 -
trunk/WebCore/platform/graphics/chromium/GLES2Texture.h
r64046 r64872 38 38 39 39 namespace WebCore { 40 class GraphicsContext3D; 40 41 41 42 class GLES2Texture : public RefCounted<GLES2Texture> { … … 43 44 ~GLES2Texture(); 44 45 enum Format { RGBA8, BGRA8 }; 45 static PassRefPtr<GLES2Texture> create( Format, int width, int height);46 static PassRefPtr<GLES2Texture> create(GraphicsContext3D*, Format, int width, int height); 46 47 void bind(); 47 48 void load(void* pixels); … … 50 51 int height() const { return m_height; } 51 52 private: 52 GLES2Texture(unsigned int textureId, Format format, int width, int height); 53 unsigned int m_textureId; 53 GLES2Texture(GraphicsContext3D*, unsigned textureId, Format, int width, int height); 54 GraphicsContext3D* m_context; 55 unsigned m_textureId; 54 56 Format m_format; 55 57 int m_width; -
trunk/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp
r64227 r64872 787 787 return; 788 788 789 platformContext()->save();790 791 789 SkRect r = rect; 792 790 if (!isRectSkiaSafe(getCTM(), r)) { … … 802 800 } 803 801 #endif 802 803 platformContext()->save(); 804 804 805 805 platformContext()->prepareForSoftwareDraw(); -
trunk/WebCore/platform/graphics/skia/ImageSkia.cpp
r64374 r64872 415 415 ctxt->platformContext()->prepareForHardwareDraw(); 416 416 GLES2Canvas* gpuCanvas = ctxt->platformContext()->gpuCanvas(); 417 gpuCanvas->gles2Context()->makeCurrent();418 417 GLES2Texture* texture = gpuCanvas->getTexture(bitmap); 419 418 if (!texture) { -
trunk/WebCore/platform/graphics/skia/PlatformContextSkia.cpp
r64584 r64872 31 31 #include "config.h" 32 32 33 #include "PlatformContextSkia.h" 34 35 #include "AffineTransform.h" 33 36 #include "GraphicsContext.h" 34 37 #include "ImageBuffer.h" … … 46 49 47 50 #if USE(GLES2_RENDERING) 51 #include "GraphicsContext3D.h" 48 52 #include "GLES2Canvas.h" 49 #include "GLES2Context.h"50 53 #include "GLES2Texture.h" 51 #include <GLES2/gl2.h>52 54 #endif 53 55 … … 676 678 677 679 #if USE(GLES2_RENDERING) 678 void PlatformContextSkia::setGLES2Context(GLES2Context* context, const IntSize& size) 680 681 void PlatformContextSkia::setGraphicsContext3D(GraphicsContext3D* context, const WebCore::IntSize& size) 679 682 { 680 683 m_useGPU = true; … … 761 764 const SkBitmap& bitmap = m_canvas->getDevice()->accessBitmap(false); 762 765 SkAutoLockPixels lock(bitmap); 763 m_gpuCanvas->gles2Context()->makeCurrent();764 766 // FIXME: Keep a texture around for this rather than constantly creating/destroying one. 765 RefPtr<GLES2Texture> texture = GLES2Texture::create(GLES2Texture::BGRA8, bitmap.width(), bitmap.height()); 767 GraphicsContext3D* context = m_gpuCanvas->context(); 768 RefPtr<GLES2Texture> texture = GLES2Texture::create(context, GLES2Texture::BGRA8, bitmap.width(), bitmap.height()); 766 769 texture->load(bitmap.getPixels()); 767 770 IntRect rect(0, 0, bitmap.width(), bitmap.height()); 768 gpuCanvas()->drawTexturedRect(texture.get(), rect, rect, DeviceColorSpace, op); 771 AffineTransform identity; 772 gpuCanvas()->drawTexturedRect(texture.get(), rect, rect, identity, 1.0, DeviceColorSpace, op); 769 773 } 770 774 … … 773 777 const SkBitmap& bitmap = m_canvas->getDevice()->accessBitmap(true); 774 778 SkAutoLockPixels lock(bitmap); 775 m_gpuCanvas->gles2Context()->makeCurrent();776 779 int width = bitmap.width(), height = bitmap.height(); 777 780 OwnArrayPtr<uint32_t> buf(new uint32_t[width]); 781 GraphicsContext3D* context = m_gpuCanvas->context(); 778 782 // Flips the image vertically. 779 783 for (int y = 0; y < height; ++y) { 780 784 uint32_t* pixels = bitmap.getAddr32(0, y); 781 glReadPixels(0, height - 1 - y, width, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);785 context->readPixels(0, height - 1 - y, width, 1, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, pixels); 782 786 for (int i = 0; i < width; ++i) { 783 787 uint32_t pixel = pixels[i]; -
trunk/WebCore/platform/graphics/skia/PlatformContextSkia.h
r64584 r64872 49 49 enum CompositeOperator; 50 50 class GLES2Canvas; 51 class G LES2Context;51 class GraphicsContext3D; 52 52 #endif 53 53 … … 184 184 #if USE(GLES2_RENDERING) 185 185 bool useGPU() { return m_useGPU; } 186 void setG LES2Context(GLES2Context*, const IntSize&);186 void setGraphicsContext3D(GraphicsContext3D*, const IntSize&); 187 187 GLES2Canvas* gpuCanvas() const { return m_gpuCanvas.get(); } 188 188 #endif
Note: See TracChangeset
for help on using the changeset viewer.