| OLD | NEW |
| 1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 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/output/gl_renderer.h" | 5 #include "cc/output/gl_renderer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 #include "third_party/skia/include/core/SkSurface.h" | 49 #include "third_party/skia/include/core/SkSurface.h" |
| 50 #include "third_party/skia/include/gpu/GrContext.h" | 50 #include "third_party/skia/include/gpu/GrContext.h" |
| 51 #include "third_party/skia/include/gpu/GrTexture.h" | 51 #include "third_party/skia/include/gpu/GrTexture.h" |
| 52 #include "third_party/skia/include/gpu/SkGpuDevice.h" | 52 #include "third_party/skia/include/gpu/SkGpuDevice.h" |
| 53 #include "third_party/skia/include/gpu/SkGrTexturePixelRef.h" | 53 #include "third_party/skia/include/gpu/SkGrTexturePixelRef.h" |
| 54 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" | 54 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" |
| 55 #include "ui/gfx/quad_f.h" | 55 #include "ui/gfx/quad_f.h" |
| 56 #include "ui/gfx/rect_conversions.h" | 56 #include "ui/gfx/rect_conversions.h" |
| 57 | 57 |
| 58 using blink::WebGraphicsContext3D; | 58 using blink::WebGraphicsContext3D; |
| 59 using gpu::gles2::GLES2Interface; |
| 59 | 60 |
| 60 namespace cc { | 61 namespace cc { |
| 61 | 62 |
| 62 namespace { | 63 namespace { |
| 63 | 64 |
| 64 // TODO(epenner): This should probably be moved to output surface. | 65 // TODO(epenner): This should probably be moved to output surface. |
| 65 // | 66 // |
| 66 // This implements a simple fence based on client side swaps. | 67 // This implements a simple fence based on client side swaps. |
| 67 // This is to isolate the ResourceProvider from 'frames' which | 68 // This is to isolate the ResourceProvider from 'frames' which |
| 68 // it shouldn't need to care about, while still allowing us to | 69 // it shouldn't need to care about, while still allowing us to |
| 69 // enforce good texture recycling behavior strictly throughout | 70 // enforce good texture recycling behavior strictly throughout |
| 70 // the compositor (don't recycle a texture while it's in use). | 71 // the compositor (don't recycle a texture while it's in use). |
| 71 class SimpleSwapFence : public ResourceProvider::Fence { | 72 class SimpleSwapFence : public ResourceProvider::Fence { |
| 72 public: | 73 public: |
| 73 SimpleSwapFence() : has_passed_(false) {} | 74 SimpleSwapFence() : has_passed_(false) {} |
| 74 virtual bool HasPassed() OVERRIDE { return has_passed_; } | 75 virtual bool HasPassed() OVERRIDE { return has_passed_; } |
| 75 void SetHasPassed() { has_passed_ = true; } | 76 void SetHasPassed() { has_passed_ = true; } |
| 77 |
| 76 private: | 78 private: |
| 77 virtual ~SimpleSwapFence() {} | 79 virtual ~SimpleSwapFence() {} |
| 78 bool has_passed_; | 80 bool has_passed_; |
| 79 }; | 81 }; |
| 80 | 82 |
| 81 bool NeedsIOSurfaceReadbackWorkaround() { | 83 bool NeedsIOSurfaceReadbackWorkaround() { |
| 82 #if defined(OS_MACOSX) | 84 #if defined(OS_MACOSX) |
| 83 // This isn't strictly required in DumpRenderTree-mode when Mesa is used, | 85 // This isn't strictly required in DumpRenderTree-mode when Mesa is used, |
| 84 // but it doesn't seem to hurt. | 86 // but it doesn't seem to hurt. |
| 85 return true; | 87 return true; |
| 86 #else | 88 #else |
| 87 return false; | 89 return false; |
| 88 #endif | 90 #endif |
| 89 } | 91 } |
| 90 | 92 |
| 91 Float4 UVTransform(const TextureDrawQuad* quad) { | 93 Float4 UVTransform(const TextureDrawQuad* quad) { |
| 92 gfx::PointF uv0 = quad->uv_top_left; | 94 gfx::PointF uv0 = quad->uv_top_left; |
| 93 gfx::PointF uv1 = quad->uv_bottom_right; | 95 gfx::PointF uv1 = quad->uv_bottom_right; |
| 94 Float4 xform = { { uv0.x(), uv0.y(), uv1.x() - uv0.x(), uv1.y() - uv0.y() } }; | 96 Float4 xform = {{uv0.x(), uv0.y(), uv1.x() - uv0.x(), uv1.y() - uv0.y()}}; |
| 95 if (quad->flipped) { | 97 if (quad->flipped) { |
| 96 xform.data[1] = 1.0f - xform.data[1]; | 98 xform.data[1] = 1.0f - xform.data[1]; |
| 97 xform.data[3] = -xform.data[3]; | 99 xform.data[3] = -xform.data[3]; |
| 98 } | 100 } |
| 99 return xform; | 101 return xform; |
| 100 } | 102 } |
| 101 | 103 |
| 102 Float4 PremultipliedColor(SkColor color) { | 104 Float4 PremultipliedColor(SkColor color) { |
| 103 const float factor = 1.0f / 255.0f; | 105 const float factor = 1.0f / 255.0f; |
| 104 const float alpha = SkColorGetA(color) * factor; | 106 const float alpha = SkColorGetA(color) * factor; |
| 105 | 107 |
| 106 Float4 result = { { | 108 Float4 result = { |
| 107 SkColorGetR(color) * factor * alpha, | 109 {SkColorGetR(color) * factor * alpha, SkColorGetG(color) * factor * alpha, |
| 108 SkColorGetG(color) * factor * alpha, | 110 SkColorGetB(color) * factor * alpha, alpha}}; |
| 109 SkColorGetB(color) * factor * alpha, | |
| 110 alpha | |
| 111 } }; | |
| 112 return result; | 111 return result; |
| 113 } | 112 } |
| 114 | 113 |
| 115 SamplerType SamplerTypeFromTextureTarget(GLenum target) { | 114 SamplerType SamplerTypeFromTextureTarget(GLenum target) { |
| 116 switch (target) { | 115 switch (target) { |
| 117 case GL_TEXTURE_2D: | 116 case GL_TEXTURE_2D: |
| 118 return SamplerType2D; | 117 return SamplerType2D; |
| 119 case GL_TEXTURE_RECTANGLE_ARB: | 118 case GL_TEXTURE_RECTANGLE_ARB: |
| 120 return SamplerType2DRect; | 119 return SamplerType2DRect; |
| 121 case GL_TEXTURE_EXTERNAL_OES: | 120 case GL_TEXTURE_EXTERNAL_OES: |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 scissor_rect_needs_reset_(true), | 176 scissor_rect_needs_reset_(true), |
| 178 stencil_shadow_(false), | 177 stencil_shadow_(false), |
| 179 blend_shadow_(false), | 178 blend_shadow_(false), |
| 180 highp_threshold_min_(highp_threshold_min), | 179 highp_threshold_min_(highp_threshold_min), |
| 181 highp_threshold_cache_(0), | 180 highp_threshold_cache_(0), |
| 182 on_demand_tile_raster_resource_id_(0) { | 181 on_demand_tile_raster_resource_id_(0) { |
| 183 DCHECK(context_); | 182 DCHECK(context_); |
| 184 DCHECK(context_support_); | 183 DCHECK(context_support_); |
| 185 | 184 |
| 186 ContextProvider::Capabilities context_caps = | 185 ContextProvider::Capabilities context_caps = |
| 187 output_surface_->context_provider()->ContextCapabilities(); | 186 output_surface_->context_provider()->ContextCapabilities(); |
| 188 | 187 |
| 189 capabilities_.using_partial_swap = | 188 capabilities_.using_partial_swap = |
| 190 settings_->partial_swap_enabled && context_caps.post_sub_buffer; | 189 settings_->partial_swap_enabled && context_caps.post_sub_buffer; |
| 191 | 190 |
| 192 DCHECK(!context_caps.iosurface || context_caps.texture_rectangle); | 191 DCHECK(!context_caps.iosurface || context_caps.texture_rectangle); |
| 193 | 192 |
| 194 capabilities_.using_egl_image = context_caps.egl_image_external; | 193 capabilities_.using_egl_image = context_caps.egl_image_external; |
| 195 | 194 |
| 196 capabilities_.max_texture_size = resource_provider_->max_texture_size(); | 195 capabilities_.max_texture_size = resource_provider_->max_texture_size(); |
| 197 capabilities_.best_texture_format = resource_provider_->best_texture_format(); | 196 capabilities_.best_texture_format = resource_provider_->best_texture_format(); |
| 198 | 197 |
| 199 // The updater can access textures while the GLRenderer is using them. | 198 // The updater can access textures while the GLRenderer is using them. |
| 200 capabilities_.allow_partial_texture_updates = true; | 199 capabilities_.allow_partial_texture_updates = true; |
| 201 | 200 |
| 202 // Check for texture fast paths. Currently we always use MO8 textures, | 201 // Check for texture fast paths. Currently we always use MO8 textures, |
| 203 // so we only need to avoid POT textures if we have an NPOT fast-path. | 202 // so we only need to avoid POT textures if we have an NPOT fast-path. |
| 204 capabilities_.avoid_pow2_textures = context_caps.fast_npot_mo8_textures; | 203 capabilities_.avoid_pow2_textures = context_caps.fast_npot_mo8_textures; |
| 205 | 204 |
| 206 capabilities_.using_offscreen_context3d = true; | 205 capabilities_.using_offscreen_context3d = true; |
| 207 | 206 |
| 208 capabilities_.using_map_image = | 207 capabilities_.using_map_image = |
| 209 settings_->use_map_image && context_caps.map_image; | 208 settings_->use_map_image && context_caps.map_image; |
| 210 | 209 |
| 211 capabilities_.using_discard_framebuffer = | 210 capabilities_.using_discard_framebuffer = context_caps.discard_framebuffer; |
| 212 context_caps.discard_framebuffer; | |
| 213 | 211 |
| 214 InitializeSharedObjects(); | 212 InitializeSharedObjects(); |
| 215 } | 213 } |
| 216 | 214 |
| 217 GLRenderer::~GLRenderer() { | 215 GLRenderer::~GLRenderer() { |
| 218 while (!pending_async_read_pixels_.empty()) { | 216 while (!pending_async_read_pixels_.empty()) { |
| 219 PendingAsyncReadPixels* pending_read = pending_async_read_pixels_.back(); | 217 PendingAsyncReadPixels* pending_read = pending_async_read_pixels_.back(); |
| 220 pending_read->finished_read_pixels_callback.Cancel(); | 218 pending_read->finished_read_pixels_callback.Cancel(); |
| 221 pending_async_read_pixels_.pop_back(); | 219 pending_async_read_pixels_.pop_back(); |
| 222 } | 220 } |
| 223 | 221 |
| 224 CleanupSharedObjects(); | 222 CleanupSharedObjects(); |
| 225 } | 223 } |
| 226 | 224 |
| 227 const RendererCapabilities& GLRenderer::Capabilities() const { | 225 const RendererCapabilities& GLRenderer::Capabilities() const { |
| 228 return capabilities_; | 226 return capabilities_; |
| 229 } | 227 } |
| 230 | 228 |
| 231 WebGraphicsContext3D* GLRenderer::Context() { return context_; } | 229 WebGraphicsContext3D* GLRenderer::Context() { return context_; } |
| 232 | 230 |
| 233 void GLRenderer::DebugGLCall(WebGraphicsContext3D* context, | 231 void GLRenderer::DebugGLCall(GLES2Interface* gl, |
| 234 const char* command, | 232 const char* command, |
| 235 const char* file, | 233 const char* file, |
| 236 int line) { | 234 int line) { |
| 237 unsigned error = context->getError(); | 235 GLuint error = gl->GetError(); |
| 238 if (error != GL_NO_ERROR) | 236 if (error != GL_NO_ERROR) |
| 239 LOG(ERROR) << "GL command failed: File: " << file << "\n\tLine " << line | 237 LOG(ERROR) << "GL command failed: File: " << file << "\n\tLine " << line |
| 240 << "\n\tcommand: " << command << ", error " | 238 << "\n\tcommand: " << command << ", error " |
| 241 << static_cast<int>(error) << "\n"; | 239 << static_cast<int>(error) << "\n"; |
| 242 } | 240 } |
| 243 | 241 |
| 244 void GLRenderer::SetVisible(bool visible) { | 242 void GLRenderer::SetVisible(bool visible) { |
| 245 if (visible_ == visible) | 243 if (visible_ == visible) |
| 246 return; | 244 return; |
| 247 visible_ = visible; | 245 visible_ = visible; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 267 void GLRenderer::DiscardPixels(bool has_external_stencil_test, | 265 void GLRenderer::DiscardPixels(bool has_external_stencil_test, |
| 268 bool draw_rect_covers_full_surface) { | 266 bool draw_rect_covers_full_surface) { |
| 269 if (has_external_stencil_test || !draw_rect_covers_full_surface || | 267 if (has_external_stencil_test || !draw_rect_covers_full_surface || |
| 270 !capabilities_.using_discard_framebuffer) | 268 !capabilities_.using_discard_framebuffer) |
| 271 return; | 269 return; |
| 272 bool using_default_framebuffer = | 270 bool using_default_framebuffer = |
| 273 !current_framebuffer_lock_ && | 271 !current_framebuffer_lock_ && |
| 274 output_surface_->capabilities().uses_default_gl_framebuffer; | 272 output_surface_->capabilities().uses_default_gl_framebuffer; |
| 275 GLenum attachments[] = {static_cast<GLenum>( | 273 GLenum attachments[] = {static_cast<GLenum>( |
| 276 using_default_framebuffer ? GL_COLOR_EXT : GL_COLOR_ATTACHMENT0_EXT)}; | 274 using_default_framebuffer ? GL_COLOR_EXT : GL_COLOR_ATTACHMENT0_EXT)}; |
| 277 context_->discardFramebufferEXT( | 275 gl_->DiscardFramebufferEXT( |
| 278 GL_FRAMEBUFFER, arraysize(attachments), attachments); | 276 GL_FRAMEBUFFER, arraysize(attachments), attachments); |
| 279 } | 277 } |
| 280 | 278 |
| 281 void GLRenderer::ClearFramebuffer(DrawingFrame* frame, | 279 void GLRenderer::ClearFramebuffer(DrawingFrame* frame, |
| 282 bool has_external_stencil_test) { | 280 bool has_external_stencil_test) { |
| 283 // It's unsafe to clear when we have a stencil test because glClear ignores | 281 // It's unsafe to clear when we have a stencil test because glClear ignores |
| 284 // stencil. | 282 // stencil. |
| 285 if (has_external_stencil_test) { | 283 if (has_external_stencil_test) { |
| 286 DCHECK(!frame->current_render_pass->has_transparent_background); | 284 DCHECK(!frame->current_render_pass->has_transparent_background); |
| 287 return; | 285 return; |
| 288 } | 286 } |
| 289 | 287 |
| 290 // On DEBUG builds, opaque render passes are cleared to blue to easily see | 288 // On DEBUG builds, opaque render passes are cleared to blue to easily see |
| 291 // regions that were not drawn on the screen. | 289 // regions that were not drawn on the screen. |
| 292 if (frame->current_render_pass->has_transparent_background) | 290 if (frame->current_render_pass->has_transparent_background) |
| 293 GLC(context_, context_->clearColor(0, 0, 0, 0)); | 291 GLC(gl_, gl_->ClearColor(0, 0, 0, 0)); |
| 294 else | 292 else |
| 295 GLC(context_, context_->clearColor(0, 0, 1, 1)); | 293 GLC(gl_, gl_->ClearColor(0, 0, 1, 1)); |
| 296 | 294 |
| 297 bool always_clear = false; | 295 bool always_clear = false; |
| 298 #ifndef NDEBUG | 296 #ifndef NDEBUG |
| 299 always_clear = true; | 297 always_clear = true; |
| 300 #endif | 298 #endif |
| 301 if (always_clear || frame->current_render_pass->has_transparent_background) { | 299 if (always_clear || frame->current_render_pass->has_transparent_background) { |
| 302 GLbitfield clear_bits = GL_COLOR_BUFFER_BIT; | 300 GLbitfield clear_bits = GL_COLOR_BUFFER_BIT; |
| 303 if (always_clear) | 301 if (always_clear) |
| 304 clear_bits |= GL_STENCIL_BUFFER_BIT; | 302 clear_bits |= GL_STENCIL_BUFFER_BIT; |
| 305 context_->clear(clear_bits); | 303 gl_->Clear(clear_bits); |
| 306 } | 304 } |
| 307 } | 305 } |
| 308 | 306 |
| 309 void GLRenderer::BeginDrawingFrame(DrawingFrame* frame) { | 307 void GLRenderer::BeginDrawingFrame(DrawingFrame* frame) { |
| 310 if (frame->device_viewport_rect.IsEmpty()) | 308 if (frame->device_viewport_rect.IsEmpty()) |
| 311 return; | 309 return; |
| 312 | 310 |
| 313 TRACE_EVENT0("cc", "GLRenderer::BeginDrawingFrame"); | 311 TRACE_EVENT0("cc", "GLRenderer::BeginDrawingFrame"); |
| 314 | 312 |
| 315 ReinitializeGLState(); | 313 ReinitializeGLState(); |
| 316 } | 314 } |
| 317 | 315 |
| 318 void GLRenderer::DoNoOp() { | 316 void GLRenderer::DoNoOp() { |
| 319 GLC(context_, context_->bindFramebuffer(GL_FRAMEBUFFER, 0)); | 317 GLC(gl_, gl_->BindFramebuffer(GL_FRAMEBUFFER, 0)); |
| 320 GLC(context_, context_->flush()); | 318 GLC(gl_, gl_->Flush()); |
| 321 } | 319 } |
| 322 | 320 |
| 323 void GLRenderer::DoDrawQuad(DrawingFrame* frame, const DrawQuad* quad) { | 321 void GLRenderer::DoDrawQuad(DrawingFrame* frame, const DrawQuad* quad) { |
| 324 DCHECK(quad->rect.Contains(quad->visible_rect)); | 322 DCHECK(quad->rect.Contains(quad->visible_rect)); |
| 325 if (quad->material != DrawQuad::TEXTURE_CONTENT) { | 323 if (quad->material != DrawQuad::TEXTURE_CONTENT) { |
| 326 FlushTextureQuadCache(); | 324 FlushTextureQuadCache(); |
| 327 } | 325 } |
| 328 | 326 |
| 329 switch (quad->material) { | 327 switch (quad->material) { |
| 330 case DrawQuad::INVALID: | 328 case DrawQuad::INVALID: |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 | 363 |
| 366 void GLRenderer::DrawCheckerboardQuad(const DrawingFrame* frame, | 364 void GLRenderer::DrawCheckerboardQuad(const DrawingFrame* frame, |
| 367 const CheckerboardDrawQuad* quad) { | 365 const CheckerboardDrawQuad* quad) { |
| 368 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 366 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 369 | 367 |
| 370 const TileCheckerboardProgram* program = GetTileCheckerboardProgram(); | 368 const TileCheckerboardProgram* program = GetTileCheckerboardProgram(); |
| 371 DCHECK(program && (program->initialized() || IsContextLost())); | 369 DCHECK(program && (program->initialized() || IsContextLost())); |
| 372 SetUseProgram(program->program()); | 370 SetUseProgram(program->program()); |
| 373 | 371 |
| 374 SkColor color = quad->color; | 372 SkColor color = quad->color; |
| 375 GLC(Context(), | 373 GLC(gl_, |
| 376 Context()->uniform4f(program->fragment_shader().color_location(), | 374 gl_->Uniform4f(program->fragment_shader().color_location(), |
| 377 SkColorGetR(color) * (1.0f / 255.0f), | 375 SkColorGetR(color) * (1.0f / 255.0f), |
| 378 SkColorGetG(color) * (1.0f / 255.0f), | 376 SkColorGetG(color) * (1.0f / 255.0f), |
| 379 SkColorGetB(color) * (1.0f / 255.0f), | 377 SkColorGetB(color) * (1.0f / 255.0f), |
| 380 1)); | 378 1)); |
| 381 | 379 |
| 382 const int checkerboard_width = 16; | 380 const int checkerboard_width = 16; |
| 383 float frequency = 1.0f / checkerboard_width; | 381 float frequency = 1.0f / checkerboard_width; |
| 384 | 382 |
| 385 gfx::Rect tile_rect = quad->rect; | 383 gfx::Rect tile_rect = quad->rect; |
| 386 float tex_offset_x = tile_rect.x() % checkerboard_width; | 384 float tex_offset_x = tile_rect.x() % checkerboard_width; |
| 387 float tex_offset_y = tile_rect.y() % checkerboard_width; | 385 float tex_offset_y = tile_rect.y() % checkerboard_width; |
| 388 float tex_scale_x = tile_rect.width(); | 386 float tex_scale_x = tile_rect.width(); |
| 389 float tex_scale_y = tile_rect.height(); | 387 float tex_scale_y = tile_rect.height(); |
| 390 GLC(Context(), | 388 GLC(gl_, |
| 391 Context()->uniform4f(program->fragment_shader().tex_transform_location(), | 389 gl_->Uniform4f(program->fragment_shader().tex_transform_location(), |
| 392 tex_offset_x, | 390 tex_offset_x, |
| 393 tex_offset_y, | 391 tex_offset_y, |
| 394 tex_scale_x, | 392 tex_scale_x, |
| 395 tex_scale_y)); | 393 tex_scale_y)); |
| 396 | 394 |
| 397 GLC(Context(), | 395 GLC(gl_, |
| 398 Context()->uniform1f(program->fragment_shader().frequency_location(), | 396 gl_->Uniform1f(program->fragment_shader().frequency_location(), |
| 399 frequency)); | 397 frequency)); |
| 400 | 398 |
| 401 SetShaderOpacity(quad->opacity(), | 399 SetShaderOpacity(quad->opacity(), |
| 402 program->fragment_shader().alpha_location()); | 400 program->fragment_shader().alpha_location()); |
| 403 DrawQuadGeometry(frame, | 401 DrawQuadGeometry(frame, |
| 404 quad->quadTransform(), | 402 quad->quadTransform(), |
| 405 quad->rect, | 403 quad->rect, |
| 406 program->vertex_shader().matrix_location()); | 404 program->vertex_shader().matrix_location()); |
| 407 } | 405 } |
| 408 | 406 |
| 409 void GLRenderer::DrawDebugBorderQuad(const DrawingFrame* frame, | 407 void GLRenderer::DrawDebugBorderQuad(const DrawingFrame* frame, |
| 410 const DebugBorderDrawQuad* quad) { | 408 const DebugBorderDrawQuad* quad) { |
| 411 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 409 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 412 | 410 |
| 413 static float gl_matrix[16]; | 411 static float gl_matrix[16]; |
| 414 const DebugBorderProgram* program = GetDebugBorderProgram(); | 412 const DebugBorderProgram* program = GetDebugBorderProgram(); |
| 415 DCHECK(program && (program->initialized() || IsContextLost())); | 413 DCHECK(program && (program->initialized() || IsContextLost())); |
| 416 SetUseProgram(program->program()); | 414 SetUseProgram(program->program()); |
| 417 | 415 |
| 418 // Use the full quad_rect for debug quads to not move the edges based on | 416 // Use the full quad_rect for debug quads to not move the edges based on |
| 419 // partial swaps. | 417 // partial swaps. |
| 420 gfx::Rect layer_rect = quad->rect; | 418 gfx::Rect layer_rect = quad->rect; |
| 421 gfx::Transform render_matrix = quad->quadTransform(); | 419 gfx::Transform render_matrix = quad->quadTransform(); |
| 422 render_matrix.Translate(0.5f * layer_rect.width() + layer_rect.x(), | 420 render_matrix.Translate(0.5f * layer_rect.width() + layer_rect.x(), |
| 423 0.5f * layer_rect.height() + layer_rect.y()); | 421 0.5f * layer_rect.height() + layer_rect.y()); |
| 424 render_matrix.Scale(layer_rect.width(), layer_rect.height()); | 422 render_matrix.Scale(layer_rect.width(), layer_rect.height()); |
| 425 GLRenderer::ToGLMatrix(&gl_matrix[0], | 423 GLRenderer::ToGLMatrix(&gl_matrix[0], |
| 426 frame->projection_matrix * render_matrix); | 424 frame->projection_matrix * render_matrix); |
| 427 GLC(Context(), | 425 GLC(gl_, |
| 428 Context()->uniformMatrix4fv( | 426 gl_->UniformMatrix4fv( |
| 429 program->vertex_shader().matrix_location(), 1, false, &gl_matrix[0])); | 427 program->vertex_shader().matrix_location(), 1, false, &gl_matrix[0])); |
| 430 | 428 |
| 431 SkColor color = quad->color; | 429 SkColor color = quad->color; |
| 432 float alpha = SkColorGetA(color) * (1.0f / 255.0f); | 430 float alpha = SkColorGetA(color) * (1.0f / 255.0f); |
| 433 | 431 |
| 434 GLC(Context(), | 432 GLC(gl_, |
| 435 Context()->uniform4f(program->fragment_shader().color_location(), | 433 gl_->Uniform4f(program->fragment_shader().color_location(), |
| 436 (SkColorGetR(color) * (1.0f / 255.0f)) * alpha, | 434 (SkColorGetR(color) * (1.0f / 255.0f)) * alpha, |
| 437 (SkColorGetG(color) * (1.0f / 255.0f)) * alpha, | 435 (SkColorGetG(color) * (1.0f / 255.0f)) * alpha, |
| 438 (SkColorGetB(color) * (1.0f / 255.0f)) * alpha, | 436 (SkColorGetB(color) * (1.0f / 255.0f)) * alpha, |
| 439 alpha)); | 437 alpha)); |
| 440 | 438 |
| 441 GLC(Context(), Context()->lineWidth(quad->width)); | 439 GLC(gl_, gl_->LineWidth(quad->width)); |
| 442 | 440 |
| 443 // The indices for the line are stored in the same array as the triangle | 441 // The indices for the line are stored in the same array as the triangle |
| 444 // indices. | 442 // indices. |
| 445 GLC(Context(), | 443 GLC(gl_, gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0)); |
| 446 Context()->drawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0)); | |
| 447 } | 444 } |
| 448 | 445 |
| 449 static SkBitmap ApplyImageFilter(GLRenderer* renderer, | 446 static SkBitmap ApplyImageFilter(GLRenderer* renderer, |
| 450 ContextProvider* offscreen_contexts, | 447 ContextProvider* offscreen_contexts, |
| 451 gfx::Point origin, | 448 gfx::Point origin, |
| 452 SkImageFilter* filter, | 449 SkImageFilter* filter, |
| 453 ScopedResource* source_texture_resource) { | 450 ScopedResource* source_texture_resource) { |
| 454 if (!filter) | 451 if (!filter) |
| 455 return SkBitmap(); | 452 return SkBitmap(); |
| 456 | 453 |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 scoped_ptr<ScopedResource> device_background_texture = | 710 scoped_ptr<ScopedResource> device_background_texture = |
| 714 ScopedResource::Create(resource_provider_); | 711 ScopedResource::Create(resource_provider_); |
| 715 // The TextureUsageFramebuffer hint makes ResourceProvider avoid immutable | 712 // The TextureUsageFramebuffer hint makes ResourceProvider avoid immutable |
| 716 // storage allocation (texStorage2DEXT) for this texture. copyTexImage2D fails | 713 // storage allocation (texStorage2DEXT) for this texture. copyTexImage2D fails |
| 717 // when called on a texture having immutable storage. | 714 // when called on a texture having immutable storage. |
| 718 device_background_texture->Allocate( | 715 device_background_texture->Allocate( |
| 719 window_rect.size(), ResourceProvider::TextureUsageFramebuffer, RGBA_8888); | 716 window_rect.size(), ResourceProvider::TextureUsageFramebuffer, RGBA_8888); |
| 720 { | 717 { |
| 721 ResourceProvider::ScopedWriteLockGL lock(resource_provider_, | 718 ResourceProvider::ScopedWriteLockGL lock(resource_provider_, |
| 722 device_background_texture->id()); | 719 device_background_texture->id()); |
| 723 GetFramebufferTexture(lock.texture_id(), | 720 GetFramebufferTexture( |
| 724 device_background_texture->format(), | 721 lock.texture_id(), device_background_texture->format(), window_rect); |
| 725 window_rect); | |
| 726 } | 722 } |
| 727 | 723 |
| 728 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( | 724 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( |
| 729 quad->background_filters, device_background_texture->size()); | 725 quad->background_filters, device_background_texture->size()); |
| 730 | 726 |
| 731 SkBitmap filtered_device_background; | 727 SkBitmap filtered_device_background; |
| 732 if (apply_background_filters) { | 728 if (apply_background_filters) { |
| 733 filtered_device_background = | 729 filtered_device_background = |
| 734 ApplyImageFilter(this, | 730 ApplyImageFilter(this, |
| 735 frame->offscreen_context_provider, | 731 frame->offscreen_context_provider, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 766 gfx::Transform device_to_framebuffer_transform; | 762 gfx::Transform device_to_framebuffer_transform; |
| 767 device_to_framebuffer_transform.Translate( | 763 device_to_framebuffer_transform.Translate( |
| 768 quad->rect.width() * 0.5f + quad->rect.x(), | 764 quad->rect.width() * 0.5f + quad->rect.x(), |
| 769 quad->rect.height() * 0.5f + quad->rect.y()); | 765 quad->rect.height() * 0.5f + quad->rect.y()); |
| 770 device_to_framebuffer_transform.Scale(quad->rect.width(), | 766 device_to_framebuffer_transform.Scale(quad->rect.width(), |
| 771 quad->rect.height()); | 767 quad->rect.height()); |
| 772 device_to_framebuffer_transform.PreconcatTransform( | 768 device_to_framebuffer_transform.PreconcatTransform( |
| 773 contents_device_transform_inverse); | 769 contents_device_transform_inverse); |
| 774 | 770 |
| 775 #ifndef NDEBUG | 771 #ifndef NDEBUG |
| 776 GLC(Context(), Context()->clearColor(0, 0, 1, 1)); | 772 GLC(gl_, gl_->ClearColor(0, 0, 1, 1)); |
| 777 Context()->clear(GL_COLOR_BUFFER_BIT); | 773 gl_->Clear(GL_COLOR_BUFFER_BIT); |
| 778 #endif | 774 #endif |
| 779 | 775 |
| 780 // The filtered_deveice_background_texture is oriented the same as the frame | 776 // The filtered_deveice_background_texture is oriented the same as the frame |
| 781 // buffer. The transform we are copying with has a vertical flip, as well as | 777 // buffer. The transform we are copying with has a vertical flip, as well as |
| 782 // the |device_to_framebuffer_transform|, which cancel each other out. So do | 778 // the |device_to_framebuffer_transform|, which cancel each other out. So do |
| 783 // not flip the contents in the shader to maintain orientation. | 779 // not flip the contents in the shader to maintain orientation. |
| 784 bool flip_vertically = false; | 780 bool flip_vertically = false; |
| 785 | 781 |
| 786 CopyTextureToFramebuffer(frame, | 782 CopyTextureToFramebuffer(frame, |
| 787 filtered_device_background_texture_id, | 783 filtered_device_background_texture_id, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 flip_vertically); | 899 flip_vertically); |
| 904 } | 900 } |
| 905 | 901 |
| 906 bool clipped = false; | 902 bool clipped = false; |
| 907 gfx::QuadF device_quad = MathUtil::MapQuad( | 903 gfx::QuadF device_quad = MathUtil::MapQuad( |
| 908 contents_device_transform, SharedGeometryQuad(), &clipped); | 904 contents_device_transform, SharedGeometryQuad(), &clipped); |
| 909 LayerQuad device_layer_bounds(gfx::QuadF(device_quad.BoundingBox())); | 905 LayerQuad device_layer_bounds(gfx::QuadF(device_quad.BoundingBox())); |
| 910 LayerQuad device_layer_edges(device_quad); | 906 LayerQuad device_layer_edges(device_quad); |
| 911 | 907 |
| 912 // Use anti-aliasing programs only when necessary. | 908 // Use anti-aliasing programs only when necessary. |
| 913 bool use_aa = !clipped && | 909 bool use_aa = |
| 914 (!device_quad.IsRectilinear() || | 910 !clipped && (!device_quad.IsRectilinear() || |
| 915 !gfx::IsNearestRectWithinDistance(device_quad.BoundingBox(), | 911 !gfx::IsNearestRectWithinDistance(device_quad.BoundingBox(), |
| 916 kAntiAliasingEpsilon)); | 912 kAntiAliasingEpsilon)); |
| 917 if (use_aa) { | 913 if (use_aa) { |
| 918 device_layer_bounds.InflateAntiAliasingDistance(); | 914 device_layer_bounds.InflateAntiAliasingDistance(); |
| 919 device_layer_edges.InflateAntiAliasingDistance(); | 915 device_layer_edges.InflateAntiAliasingDistance(); |
| 920 } | 916 } |
| 921 | 917 |
| 922 scoped_ptr<ResourceProvider::ScopedReadLockGL> mask_resource_lock; | 918 scoped_ptr<ResourceProvider::ScopedReadLockGL> mask_resource_lock; |
| 923 unsigned mask_texture_id = 0; | 919 unsigned mask_texture_id = 0; |
| 924 if (quad->mask_resource_id) { | 920 if (quad->mask_resource_id) { |
| 925 mask_resource_lock.reset(new ResourceProvider::ScopedReadLockGL( | 921 mask_resource_lock.reset(new ResourceProvider::ScopedReadLockGL( |
| 926 resource_provider_, quad->mask_resource_id)); | 922 resource_provider_, quad->mask_resource_id)); |
| 927 mask_texture_id = mask_resource_lock->texture_id(); | 923 mask_texture_id = mask_resource_lock->texture_id(); |
| 928 } | 924 } |
| 929 | 925 |
| 930 // TODO(danakj): use the background_texture and blend the background in with | 926 // TODO(danakj): use the background_texture and blend the background in with |
| 931 // this draw instead of having a separate copy of the background texture. | 927 // this draw instead of having a separate copy of the background texture. |
| 932 | 928 |
| 933 scoped_ptr<ResourceProvider::ScopedSamplerGL> contents_resource_lock; | 929 scoped_ptr<ResourceProvider::ScopedSamplerGL> contents_resource_lock; |
| 934 if (filter_bitmap.getTexture()) { | 930 if (filter_bitmap.getTexture()) { |
| 935 GrTexture* texture = | 931 GrTexture* texture = |
| 936 reinterpret_cast<GrTexture*>(filter_bitmap.getTexture()); | 932 reinterpret_cast<GrTexture*>(filter_bitmap.getTexture()); |
| 937 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(Context())); | 933 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(Context())); |
| 938 Context()->bindTexture(GL_TEXTURE_2D, texture->getTextureHandle()); | 934 gl_->BindTexture(GL_TEXTURE_2D, texture->getTextureHandle()); |
| 939 } else { | 935 } else { |
| 940 contents_resource_lock = make_scoped_ptr( | 936 contents_resource_lock = |
| 941 new ResourceProvider::ScopedSamplerGL(resource_provider_, | 937 make_scoped_ptr(new ResourceProvider::ScopedSamplerGL( |
| 942 contents_texture->id(), | 938 resource_provider_, contents_texture->id(), GL_LINEAR)); |
| 943 GL_LINEAR)); | |
| 944 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), | 939 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), |
| 945 contents_resource_lock->target()); | 940 contents_resource_lock->target()); |
| 946 } | 941 } |
| 947 | 942 |
| 948 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 943 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 949 gl_, &highp_threshold_cache_, highp_threshold_min_, | 944 gl_, |
| 945 &highp_threshold_cache_, |
| 946 highp_threshold_min_, |
| 950 quad->shared_quad_state->visible_content_rect.bottom_right()); | 947 quad->shared_quad_state->visible_content_rect.bottom_right()); |
| 951 | 948 |
| 952 int shader_quad_location = -1; | 949 int shader_quad_location = -1; |
| 953 int shader_edge_location = -1; | 950 int shader_edge_location = -1; |
| 954 int shader_viewport_location = -1; | 951 int shader_viewport_location = -1; |
| 955 int shader_mask_sampler_location = -1; | 952 int shader_mask_sampler_location = -1; |
| 956 int shader_mask_tex_coord_scale_location = -1; | 953 int shader_mask_tex_coord_scale_location = -1; |
| 957 int shader_mask_tex_coord_offset_location = -1; | 954 int shader_mask_tex_coord_offset_location = -1; |
| 958 int shader_matrix_location = -1; | 955 int shader_matrix_location = -1; |
| 959 int shader_alpha_location = -1; | 956 int shader_alpha_location = -1; |
| 960 int shader_color_matrix_location = -1; | 957 int shader_color_matrix_location = -1; |
| 961 int shader_color_offset_location = -1; | 958 int shader_color_offset_location = -1; |
| 962 int shader_tex_transform_location = -1; | 959 int shader_tex_transform_location = -1; |
| 963 | 960 |
| 964 if (use_aa && mask_texture_id && !use_color_matrix) { | 961 if (use_aa && mask_texture_id && !use_color_matrix) { |
| 965 const RenderPassMaskProgramAA* program = | 962 const RenderPassMaskProgramAA* program = |
| 966 GetRenderPassMaskProgramAA(tex_coord_precision); | 963 GetRenderPassMaskProgramAA(tex_coord_precision); |
| 967 SetUseProgram(program->program()); | 964 SetUseProgram(program->program()); |
| 968 GLC(Context(), | 965 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 969 Context()->uniform1i(program->fragment_shader().sampler_location(), 0)); | |
| 970 | 966 |
| 971 shader_quad_location = program->vertex_shader().quad_location(); | 967 shader_quad_location = program->vertex_shader().quad_location(); |
| 972 shader_edge_location = program->vertex_shader().edge_location(); | 968 shader_edge_location = program->vertex_shader().edge_location(); |
| 973 shader_viewport_location = program->vertex_shader().viewport_location(); | 969 shader_viewport_location = program->vertex_shader().viewport_location(); |
| 974 shader_mask_sampler_location = | 970 shader_mask_sampler_location = |
| 975 program->fragment_shader().mask_sampler_location(); | 971 program->fragment_shader().mask_sampler_location(); |
| 976 shader_mask_tex_coord_scale_location = | 972 shader_mask_tex_coord_scale_location = |
| 977 program->fragment_shader().mask_tex_coord_scale_location(); | 973 program->fragment_shader().mask_tex_coord_scale_location(); |
| 978 shader_mask_tex_coord_offset_location = | 974 shader_mask_tex_coord_offset_location = |
| 979 program->fragment_shader().mask_tex_coord_offset_location(); | 975 program->fragment_shader().mask_tex_coord_offset_location(); |
| 980 shader_matrix_location = program->vertex_shader().matrix_location(); | 976 shader_matrix_location = program->vertex_shader().matrix_location(); |
| 981 shader_alpha_location = program->fragment_shader().alpha_location(); | 977 shader_alpha_location = program->fragment_shader().alpha_location(); |
| 982 shader_tex_transform_location = | 978 shader_tex_transform_location = |
| 983 program->vertex_shader().tex_transform_location(); | 979 program->vertex_shader().tex_transform_location(); |
| 984 } else if (!use_aa && mask_texture_id && !use_color_matrix) { | 980 } else if (!use_aa && mask_texture_id && !use_color_matrix) { |
| 985 const RenderPassMaskProgram* program = | 981 const RenderPassMaskProgram* program = |
| 986 GetRenderPassMaskProgram(tex_coord_precision); | 982 GetRenderPassMaskProgram(tex_coord_precision); |
| 987 SetUseProgram(program->program()); | 983 SetUseProgram(program->program()); |
| 988 GLC(Context(), | 984 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 989 Context()->uniform1i(program->fragment_shader().sampler_location(), 0)); | |
| 990 | 985 |
| 991 shader_mask_sampler_location = | 986 shader_mask_sampler_location = |
| 992 program->fragment_shader().mask_sampler_location(); | 987 program->fragment_shader().mask_sampler_location(); |
| 993 shader_mask_tex_coord_scale_location = | 988 shader_mask_tex_coord_scale_location = |
| 994 program->fragment_shader().mask_tex_coord_scale_location(); | 989 program->fragment_shader().mask_tex_coord_scale_location(); |
| 995 shader_mask_tex_coord_offset_location = | 990 shader_mask_tex_coord_offset_location = |
| 996 program->fragment_shader().mask_tex_coord_offset_location(); | 991 program->fragment_shader().mask_tex_coord_offset_location(); |
| 997 shader_matrix_location = program->vertex_shader().matrix_location(); | 992 shader_matrix_location = program->vertex_shader().matrix_location(); |
| 998 shader_alpha_location = program->fragment_shader().alpha_location(); | 993 shader_alpha_location = program->fragment_shader().alpha_location(); |
| 999 shader_tex_transform_location = | 994 shader_tex_transform_location = |
| 1000 program->vertex_shader().tex_transform_location(); | 995 program->vertex_shader().tex_transform_location(); |
| 1001 } else if (use_aa && !mask_texture_id && !use_color_matrix) { | 996 } else if (use_aa && !mask_texture_id && !use_color_matrix) { |
| 1002 const RenderPassProgramAA* program = | 997 const RenderPassProgramAA* program = |
| 1003 GetRenderPassProgramAA(tex_coord_precision); | 998 GetRenderPassProgramAA(tex_coord_precision); |
| 1004 SetUseProgram(program->program()); | 999 SetUseProgram(program->program()); |
| 1005 GLC(Context(), | 1000 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 1006 Context()->uniform1i(program->fragment_shader().sampler_location(), 0)); | |
| 1007 | 1001 |
| 1008 shader_quad_location = program->vertex_shader().quad_location(); | 1002 shader_quad_location = program->vertex_shader().quad_location(); |
| 1009 shader_edge_location = program->vertex_shader().edge_location(); | 1003 shader_edge_location = program->vertex_shader().edge_location(); |
| 1010 shader_viewport_location = program->vertex_shader().viewport_location(); | 1004 shader_viewport_location = program->vertex_shader().viewport_location(); |
| 1011 shader_matrix_location = program->vertex_shader().matrix_location(); | 1005 shader_matrix_location = program->vertex_shader().matrix_location(); |
| 1012 shader_alpha_location = program->fragment_shader().alpha_location(); | 1006 shader_alpha_location = program->fragment_shader().alpha_location(); |
| 1013 shader_tex_transform_location = | 1007 shader_tex_transform_location = |
| 1014 program->vertex_shader().tex_transform_location(); | 1008 program->vertex_shader().tex_transform_location(); |
| 1015 } else if (use_aa && mask_texture_id && use_color_matrix) { | 1009 } else if (use_aa && mask_texture_id && use_color_matrix) { |
| 1016 const RenderPassMaskColorMatrixProgramAA* program = | 1010 const RenderPassMaskColorMatrixProgramAA* program = |
| 1017 GetRenderPassMaskColorMatrixProgramAA(tex_coord_precision); | 1011 GetRenderPassMaskColorMatrixProgramAA(tex_coord_precision); |
| 1018 SetUseProgram(program->program()); | 1012 SetUseProgram(program->program()); |
| 1019 GLC(Context(), | 1013 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 1020 Context()->uniform1i(program->fragment_shader().sampler_location(), 0)); | |
| 1021 | 1014 |
| 1022 shader_matrix_location = program->vertex_shader().matrix_location(); | 1015 shader_matrix_location = program->vertex_shader().matrix_location(); |
| 1023 shader_quad_location = program->vertex_shader().quad_location(); | 1016 shader_quad_location = program->vertex_shader().quad_location(); |
| 1024 shader_tex_transform_location = | 1017 shader_tex_transform_location = |
| 1025 program->vertex_shader().tex_transform_location(); | 1018 program->vertex_shader().tex_transform_location(); |
| 1026 shader_edge_location = program->vertex_shader().edge_location(); | 1019 shader_edge_location = program->vertex_shader().edge_location(); |
| 1027 shader_viewport_location = program->vertex_shader().viewport_location(); | 1020 shader_viewport_location = program->vertex_shader().viewport_location(); |
| 1028 shader_alpha_location = program->fragment_shader().alpha_location(); | 1021 shader_alpha_location = program->fragment_shader().alpha_location(); |
| 1029 shader_mask_sampler_location = | 1022 shader_mask_sampler_location = |
| 1030 program->fragment_shader().mask_sampler_location(); | 1023 program->fragment_shader().mask_sampler_location(); |
| 1031 shader_mask_tex_coord_scale_location = | 1024 shader_mask_tex_coord_scale_location = |
| 1032 program->fragment_shader().mask_tex_coord_scale_location(); | 1025 program->fragment_shader().mask_tex_coord_scale_location(); |
| 1033 shader_mask_tex_coord_offset_location = | 1026 shader_mask_tex_coord_offset_location = |
| 1034 program->fragment_shader().mask_tex_coord_offset_location(); | 1027 program->fragment_shader().mask_tex_coord_offset_location(); |
| 1035 shader_color_matrix_location = | 1028 shader_color_matrix_location = |
| 1036 program->fragment_shader().color_matrix_location(); | 1029 program->fragment_shader().color_matrix_location(); |
| 1037 shader_color_offset_location = | 1030 shader_color_offset_location = |
| 1038 program->fragment_shader().color_offset_location(); | 1031 program->fragment_shader().color_offset_location(); |
| 1039 } else if (use_aa && !mask_texture_id && use_color_matrix) { | 1032 } else if (use_aa && !mask_texture_id && use_color_matrix) { |
| 1040 const RenderPassColorMatrixProgramAA* program = | 1033 const RenderPassColorMatrixProgramAA* program = |
| 1041 GetRenderPassColorMatrixProgramAA(tex_coord_precision); | 1034 GetRenderPassColorMatrixProgramAA(tex_coord_precision); |
| 1042 SetUseProgram(program->program()); | 1035 SetUseProgram(program->program()); |
| 1043 GLC(Context(), | 1036 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 1044 Context()->uniform1i(program->fragment_shader().sampler_location(), 0)); | |
| 1045 | 1037 |
| 1046 shader_matrix_location = program->vertex_shader().matrix_location(); | 1038 shader_matrix_location = program->vertex_shader().matrix_location(); |
| 1047 shader_quad_location = program->vertex_shader().quad_location(); | 1039 shader_quad_location = program->vertex_shader().quad_location(); |
| 1048 shader_tex_transform_location = | 1040 shader_tex_transform_location = |
| 1049 program->vertex_shader().tex_transform_location(); | 1041 program->vertex_shader().tex_transform_location(); |
| 1050 shader_edge_location = program->vertex_shader().edge_location(); | 1042 shader_edge_location = program->vertex_shader().edge_location(); |
| 1051 shader_viewport_location = program->vertex_shader().viewport_location(); | 1043 shader_viewport_location = program->vertex_shader().viewport_location(); |
| 1052 shader_alpha_location = program->fragment_shader().alpha_location(); | 1044 shader_alpha_location = program->fragment_shader().alpha_location(); |
| 1053 shader_color_matrix_location = | 1045 shader_color_matrix_location = |
| 1054 program->fragment_shader().color_matrix_location(); | 1046 program->fragment_shader().color_matrix_location(); |
| 1055 shader_color_offset_location = | 1047 shader_color_offset_location = |
| 1056 program->fragment_shader().color_offset_location(); | 1048 program->fragment_shader().color_offset_location(); |
| 1057 } else if (!use_aa && mask_texture_id && use_color_matrix) { | 1049 } else if (!use_aa && mask_texture_id && use_color_matrix) { |
| 1058 const RenderPassMaskColorMatrixProgram* program = | 1050 const RenderPassMaskColorMatrixProgram* program = |
| 1059 GetRenderPassMaskColorMatrixProgram(tex_coord_precision); | 1051 GetRenderPassMaskColorMatrixProgram(tex_coord_precision); |
| 1060 SetUseProgram(program->program()); | 1052 SetUseProgram(program->program()); |
| 1061 GLC(Context(), | 1053 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 1062 Context()->uniform1i(program->fragment_shader().sampler_location(), 0)); | |
| 1063 | 1054 |
| 1064 shader_matrix_location = program->vertex_shader().matrix_location(); | 1055 shader_matrix_location = program->vertex_shader().matrix_location(); |
| 1065 shader_tex_transform_location = | 1056 shader_tex_transform_location = |
| 1066 program->vertex_shader().tex_transform_location(); | 1057 program->vertex_shader().tex_transform_location(); |
| 1067 shader_mask_sampler_location = | 1058 shader_mask_sampler_location = |
| 1068 program->fragment_shader().mask_sampler_location(); | 1059 program->fragment_shader().mask_sampler_location(); |
| 1069 shader_mask_tex_coord_scale_location = | 1060 shader_mask_tex_coord_scale_location = |
| 1070 program->fragment_shader().mask_tex_coord_scale_location(); | 1061 program->fragment_shader().mask_tex_coord_scale_location(); |
| 1071 shader_mask_tex_coord_offset_location = | 1062 shader_mask_tex_coord_offset_location = |
| 1072 program->fragment_shader().mask_tex_coord_offset_location(); | 1063 program->fragment_shader().mask_tex_coord_offset_location(); |
| 1073 shader_alpha_location = program->fragment_shader().alpha_location(); | 1064 shader_alpha_location = program->fragment_shader().alpha_location(); |
| 1074 shader_color_matrix_location = | 1065 shader_color_matrix_location = |
| 1075 program->fragment_shader().color_matrix_location(); | 1066 program->fragment_shader().color_matrix_location(); |
| 1076 shader_color_offset_location = | 1067 shader_color_offset_location = |
| 1077 program->fragment_shader().color_offset_location(); | 1068 program->fragment_shader().color_offset_location(); |
| 1078 } else if (!use_aa && !mask_texture_id && use_color_matrix) { | 1069 } else if (!use_aa && !mask_texture_id && use_color_matrix) { |
| 1079 const RenderPassColorMatrixProgram* program = | 1070 const RenderPassColorMatrixProgram* program = |
| 1080 GetRenderPassColorMatrixProgram(tex_coord_precision); | 1071 GetRenderPassColorMatrixProgram(tex_coord_precision); |
| 1081 SetUseProgram(program->program()); | 1072 SetUseProgram(program->program()); |
| 1082 GLC(Context(), | 1073 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 1083 Context()->uniform1i(program->fragment_shader().sampler_location(), 0)); | |
| 1084 | 1074 |
| 1085 shader_matrix_location = program->vertex_shader().matrix_location(); | 1075 shader_matrix_location = program->vertex_shader().matrix_location(); |
| 1086 shader_tex_transform_location = | 1076 shader_tex_transform_location = |
| 1087 program->vertex_shader().tex_transform_location(); | 1077 program->vertex_shader().tex_transform_location(); |
| 1088 shader_alpha_location = program->fragment_shader().alpha_location(); | 1078 shader_alpha_location = program->fragment_shader().alpha_location(); |
| 1089 shader_color_matrix_location = | 1079 shader_color_matrix_location = |
| 1090 program->fragment_shader().color_matrix_location(); | 1080 program->fragment_shader().color_matrix_location(); |
| 1091 shader_color_offset_location = | 1081 shader_color_offset_location = |
| 1092 program->fragment_shader().color_offset_location(); | 1082 program->fragment_shader().color_offset_location(); |
| 1093 } else { | 1083 } else { |
| 1094 const RenderPassProgram* program = | 1084 const RenderPassProgram* program = |
| 1095 GetRenderPassProgram(tex_coord_precision); | 1085 GetRenderPassProgram(tex_coord_precision); |
| 1096 SetUseProgram(program->program()); | 1086 SetUseProgram(program->program()); |
| 1097 GLC(Context(), | 1087 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 1098 Context()->uniform1i(program->fragment_shader().sampler_location(), 0)); | |
| 1099 | 1088 |
| 1100 shader_matrix_location = program->vertex_shader().matrix_location(); | 1089 shader_matrix_location = program->vertex_shader().matrix_location(); |
| 1101 shader_alpha_location = program->fragment_shader().alpha_location(); | 1090 shader_alpha_location = program->fragment_shader().alpha_location(); |
| 1102 shader_tex_transform_location = | 1091 shader_tex_transform_location = |
| 1103 program->vertex_shader().tex_transform_location(); | 1092 program->vertex_shader().tex_transform_location(); |
| 1104 } | 1093 } |
| 1105 float tex_scale_x = | 1094 float tex_scale_x = |
| 1106 quad->rect.width() / static_cast<float>(contents_texture->size().width()); | 1095 quad->rect.width() / static_cast<float>(contents_texture->size().width()); |
| 1107 float tex_scale_y = quad->rect.height() / | 1096 float tex_scale_y = quad->rect.height() / |
| 1108 static_cast<float>(contents_texture->size().height()); | 1097 static_cast<float>(contents_texture->size().height()); |
| 1109 DCHECK_LE(tex_scale_x, 1.0f); | 1098 DCHECK_LE(tex_scale_x, 1.0f); |
| 1110 DCHECK_LE(tex_scale_y, 1.0f); | 1099 DCHECK_LE(tex_scale_y, 1.0f); |
| 1111 | 1100 |
| 1112 DCHECK(shader_tex_transform_location != -1 || IsContextLost()); | 1101 DCHECK(shader_tex_transform_location != -1 || IsContextLost()); |
| 1113 // Flip the content vertically in the shader, as the RenderPass input | 1102 // Flip the content vertically in the shader, as the RenderPass input |
| 1114 // texture is already oriented the same way as the framebuffer, but the | 1103 // texture is already oriented the same way as the framebuffer, but the |
| 1115 // projection transform does a flip. | 1104 // projection transform does a flip. |
| 1116 GLC(Context(), Context()->uniform4f(shader_tex_transform_location, | 1105 GLC(gl_, |
| 1117 0.0f, | 1106 gl_->Uniform4f(shader_tex_transform_location, |
| 1118 tex_scale_y, | 1107 0.0f, |
| 1119 tex_scale_x, | 1108 tex_scale_y, |
| 1120 -tex_scale_y)); | 1109 tex_scale_x, |
| 1110 -tex_scale_y)); |
| 1121 | 1111 |
| 1122 scoped_ptr<ResourceProvider::ScopedSamplerGL> shader_mask_sampler_lock; | 1112 scoped_ptr<ResourceProvider::ScopedSamplerGL> shader_mask_sampler_lock; |
| 1123 if (shader_mask_sampler_location != -1) { | 1113 if (shader_mask_sampler_location != -1) { |
| 1124 DCHECK_NE(shader_mask_tex_coord_scale_location, 1); | 1114 DCHECK_NE(shader_mask_tex_coord_scale_location, 1); |
| 1125 DCHECK_NE(shader_mask_tex_coord_offset_location, 1); | 1115 DCHECK_NE(shader_mask_tex_coord_offset_location, 1); |
| 1126 GLC(Context(), Context()->uniform1i(shader_mask_sampler_location, 1)); | 1116 GLC(gl_, gl_->Uniform1i(shader_mask_sampler_location, 1)); |
| 1127 | 1117 |
| 1128 float mask_tex_scale_x = quad->mask_uv_rect.width() / tex_scale_x; | 1118 float mask_tex_scale_x = quad->mask_uv_rect.width() / tex_scale_x; |
| 1129 float mask_tex_scale_y = quad->mask_uv_rect.height() / tex_scale_y; | 1119 float mask_tex_scale_y = quad->mask_uv_rect.height() / tex_scale_y; |
| 1130 | 1120 |
| 1131 // Mask textures are oriented vertically flipped relative to the framebuffer | 1121 // Mask textures are oriented vertically flipped relative to the framebuffer |
| 1132 // and the RenderPass contents texture, so we flip the tex coords from the | 1122 // and the RenderPass contents texture, so we flip the tex coords from the |
| 1133 // RenderPass texture to find the mask texture coords. | 1123 // RenderPass texture to find the mask texture coords. |
| 1134 GLC(Context(), | 1124 GLC(gl_, |
| 1135 Context()->uniform2f( | 1125 gl_->Uniform2f(shader_mask_tex_coord_offset_location, |
| 1136 shader_mask_tex_coord_offset_location, | 1126 quad->mask_uv_rect.x(), |
| 1137 quad->mask_uv_rect.x(), | 1127 quad->mask_uv_rect.y() + quad->mask_uv_rect.height())); |
| 1138 quad->mask_uv_rect.y() + quad->mask_uv_rect.height())); | 1128 GLC(gl_, |
| 1139 GLC(Context(), | 1129 gl_->Uniform2f(shader_mask_tex_coord_scale_location, |
| 1140 Context()->uniform2f(shader_mask_tex_coord_scale_location, | 1130 mask_tex_scale_x, |
| 1141 mask_tex_scale_x, | 1131 -mask_tex_scale_y)); |
| 1142 -mask_tex_scale_y)); | |
| 1143 shader_mask_sampler_lock = make_scoped_ptr( | 1132 shader_mask_sampler_lock = make_scoped_ptr( |
| 1144 new ResourceProvider::ScopedSamplerGL(resource_provider_, | 1133 new ResourceProvider::ScopedSamplerGL(resource_provider_, |
| 1145 quad->mask_resource_id, | 1134 quad->mask_resource_id, |
| 1146 GL_TEXTURE1, | 1135 GL_TEXTURE1, |
| 1147 GL_LINEAR)); | 1136 GL_LINEAR)); |
| 1148 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), | 1137 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), |
| 1149 shader_mask_sampler_lock->target()); | 1138 shader_mask_sampler_lock->target()); |
| 1150 } | 1139 } |
| 1151 | 1140 |
| 1152 if (shader_edge_location != -1) { | 1141 if (shader_edge_location != -1) { |
| 1153 float edge[24]; | 1142 float edge[24]; |
| 1154 device_layer_edges.ToFloatArray(edge); | 1143 device_layer_edges.ToFloatArray(edge); |
| 1155 device_layer_bounds.ToFloatArray(&edge[12]); | 1144 device_layer_bounds.ToFloatArray(&edge[12]); |
| 1156 GLC(Context(), Context()->uniform3fv(shader_edge_location, 8, edge)); | 1145 GLC(gl_, gl_->Uniform3fv(shader_edge_location, 8, edge)); |
| 1157 } | 1146 } |
| 1158 | 1147 |
| 1159 if (shader_viewport_location != -1) { | 1148 if (shader_viewport_location != -1) { |
| 1160 float viewport[4] = { | 1149 float viewport[4] = {static_cast<float>(viewport_.x()), |
| 1161 static_cast<float>(viewport_.x()), | 1150 static_cast<float>(viewport_.y()), |
| 1162 static_cast<float>(viewport_.y()), | 1151 static_cast<float>(viewport_.width()), |
| 1163 static_cast<float>(viewport_.width()), | 1152 static_cast<float>(viewport_.height()), }; |
| 1164 static_cast<float>(viewport_.height()), | 1153 GLC(gl_, gl_->Uniform4fv(shader_viewport_location, 1, viewport)); |
| 1165 }; | |
| 1166 GLC(Context(), | |
| 1167 Context()->uniform4fv(shader_viewport_location, 1, viewport)); | |
| 1168 } | 1154 } |
| 1169 | 1155 |
| 1170 if (shader_color_matrix_location != -1) { | 1156 if (shader_color_matrix_location != -1) { |
| 1171 float matrix[16]; | 1157 float matrix[16]; |
| 1172 for (int i = 0; i < 4; ++i) { | 1158 for (int i = 0; i < 4; ++i) { |
| 1173 for (int j = 0; j < 4; ++j) | 1159 for (int j = 0; j < 4; ++j) |
| 1174 matrix[i * 4 + j] = SkScalarToFloat(color_matrix[j * 5 + i]); | 1160 matrix[i * 4 + j] = SkScalarToFloat(color_matrix[j * 5 + i]); |
| 1175 } | 1161 } |
| 1176 GLC(Context(), | 1162 GLC(gl_, |
| 1177 Context()->uniformMatrix4fv( | 1163 gl_->UniformMatrix4fv(shader_color_matrix_location, 1, false, matrix)); |
| 1178 shader_color_matrix_location, 1, false, matrix)); | |
| 1179 } | 1164 } |
| 1180 static const float kScale = 1.0f / 255.0f; | 1165 static const float kScale = 1.0f / 255.0f; |
| 1181 if (shader_color_offset_location != -1) { | 1166 if (shader_color_offset_location != -1) { |
| 1182 float offset[4]; | 1167 float offset[4]; |
| 1183 for (int i = 0; i < 4; ++i) | 1168 for (int i = 0; i < 4; ++i) |
| 1184 offset[i] = SkScalarToFloat(color_matrix[i * 5 + 4]) * kScale; | 1169 offset[i] = SkScalarToFloat(color_matrix[i * 5 + 4]) * kScale; |
| 1185 | 1170 |
| 1186 GLC(Context(), | 1171 GLC(gl_, gl_->Uniform4fv(shader_color_offset_location, 1, offset)); |
| 1187 Context()->uniform4fv(shader_color_offset_location, 1, offset)); | |
| 1188 } | 1172 } |
| 1189 | 1173 |
| 1190 // Map device space quad to surface space. contents_device_transform has no 3d | 1174 // Map device space quad to surface space. contents_device_transform has no 3d |
| 1191 // component since it was flattened, so we don't need to project. | 1175 // component since it was flattened, so we don't need to project. |
| 1192 gfx::QuadF surface_quad = MathUtil::MapQuad(contents_device_transform_inverse, | 1176 gfx::QuadF surface_quad = MathUtil::MapQuad(contents_device_transform_inverse, |
| 1193 device_layer_edges.ToQuadF(), | 1177 device_layer_edges.ToQuadF(), |
| 1194 &clipped); | 1178 &clipped); |
| 1195 | 1179 |
| 1196 SetShaderOpacity(quad->opacity(), shader_alpha_location); | 1180 SetShaderOpacity(quad->opacity(), shader_alpha_location); |
| 1197 SetShaderQuadF(surface_quad, shader_quad_location); | 1181 SetShaderQuadF(surface_quad, shader_quad_location); |
| 1198 DrawQuadGeometry( | 1182 DrawQuadGeometry( |
| 1199 frame, quad->quadTransform(), quad->rect, shader_matrix_location); | 1183 frame, quad->quadTransform(), quad->rect, shader_matrix_location); |
| 1200 | 1184 |
| 1201 // Flush the compositor context before the filter bitmap goes out of | 1185 // Flush the compositor context before the filter bitmap goes out of |
| 1202 // scope, so the draw gets processed before the filter texture gets deleted. | 1186 // scope, so the draw gets processed before the filter texture gets deleted. |
| 1203 if (filter_bitmap.getTexture()) | 1187 if (filter_bitmap.getTexture()) |
| 1204 GLC(context_, context_->flush()); | 1188 GLC(gl_, gl_->Flush()); |
| 1205 } | 1189 } |
| 1206 | 1190 |
| 1207 struct SolidColorProgramUniforms { | 1191 struct SolidColorProgramUniforms { |
| 1208 unsigned program; | 1192 unsigned program; |
| 1209 unsigned matrix_location; | 1193 unsigned matrix_location; |
| 1210 unsigned viewport_location; | 1194 unsigned viewport_location; |
| 1211 unsigned quad_location; | 1195 unsigned quad_location; |
| 1212 unsigned edge_location; | 1196 unsigned edge_location; |
| 1213 unsigned color_location; | 1197 unsigned color_location; |
| 1214 }; | 1198 }; |
| 1215 | 1199 |
| 1216 template<class T> | 1200 template <class T> |
| 1217 static void SolidColorUniformLocation(T program, | 1201 static void SolidColorUniformLocation(T program, |
| 1218 SolidColorProgramUniforms* uniforms) { | 1202 SolidColorProgramUniforms* uniforms) { |
| 1219 uniforms->program = program->program(); | 1203 uniforms->program = program->program(); |
| 1220 uniforms->matrix_location = program->vertex_shader().matrix_location(); | 1204 uniforms->matrix_location = program->vertex_shader().matrix_location(); |
| 1221 uniforms->viewport_location = program->vertex_shader().viewport_location(); | 1205 uniforms->viewport_location = program->vertex_shader().viewport_location(); |
| 1222 uniforms->quad_location = program->vertex_shader().quad_location(); | 1206 uniforms->quad_location = program->vertex_shader().quad_location(); |
| 1223 uniforms->edge_location = program->vertex_shader().edge_location(); | 1207 uniforms->edge_location = program->vertex_shader().edge_location(); |
| 1224 uniforms->color_location = program->fragment_shader().color_location(); | 1208 uniforms->color_location = program->fragment_shader().color_location(); |
| 1225 } | 1209 } |
| 1226 | 1210 |
| 1227 // static | 1211 // static |
| 1228 bool GLRenderer::SetupQuadForAntialiasing( | 1212 bool GLRenderer::SetupQuadForAntialiasing( |
| 1229 const gfx::Transform& device_transform, | 1213 const gfx::Transform& device_transform, |
| 1230 const DrawQuad* quad, | 1214 const DrawQuad* quad, |
| 1231 gfx::QuadF* local_quad, | 1215 gfx::QuadF* local_quad, |
| 1232 float edge[24]) { | 1216 float edge[24]) { |
| 1233 gfx::Rect tile_rect = quad->visible_rect; | 1217 gfx::Rect tile_rect = quad->visible_rect; |
| 1234 | 1218 |
| 1235 bool clipped = false; | 1219 bool clipped = false; |
| 1236 gfx::QuadF device_layer_quad = MathUtil::MapQuad( | 1220 gfx::QuadF device_layer_quad = MathUtil::MapQuad( |
| 1237 device_transform, gfx::QuadF(quad->visibleContentRect()), &clipped); | 1221 device_transform, gfx::QuadF(quad->visibleContentRect()), &clipped); |
| 1238 | 1222 |
| 1239 bool is_axis_aligned_in_target = device_layer_quad.IsRectilinear(); | 1223 bool is_axis_aligned_in_target = device_layer_quad.IsRectilinear(); |
| 1240 bool is_nearest_rect_within_epsilon = is_axis_aligned_in_target && | 1224 bool is_nearest_rect_within_epsilon = |
| 1225 is_axis_aligned_in_target && |
| 1241 gfx::IsNearestRectWithinDistance(device_layer_quad.BoundingBox(), | 1226 gfx::IsNearestRectWithinDistance(device_layer_quad.BoundingBox(), |
| 1242 kAntiAliasingEpsilon); | 1227 kAntiAliasingEpsilon); |
| 1243 // AAing clipped quads is not supported by the code yet. | 1228 // AAing clipped quads is not supported by the code yet. |
| 1244 bool use_aa = !clipped && !is_nearest_rect_within_epsilon && quad->IsEdge(); | 1229 bool use_aa = !clipped && !is_nearest_rect_within_epsilon && quad->IsEdge(); |
| 1245 if (!use_aa) | 1230 if (!use_aa) |
| 1246 return false; | 1231 return false; |
| 1247 | 1232 |
| 1248 LayerQuad device_layer_bounds(gfx::QuadF(device_layer_quad.BoundingBox())); | 1233 LayerQuad device_layer_bounds(gfx::QuadF(device_layer_quad.BoundingBox())); |
| 1249 device_layer_bounds.InflateAntiAliasingDistance(); | 1234 device_layer_bounds.InflateAntiAliasingDistance(); |
| 1250 | 1235 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1289 left_edge.scale(sign); | 1274 left_edge.scale(sign); |
| 1290 top_edge.scale(sign); | 1275 top_edge.scale(sign); |
| 1291 right_edge.scale(sign); | 1276 right_edge.scale(sign); |
| 1292 | 1277 |
| 1293 // Create device space quad. | 1278 // Create device space quad. |
| 1294 LayerQuad device_quad(left_edge, top_edge, right_edge, bottom_edge); | 1279 LayerQuad device_quad(left_edge, top_edge, right_edge, bottom_edge); |
| 1295 | 1280 |
| 1296 // Map device space quad to local space. device_transform has no 3d | 1281 // Map device space quad to local space. device_transform has no 3d |
| 1297 // component since it was flattened, so we don't need to project. We should | 1282 // component since it was flattened, so we don't need to project. We should |
| 1298 // have already checked that the transform was uninvertible above. | 1283 // have already checked that the transform was uninvertible above. |
| 1299 gfx::Transform inverse_device_transform( | 1284 gfx::Transform inverse_device_transform(gfx::Transform::kSkipInitialization); |
| 1300 gfx::Transform::kSkipInitialization); | |
| 1301 bool did_invert = device_transform.GetInverse(&inverse_device_transform); | 1285 bool did_invert = device_transform.GetInverse(&inverse_device_transform); |
| 1302 DCHECK(did_invert); | 1286 DCHECK(did_invert); |
| 1303 *local_quad = MathUtil::MapQuad( | 1287 *local_quad = MathUtil::MapQuad( |
| 1304 inverse_device_transform, device_quad.ToQuadF(), &clipped); | 1288 inverse_device_transform, device_quad.ToQuadF(), &clipped); |
| 1305 // We should not DCHECK(!clipped) here, because anti-aliasing inflation may | 1289 // We should not DCHECK(!clipped) here, because anti-aliasing inflation may |
| 1306 // cause device_quad to become clipped. To our knowledge this scenario does | 1290 // cause device_quad to become clipped. To our knowledge this scenario does |
| 1307 // not need to be handled differently than the unclipped case. | 1291 // not need to be handled differently than the unclipped case. |
| 1308 | 1292 |
| 1309 return true; | 1293 return true; |
| 1310 } | 1294 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1334 settings_->allow_antialiasing && !quad->force_anti_aliasing_off && | 1318 settings_->allow_antialiasing && !quad->force_anti_aliasing_off && |
| 1335 SetupQuadForAntialiasing(device_transform, quad, &local_quad, edge); | 1319 SetupQuadForAntialiasing(device_transform, quad, &local_quad, edge); |
| 1336 | 1320 |
| 1337 SolidColorProgramUniforms uniforms; | 1321 SolidColorProgramUniforms uniforms; |
| 1338 if (use_aa) | 1322 if (use_aa) |
| 1339 SolidColorUniformLocation(GetSolidColorProgramAA(), &uniforms); | 1323 SolidColorUniformLocation(GetSolidColorProgramAA(), &uniforms); |
| 1340 else | 1324 else |
| 1341 SolidColorUniformLocation(GetSolidColorProgram(), &uniforms); | 1325 SolidColorUniformLocation(GetSolidColorProgram(), &uniforms); |
| 1342 SetUseProgram(uniforms.program); | 1326 SetUseProgram(uniforms.program); |
| 1343 | 1327 |
| 1344 GLC(Context(), | 1328 GLC(gl_, |
| 1345 Context()->uniform4f(uniforms.color_location, | 1329 gl_->Uniform4f(uniforms.color_location, |
| 1346 (SkColorGetR(color) * (1.0f / 255.0f)) * alpha, | 1330 (SkColorGetR(color) * (1.0f / 255.0f)) * alpha, |
| 1347 (SkColorGetG(color) * (1.0f / 255.0f)) * alpha, | 1331 (SkColorGetG(color) * (1.0f / 255.0f)) * alpha, |
| 1348 (SkColorGetB(color) * (1.0f / 255.0f)) * alpha, | 1332 (SkColorGetB(color) * (1.0f / 255.0f)) * alpha, |
| 1349 alpha)); | 1333 alpha)); |
| 1350 if (use_aa) { | 1334 if (use_aa) { |
| 1351 float viewport[4] = { | 1335 float viewport[4] = {static_cast<float>(viewport_.x()), |
| 1352 static_cast<float>(viewport_.x()), | 1336 static_cast<float>(viewport_.y()), |
| 1353 static_cast<float>(viewport_.y()), | 1337 static_cast<float>(viewport_.width()), |
| 1354 static_cast<float>(viewport_.width()), | 1338 static_cast<float>(viewport_.height()), }; |
| 1355 static_cast<float>(viewport_.height()), | 1339 GLC(gl_, gl_->Uniform4fv(uniforms.viewport_location, 1, viewport)); |
| 1356 }; | 1340 GLC(gl_, gl_->Uniform3fv(uniforms.edge_location, 8, edge)); |
| 1357 GLC(Context(), | |
| 1358 Context()->uniform4fv(uniforms.viewport_location, 1, viewport)); | |
| 1359 GLC(Context(), Context()->uniform3fv(uniforms.edge_location, 8, edge)); | |
| 1360 } | 1341 } |
| 1361 | 1342 |
| 1362 // Enable blending when the quad properties require it or if we decided | 1343 // Enable blending when the quad properties require it or if we decided |
| 1363 // to use antialiasing. | 1344 // to use antialiasing. |
| 1364 SetBlendEnabled(quad->ShouldDrawWithBlending() || use_aa); | 1345 SetBlendEnabled(quad->ShouldDrawWithBlending() || use_aa); |
| 1365 | 1346 |
| 1366 // Normalize to tile_rect. | 1347 // Normalize to tile_rect. |
| 1367 local_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); | 1348 local_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); |
| 1368 | 1349 |
| 1369 SetShaderQuadF(local_quad, uniforms.quad_location); | 1350 SetShaderQuadF(local_quad, uniforms.quad_location); |
| 1370 | 1351 |
| 1371 // The transform and vertex data are used to figure out the extents that the | 1352 // The transform and vertex data are used to figure out the extents that the |
| 1372 // un-antialiased quad should have and which vertex this is and the float | 1353 // un-antialiased quad should have and which vertex this is and the float |
| 1373 // quad passed in via uniform is the actual geometry that gets used to draw | 1354 // quad passed in via uniform is the actual geometry that gets used to draw |
| 1374 // it. This is why this centered rect is used and not the original quad_rect. | 1355 // it. This is why this centered rect is used and not the original quad_rect. |
| 1375 gfx::RectF centered_rect(gfx::PointF(-0.5f * tile_rect.width(), | 1356 gfx::RectF centered_rect( |
| 1376 -0.5f * tile_rect.height()), | 1357 gfx::PointF(-0.5f * tile_rect.width(), -0.5f * tile_rect.height()), |
| 1377 tile_rect.size()); | 1358 tile_rect.size()); |
| 1378 DrawQuadGeometry(frame, quad->quadTransform(), | 1359 DrawQuadGeometry( |
| 1379 centered_rect, uniforms.matrix_location); | 1360 frame, quad->quadTransform(), centered_rect, uniforms.matrix_location); |
| 1380 } | 1361 } |
| 1381 | 1362 |
| 1382 struct TileProgramUniforms { | 1363 struct TileProgramUniforms { |
| 1383 unsigned program; | 1364 unsigned program; |
| 1384 unsigned matrix_location; | 1365 unsigned matrix_location; |
| 1385 unsigned viewport_location; | 1366 unsigned viewport_location; |
| 1386 unsigned quad_location; | 1367 unsigned quad_location; |
| 1387 unsigned edge_location; | 1368 unsigned edge_location; |
| 1388 unsigned vertex_tex_transform_location; | 1369 unsigned vertex_tex_transform_location; |
| 1389 unsigned sampler_location; | 1370 unsigned sampler_location; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1424 quad->rect.height() / quad->tex_coord_rect.height(); | 1405 quad->rect.height() / quad->tex_coord_rect.height(); |
| 1425 | 1406 |
| 1426 gfx::RectF clamp_geom_rect(tile_rect); | 1407 gfx::RectF clamp_geom_rect(tile_rect); |
| 1427 gfx::RectF clamp_tex_rect(tex_coord_rect); | 1408 gfx::RectF clamp_tex_rect(tex_coord_rect); |
| 1428 // Clamp texture coordinates to avoid sampling outside the layer | 1409 // Clamp texture coordinates to avoid sampling outside the layer |
| 1429 // by deflating the tile region half a texel or half a texel | 1410 // by deflating the tile region half a texel or half a texel |
| 1430 // minus epsilon for one pixel layers. The resulting clamp region | 1411 // minus epsilon for one pixel layers. The resulting clamp region |
| 1431 // is mapped to the unit square by the vertex shader and mapped | 1412 // is mapped to the unit square by the vertex shader and mapped |
| 1432 // back to normalized texture coordinates by the fragment shader | 1413 // back to normalized texture coordinates by the fragment shader |
| 1433 // after being clamped to 0-1 range. | 1414 // after being clamped to 0-1 range. |
| 1434 float tex_clamp_x = std::min( | 1415 float tex_clamp_x = |
| 1435 0.5f, 0.5f * clamp_tex_rect.width() - kAntiAliasingEpsilon); | 1416 std::min(0.5f, 0.5f * clamp_tex_rect.width() - kAntiAliasingEpsilon); |
| 1436 float tex_clamp_y = std::min( | 1417 float tex_clamp_y = |
| 1437 0.5f, 0.5f * clamp_tex_rect.height() - kAntiAliasingEpsilon); | 1418 std::min(0.5f, 0.5f * clamp_tex_rect.height() - kAntiAliasingEpsilon); |
| 1438 float geom_clamp_x = std::min( | 1419 float geom_clamp_x = |
| 1439 tex_clamp_x * tex_to_geom_scale_x, | 1420 std::min(tex_clamp_x * tex_to_geom_scale_x, |
| 1440 0.5f * clamp_geom_rect.width() - kAntiAliasingEpsilon); | 1421 0.5f * clamp_geom_rect.width() - kAntiAliasingEpsilon); |
| 1441 float geom_clamp_y = std::min( | 1422 float geom_clamp_y = |
| 1442 tex_clamp_y * tex_to_geom_scale_y, | 1423 std::min(tex_clamp_y * tex_to_geom_scale_y, |
| 1443 0.5f * clamp_geom_rect.height() - kAntiAliasingEpsilon); | 1424 0.5f * clamp_geom_rect.height() - kAntiAliasingEpsilon); |
| 1444 clamp_geom_rect.Inset(geom_clamp_x, geom_clamp_y, geom_clamp_x, geom_clamp_y); | 1425 clamp_geom_rect.Inset(geom_clamp_x, geom_clamp_y, geom_clamp_x, geom_clamp_y); |
| 1445 clamp_tex_rect.Inset(tex_clamp_x, tex_clamp_y, tex_clamp_x, tex_clamp_y); | 1426 clamp_tex_rect.Inset(tex_clamp_x, tex_clamp_y, tex_clamp_x, tex_clamp_y); |
| 1446 | 1427 |
| 1447 // Map clamping rectangle to unit square. | 1428 // Map clamping rectangle to unit square. |
| 1448 float vertex_tex_translate_x = -clamp_geom_rect.x() / clamp_geom_rect.width(); | 1429 float vertex_tex_translate_x = -clamp_geom_rect.x() / clamp_geom_rect.width(); |
| 1449 float vertex_tex_translate_y = | 1430 float vertex_tex_translate_y = |
| 1450 -clamp_geom_rect.y() / clamp_geom_rect.height(); | 1431 -clamp_geom_rect.y() / clamp_geom_rect.height(); |
| 1451 float vertex_tex_scale_x = tile_rect.width() / clamp_geom_rect.width(); | 1432 float vertex_tex_scale_x = tile_rect.width() / clamp_geom_rect.width(); |
| 1452 float vertex_tex_scale_y = tile_rect.height() / clamp_geom_rect.height(); | 1433 float vertex_tex_scale_y = tile_rect.height() / clamp_geom_rect.height(); |
| 1453 | 1434 |
| 1454 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 1435 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 1455 gl_, &highp_threshold_cache_, highp_threshold_min_, | 1436 gl_, &highp_threshold_cache_, highp_threshold_min_, quad->texture_size); |
| 1456 quad->texture_size); | |
| 1457 | 1437 |
| 1458 gfx::Transform device_transform = | 1438 gfx::Transform device_transform = |
| 1459 frame->window_matrix * frame->projection_matrix * quad->quadTransform(); | 1439 frame->window_matrix * frame->projection_matrix * quad->quadTransform(); |
| 1460 device_transform.FlattenTo2d(); | 1440 device_transform.FlattenTo2d(); |
| 1461 if (!device_transform.IsInvertible()) | 1441 if (!device_transform.IsInvertible()) |
| 1462 return; | 1442 return; |
| 1463 | 1443 |
| 1464 gfx::QuadF local_quad = gfx::QuadF(gfx::RectF(tile_rect)); | 1444 gfx::QuadF local_quad = gfx::QuadF(gfx::RectF(tile_rect)); |
| 1465 float edge[24]; | 1445 float edge[24]; |
| 1466 bool use_aa = settings_->allow_antialiasing && SetupQuadForAntialiasing( | 1446 bool use_aa = |
| 1467 device_transform, quad, &local_quad, edge); | 1447 settings_->allow_antialiasing && |
| 1448 SetupQuadForAntialiasing(device_transform, quad, &local_quad, edge); |
| 1468 | 1449 |
| 1469 bool scaled = (tex_to_geom_scale_x != 1.f || tex_to_geom_scale_y != 1.f); | 1450 bool scaled = (tex_to_geom_scale_x != 1.f || tex_to_geom_scale_y != 1.f); |
| 1470 GLenum filter = (use_aa || scaled || | 1451 GLenum filter = (use_aa || scaled || |
| 1471 !quad->quadTransform().IsIdentityOrIntegerTranslation()) | 1452 !quad->quadTransform().IsIdentityOrIntegerTranslation()) |
| 1472 ? GL_LINEAR | 1453 ? GL_LINEAR |
| 1473 : GL_NEAREST; | 1454 : GL_NEAREST; |
| 1474 ResourceProvider::ScopedSamplerGL quad_resource_lock( | 1455 ResourceProvider::ScopedSamplerGL quad_resource_lock( |
| 1475 resource_provider_, resource_id, filter); | 1456 resource_provider_, resource_id, filter); |
| 1476 SamplerType sampler = SamplerTypeFromTextureTarget( | 1457 SamplerType sampler = |
| 1477 quad_resource_lock.target()); | 1458 SamplerTypeFromTextureTarget(quad_resource_lock.target()); |
| 1478 | 1459 |
| 1479 float fragment_tex_translate_x = clamp_tex_rect.x(); | 1460 float fragment_tex_translate_x = clamp_tex_rect.x(); |
| 1480 float fragment_tex_translate_y = clamp_tex_rect.y(); | 1461 float fragment_tex_translate_y = clamp_tex_rect.y(); |
| 1481 float fragment_tex_scale_x = clamp_tex_rect.width(); | 1462 float fragment_tex_scale_x = clamp_tex_rect.width(); |
| 1482 float fragment_tex_scale_y = clamp_tex_rect.height(); | 1463 float fragment_tex_scale_y = clamp_tex_rect.height(); |
| 1483 | 1464 |
| 1484 // Map to normalized texture coordinates. | 1465 // Map to normalized texture coordinates. |
| 1485 if (sampler != SamplerType2DRect) { | 1466 if (sampler != SamplerType2DRect) { |
| 1486 gfx::Size texture_size = quad->texture_size; | 1467 gfx::Size texture_size = quad->texture_size; |
| 1487 DCHECK(!texture_size.IsEmpty()); | 1468 DCHECK(!texture_size.IsEmpty()); |
| 1488 fragment_tex_translate_x /= texture_size.width(); | 1469 fragment_tex_translate_x /= texture_size.width(); |
| 1489 fragment_tex_translate_y /= texture_size.height(); | 1470 fragment_tex_translate_y /= texture_size.height(); |
| 1490 fragment_tex_scale_x /= texture_size.width(); | 1471 fragment_tex_scale_x /= texture_size.width(); |
| 1491 fragment_tex_scale_y /= texture_size.height(); | 1472 fragment_tex_scale_y /= texture_size.height(); |
| 1492 } | 1473 } |
| 1493 | 1474 |
| 1494 TileProgramUniforms uniforms; | 1475 TileProgramUniforms uniforms; |
| 1495 if (use_aa) { | 1476 if (use_aa) { |
| 1496 if (quad->swizzle_contents) { | 1477 if (quad->swizzle_contents) { |
| 1497 TileUniformLocation( | 1478 TileUniformLocation(GetTileProgramSwizzleAA(tex_coord_precision, sampler), |
| 1498 GetTileProgramSwizzleAA(tex_coord_precision, sampler), | 1479 &uniforms); |
| 1499 &uniforms); | |
| 1500 } else { | 1480 } else { |
| 1501 TileUniformLocation(GetTileProgramAA(tex_coord_precision, sampler), | 1481 TileUniformLocation(GetTileProgramAA(tex_coord_precision, sampler), |
| 1502 &uniforms); | 1482 &uniforms); |
| 1503 } | 1483 } |
| 1504 } else { | 1484 } else { |
| 1505 if (quad->ShouldDrawWithBlending()) { | 1485 if (quad->ShouldDrawWithBlending()) { |
| 1506 if (quad->swizzle_contents) { | 1486 if (quad->swizzle_contents) { |
| 1507 TileUniformLocation( | 1487 TileUniformLocation(GetTileProgramSwizzle(tex_coord_precision, sampler), |
| 1508 GetTileProgramSwizzle(tex_coord_precision, sampler), | 1488 &uniforms); |
| 1509 &uniforms); | |
| 1510 } else { | 1489 } else { |
| 1511 TileUniformLocation(GetTileProgram(tex_coord_precision, sampler), | 1490 TileUniformLocation(GetTileProgram(tex_coord_precision, sampler), |
| 1512 &uniforms); | 1491 &uniforms); |
| 1513 } | 1492 } |
| 1514 } else { | 1493 } else { |
| 1515 if (quad->swizzle_contents) { | 1494 if (quad->swizzle_contents) { |
| 1516 TileUniformLocation( | 1495 TileUniformLocation( |
| 1517 GetTileProgramSwizzleOpaque(tex_coord_precision, sampler), | 1496 GetTileProgramSwizzleOpaque(tex_coord_precision, sampler), |
| 1518 &uniforms); | 1497 &uniforms); |
| 1519 } else { | 1498 } else { |
| 1520 TileUniformLocation(GetTileProgramOpaque(tex_coord_precision, sampler), | 1499 TileUniformLocation(GetTileProgramOpaque(tex_coord_precision, sampler), |
| 1521 &uniforms); | 1500 &uniforms); |
| 1522 } | 1501 } |
| 1523 } | 1502 } |
| 1524 } | 1503 } |
| 1525 | 1504 |
| 1526 SetUseProgram(uniforms.program); | 1505 SetUseProgram(uniforms.program); |
| 1527 GLC(Context(), Context()->uniform1i(uniforms.sampler_location, 0)); | 1506 GLC(gl_, gl_->Uniform1i(uniforms.sampler_location, 0)); |
| 1528 | 1507 |
| 1529 if (use_aa) { | 1508 if (use_aa) { |
| 1530 float viewport[4] = { | 1509 float viewport[4] = {static_cast<float>(viewport_.x()), |
| 1531 static_cast<float>(viewport_.x()), | 1510 static_cast<float>(viewport_.y()), |
| 1532 static_cast<float>(viewport_.y()), | 1511 static_cast<float>(viewport_.width()), |
| 1533 static_cast<float>(viewport_.width()), | 1512 static_cast<float>(viewport_.height()), }; |
| 1534 static_cast<float>(viewport_.height()), | 1513 GLC(gl_, gl_->Uniform4fv(uniforms.viewport_location, 1, viewport)); |
| 1535 }; | 1514 GLC(gl_, gl_->Uniform3fv(uniforms.edge_location, 8, edge)); |
| 1536 GLC(Context(), | |
| 1537 Context()->uniform4fv(uniforms.viewport_location, 1, viewport)); | |
| 1538 GLC(Context(), Context()->uniform3fv(uniforms.edge_location, 8, edge)); | |
| 1539 | 1515 |
| 1540 GLC(Context(), | 1516 GLC(gl_, |
| 1541 Context()->uniform4f(uniforms.vertex_tex_transform_location, | 1517 gl_->Uniform4f(uniforms.vertex_tex_transform_location, |
| 1542 vertex_tex_translate_x, | 1518 vertex_tex_translate_x, |
| 1543 vertex_tex_translate_y, | 1519 vertex_tex_translate_y, |
| 1544 vertex_tex_scale_x, | 1520 vertex_tex_scale_x, |
| 1545 vertex_tex_scale_y)); | 1521 vertex_tex_scale_y)); |
| 1546 GLC(Context(), | 1522 GLC(gl_, |
| 1547 Context()->uniform4f(uniforms.fragment_tex_transform_location, | 1523 gl_->Uniform4f(uniforms.fragment_tex_transform_location, |
| 1548 fragment_tex_translate_x, | 1524 fragment_tex_translate_x, |
| 1549 fragment_tex_translate_y, | 1525 fragment_tex_translate_y, |
| 1550 fragment_tex_scale_x, | 1526 fragment_tex_scale_x, |
| 1551 fragment_tex_scale_y)); | 1527 fragment_tex_scale_y)); |
| 1552 } else { | 1528 } else { |
| 1553 // Move fragment shader transform to vertex shader. We can do this while | 1529 // Move fragment shader transform to vertex shader. We can do this while |
| 1554 // still producing correct results as fragment_tex_transform_location | 1530 // still producing correct results as fragment_tex_transform_location |
| 1555 // should always be non-negative when tiles are transformed in a way | 1531 // should always be non-negative when tiles are transformed in a way |
| 1556 // that could result in sampling outside the layer. | 1532 // that could result in sampling outside the layer. |
| 1557 vertex_tex_scale_x *= fragment_tex_scale_x; | 1533 vertex_tex_scale_x *= fragment_tex_scale_x; |
| 1558 vertex_tex_scale_y *= fragment_tex_scale_y; | 1534 vertex_tex_scale_y *= fragment_tex_scale_y; |
| 1559 vertex_tex_translate_x *= fragment_tex_scale_x; | 1535 vertex_tex_translate_x *= fragment_tex_scale_x; |
| 1560 vertex_tex_translate_y *= fragment_tex_scale_y; | 1536 vertex_tex_translate_y *= fragment_tex_scale_y; |
| 1561 vertex_tex_translate_x += fragment_tex_translate_x; | 1537 vertex_tex_translate_x += fragment_tex_translate_x; |
| 1562 vertex_tex_translate_y += fragment_tex_translate_y; | 1538 vertex_tex_translate_y += fragment_tex_translate_y; |
| 1563 | 1539 |
| 1564 GLC(Context(), | 1540 GLC(gl_, |
| 1565 Context()->uniform4f(uniforms.vertex_tex_transform_location, | 1541 gl_->Uniform4f(uniforms.vertex_tex_transform_location, |
| 1566 vertex_tex_translate_x, | 1542 vertex_tex_translate_x, |
| 1567 vertex_tex_translate_y, | 1543 vertex_tex_translate_y, |
| 1568 vertex_tex_scale_x, | 1544 vertex_tex_scale_x, |
| 1569 vertex_tex_scale_y)); | 1545 vertex_tex_scale_y)); |
| 1570 } | 1546 } |
| 1571 | 1547 |
| 1572 // Enable blending when the quad properties require it or if we decided | 1548 // Enable blending when the quad properties require it or if we decided |
| 1573 // to use antialiasing. | 1549 // to use antialiasing. |
| 1574 SetBlendEnabled(quad->ShouldDrawWithBlending() || use_aa); | 1550 SetBlendEnabled(quad->ShouldDrawWithBlending() || use_aa); |
| 1575 | 1551 |
| 1576 // Normalize to tile_rect. | 1552 // Normalize to tile_rect. |
| 1577 local_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); | 1553 local_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); |
| 1578 | 1554 |
| 1579 SetShaderOpacity(quad->opacity(), uniforms.alpha_location); | 1555 SetShaderOpacity(quad->opacity(), uniforms.alpha_location); |
| 1580 SetShaderQuadF(local_quad, uniforms.quad_location); | 1556 SetShaderQuadF(local_quad, uniforms.quad_location); |
| 1581 | 1557 |
| 1582 // The transform and vertex data are used to figure out the extents that the | 1558 // The transform and vertex data are used to figure out the extents that the |
| 1583 // un-antialiased quad should have and which vertex this is and the float | 1559 // un-antialiased quad should have and which vertex this is and the float |
| 1584 // quad passed in via uniform is the actual geometry that gets used to draw | 1560 // quad passed in via uniform is the actual geometry that gets used to draw |
| 1585 // it. This is why this centered rect is used and not the original quad_rect. | 1561 // it. This is why this centered rect is used and not the original quad_rect. |
| 1586 gfx::RectF centered_rect( | 1562 gfx::RectF centered_rect( |
| 1587 gfx::PointF(-0.5f * tile_rect.width(), -0.5f * tile_rect.height()), | 1563 gfx::PointF(-0.5f * tile_rect.width(), -0.5f * tile_rect.height()), |
| 1588 tile_rect.size()); | 1564 tile_rect.size()); |
| 1589 DrawQuadGeometry( | 1565 DrawQuadGeometry( |
| 1590 frame, quad->quadTransform(), centered_rect, uniforms.matrix_location); | 1566 frame, quad->quadTransform(), centered_rect, uniforms.matrix_location); |
| 1591 } | 1567 } |
| 1592 | 1568 |
| 1593 void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, | 1569 void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, |
| 1594 const YUVVideoDrawQuad* quad) { | 1570 const YUVVideoDrawQuad* quad) { |
| 1595 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 1571 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 1596 | 1572 |
| 1597 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 1573 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 1598 gl_, &highp_threshold_cache_, highp_threshold_min_, | 1574 gl_, |
| 1575 &highp_threshold_cache_, |
| 1576 highp_threshold_min_, |
| 1599 quad->shared_quad_state->visible_content_rect.bottom_right()); | 1577 quad->shared_quad_state->visible_content_rect.bottom_right()); |
| 1600 | 1578 |
| 1601 bool use_alpha_plane = quad->a_plane_resource_id != 0; | 1579 bool use_alpha_plane = quad->a_plane_resource_id != 0; |
| 1602 | 1580 |
| 1603 ResourceProvider::ScopedSamplerGL y_plane_lock( | 1581 ResourceProvider::ScopedSamplerGL y_plane_lock( |
| 1604 resource_provider_, | 1582 resource_provider_, quad->y_plane_resource_id, GL_TEXTURE1, GL_LINEAR); |
| 1605 quad->y_plane_resource_id, | |
| 1606 GL_TEXTURE1, | |
| 1607 GL_LINEAR); | |
| 1608 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), y_plane_lock.target()); | 1583 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), y_plane_lock.target()); |
| 1609 ResourceProvider::ScopedSamplerGL u_plane_lock( | 1584 ResourceProvider::ScopedSamplerGL u_plane_lock( |
| 1610 resource_provider_, | 1585 resource_provider_, quad->u_plane_resource_id, GL_TEXTURE2, GL_LINEAR); |
| 1611 quad->u_plane_resource_id, | |
| 1612 GL_TEXTURE2, | |
| 1613 GL_LINEAR); | |
| 1614 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), u_plane_lock.target()); | 1586 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), u_plane_lock.target()); |
| 1615 ResourceProvider::ScopedSamplerGL v_plane_lock( | 1587 ResourceProvider::ScopedSamplerGL v_plane_lock( |
| 1616 resource_provider_, | 1588 resource_provider_, quad->v_plane_resource_id, GL_TEXTURE3, GL_LINEAR); |
| 1617 quad->v_plane_resource_id, | |
| 1618 GL_TEXTURE3, | |
| 1619 GL_LINEAR); | |
| 1620 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), v_plane_lock.target()); | 1589 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), v_plane_lock.target()); |
| 1621 scoped_ptr<ResourceProvider::ScopedSamplerGL> a_plane_lock; | 1590 scoped_ptr<ResourceProvider::ScopedSamplerGL> a_plane_lock; |
| 1622 if (use_alpha_plane) { | 1591 if (use_alpha_plane) { |
| 1623 a_plane_lock.reset(new ResourceProvider::ScopedSamplerGL( | 1592 a_plane_lock.reset(new ResourceProvider::ScopedSamplerGL( |
| 1624 resource_provider_, | 1593 resource_provider_, quad->a_plane_resource_id, GL_TEXTURE4, GL_LINEAR)); |
| 1625 quad->a_plane_resource_id, | |
| 1626 GL_TEXTURE4, | |
| 1627 GL_LINEAR)); | |
| 1628 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), a_plane_lock->target()); | 1594 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), a_plane_lock->target()); |
| 1629 } | 1595 } |
| 1630 | 1596 |
| 1631 int tex_scale_location = -1; | 1597 int tex_scale_location = -1; |
| 1632 int matrix_location = -1; | 1598 int matrix_location = -1; |
| 1633 int y_texture_location = -1; | 1599 int y_texture_location = -1; |
| 1634 int u_texture_location = -1; | 1600 int u_texture_location = -1; |
| 1635 int v_texture_location = -1; | 1601 int v_texture_location = -1; |
| 1636 int a_texture_location = -1; | 1602 int a_texture_location = -1; |
| 1637 int yuv_matrix_location = -1; | 1603 int yuv_matrix_location = -1; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1657 tex_scale_location = program->vertex_shader().tex_scale_location(); | 1623 tex_scale_location = program->vertex_shader().tex_scale_location(); |
| 1658 matrix_location = program->vertex_shader().matrix_location(); | 1624 matrix_location = program->vertex_shader().matrix_location(); |
| 1659 y_texture_location = program->fragment_shader().y_texture_location(); | 1625 y_texture_location = program->fragment_shader().y_texture_location(); |
| 1660 u_texture_location = program->fragment_shader().u_texture_location(); | 1626 u_texture_location = program->fragment_shader().u_texture_location(); |
| 1661 v_texture_location = program->fragment_shader().v_texture_location(); | 1627 v_texture_location = program->fragment_shader().v_texture_location(); |
| 1662 yuv_matrix_location = program->fragment_shader().yuv_matrix_location(); | 1628 yuv_matrix_location = program->fragment_shader().yuv_matrix_location(); |
| 1663 yuv_adj_location = program->fragment_shader().yuv_adj_location(); | 1629 yuv_adj_location = program->fragment_shader().yuv_adj_location(); |
| 1664 alpha_location = program->fragment_shader().alpha_location(); | 1630 alpha_location = program->fragment_shader().alpha_location(); |
| 1665 } | 1631 } |
| 1666 | 1632 |
| 1667 GLC(Context(), | 1633 GLC(gl_, |
| 1668 Context()->uniform2f(tex_scale_location, | 1634 gl_->Uniform2f(tex_scale_location, |
| 1669 quad->tex_scale.width(), | 1635 quad->tex_scale.width(), |
| 1670 quad->tex_scale.height())); | 1636 quad->tex_scale.height())); |
| 1671 GLC(Context(), Context()->uniform1i(y_texture_location, 1)); | 1637 GLC(gl_, gl_->Uniform1i(y_texture_location, 1)); |
| 1672 GLC(Context(), Context()->uniform1i(u_texture_location, 2)); | 1638 GLC(gl_, gl_->Uniform1i(u_texture_location, 2)); |
| 1673 GLC(Context(), Context()->uniform1i(v_texture_location, 3)); | 1639 GLC(gl_, gl_->Uniform1i(v_texture_location, 3)); |
| 1674 if (use_alpha_plane) | 1640 if (use_alpha_plane) |
| 1675 GLC(Context(), Context()->uniform1i(a_texture_location, 4)); | 1641 GLC(gl_, gl_->Uniform1i(a_texture_location, 4)); |
| 1676 | 1642 |
| 1677 // These values are magic numbers that are used in the transformation from YUV | 1643 // These values are magic numbers that are used in the transformation from YUV |
| 1678 // to RGB color values. They are taken from the following webpage: | 1644 // to RGB color values. They are taken from the following webpage: |
| 1679 // http://www.fourcc.org/fccyvrgb.php | 1645 // http://www.fourcc.org/fccyvrgb.php |
| 1680 float yuv_to_rgb[9] = { | 1646 float yuv_to_rgb[9] = {1.164f, 1.164f, 1.164f, 0.0f, -.391f, |
| 1681 1.164f, 1.164f, 1.164f, | 1647 2.018f, 1.596f, -.813f, 0.0f, }; |
| 1682 0.0f, -.391f, 2.018f, | 1648 GLC(gl_, gl_->UniformMatrix3fv(yuv_matrix_location, 1, 0, yuv_to_rgb)); |
| 1683 1.596f, -.813f, 0.0f, | |
| 1684 }; | |
| 1685 GLC(Context(), | |
| 1686 Context()->uniformMatrix3fv(yuv_matrix_location, 1, 0, yuv_to_rgb)); | |
| 1687 | 1649 |
| 1688 // These values map to 16, 128, and 128 respectively, and are computed | 1650 // These values map to 16, 128, and 128 respectively, and are computed |
| 1689 // as a fraction over 256 (e.g. 16 / 256 = 0.0625). | 1651 // as a fraction over 256 (e.g. 16 / 256 = 0.0625). |
| 1690 // They are used in the YUV to RGBA conversion formula: | 1652 // They are used in the YUV to RGBA conversion formula: |
| 1691 // Y - 16 : Gives 16 values of head and footroom for overshooting | 1653 // Y - 16 : Gives 16 values of head and footroom for overshooting |
| 1692 // U - 128 : Turns unsigned U into signed U [-128,127] | 1654 // U - 128 : Turns unsigned U into signed U [-128,127] |
| 1693 // V - 128 : Turns unsigned V into signed V [-128,127] | 1655 // V - 128 : Turns unsigned V into signed V [-128,127] |
| 1694 float yuv_adjust[3] = { -0.0625f, -0.5f, -0.5f, }; | 1656 float yuv_adjust[3] = {-0.0625f, -0.5f, -0.5f, }; |
| 1695 GLC(Context(), Context()->uniform3fv(yuv_adj_location, 1, yuv_adjust)); | 1657 GLC(gl_, gl_->Uniform3fv(yuv_adj_location, 1, yuv_adjust)); |
| 1696 | |
| 1697 | 1658 |
| 1698 SetShaderOpacity(quad->opacity(), alpha_location); | 1659 SetShaderOpacity(quad->opacity(), alpha_location); |
| 1699 DrawQuadGeometry(frame, quad->quadTransform(), quad->rect, matrix_location); | 1660 DrawQuadGeometry(frame, quad->quadTransform(), quad->rect, matrix_location); |
| 1700 } | 1661 } |
| 1701 | 1662 |
| 1702 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame, | 1663 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame, |
| 1703 const StreamVideoDrawQuad* quad) { | 1664 const StreamVideoDrawQuad* quad) { |
| 1704 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 1665 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 1705 | 1666 |
| 1706 static float gl_matrix[16]; | 1667 static float gl_matrix[16]; |
| 1707 | 1668 |
| 1708 DCHECK(capabilities_.using_egl_image); | 1669 DCHECK(capabilities_.using_egl_image); |
| 1709 | 1670 |
| 1710 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 1671 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 1711 gl_, &highp_threshold_cache_, highp_threshold_min_, | 1672 gl_, |
| 1673 &highp_threshold_cache_, |
| 1674 highp_threshold_min_, |
| 1712 quad->shared_quad_state->visible_content_rect.bottom_right()); | 1675 quad->shared_quad_state->visible_content_rect.bottom_right()); |
| 1713 | 1676 |
| 1714 const VideoStreamTextureProgram* program = | 1677 const VideoStreamTextureProgram* program = |
| 1715 GetVideoStreamTextureProgram(tex_coord_precision); | 1678 GetVideoStreamTextureProgram(tex_coord_precision); |
| 1716 SetUseProgram(program->program()); | 1679 SetUseProgram(program->program()); |
| 1717 | 1680 |
| 1718 ToGLMatrix(&gl_matrix[0], quad->matrix); | 1681 ToGLMatrix(&gl_matrix[0], quad->matrix); |
| 1719 GLC(Context(), | 1682 GLC(gl_, |
| 1720 Context()->uniformMatrix4fv( | 1683 gl_->UniformMatrix4fv( |
| 1721 program->vertex_shader().tex_matrix_location(), 1, false, gl_matrix)); | 1684 program->vertex_shader().tex_matrix_location(), 1, false, gl_matrix)); |
| 1722 | 1685 |
| 1723 ResourceProvider::ScopedReadLockGL lock(resource_provider_, | 1686 ResourceProvider::ScopedReadLockGL lock(resource_provider_, |
| 1724 quad->resource_id); | 1687 quad->resource_id); |
| 1725 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(Context())); | 1688 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(Context())); |
| 1726 GLC(Context(), | 1689 GLC(gl_, gl_->BindTexture(GL_TEXTURE_EXTERNAL_OES, lock.texture_id())); |
| 1727 Context()->bindTexture(GL_TEXTURE_EXTERNAL_OES, lock.texture_id())); | |
| 1728 | 1690 |
| 1729 GLC(Context(), | 1691 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 1730 Context()->uniform1i(program->fragment_shader().sampler_location(), 0)); | |
| 1731 | 1692 |
| 1732 SetShaderOpacity(quad->opacity(), | 1693 SetShaderOpacity(quad->opacity(), |
| 1733 program->fragment_shader().alpha_location()); | 1694 program->fragment_shader().alpha_location()); |
| 1734 DrawQuadGeometry(frame, | 1695 DrawQuadGeometry(frame, |
| 1735 quad->quadTransform(), | 1696 quad->quadTransform(), |
| 1736 quad->rect, | 1697 quad->rect, |
| 1737 program->vertex_shader().matrix_location()); | 1698 program->vertex_shader().matrix_location()); |
| 1738 } | 1699 } |
| 1739 | 1700 |
| 1740 void GLRenderer::DrawPictureQuad(const DrawingFrame* frame, | 1701 void GLRenderer::DrawPictureQuad(const DrawingFrame* frame, |
| 1741 const PictureDrawQuad* quad) { | 1702 const PictureDrawQuad* quad) { |
| 1742 if (on_demand_tile_raster_bitmap_.width() != quad->texture_size.width() || | 1703 if (on_demand_tile_raster_bitmap_.width() != quad->texture_size.width() || |
| 1743 on_demand_tile_raster_bitmap_.height() != quad->texture_size.height()) { | 1704 on_demand_tile_raster_bitmap_.height() != quad->texture_size.height()) { |
| 1744 on_demand_tile_raster_bitmap_.setConfig( | 1705 on_demand_tile_raster_bitmap_.setConfig(SkBitmap::kARGB_8888_Config, |
| 1745 SkBitmap::kARGB_8888_Config, | 1706 quad->texture_size.width(), |
| 1746 quad->texture_size.width(), | 1707 quad->texture_size.height()); |
| 1747 quad->texture_size.height()); | |
| 1748 on_demand_tile_raster_bitmap_.allocPixels(); | 1708 on_demand_tile_raster_bitmap_.allocPixels(); |
| 1749 | 1709 |
| 1750 if (on_demand_tile_raster_resource_id_) | 1710 if (on_demand_tile_raster_resource_id_) |
| 1751 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_); | 1711 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_); |
| 1752 | 1712 |
| 1753 on_demand_tile_raster_resource_id_ = resource_provider_->CreateGLTexture( | 1713 on_demand_tile_raster_resource_id_ = |
| 1754 quad->texture_size, | 1714 resource_provider_->CreateGLTexture(quad->texture_size, |
| 1755 GL_TEXTURE_2D, | 1715 GL_TEXTURE_2D, |
| 1756 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, | 1716 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, |
| 1757 GL_CLAMP_TO_EDGE, | 1717 GL_CLAMP_TO_EDGE, |
| 1758 ResourceProvider::TextureUsageAny, | 1718 ResourceProvider::TextureUsageAny, |
| 1759 quad->texture_format); | 1719 quad->texture_format); |
| 1760 } | 1720 } |
| 1761 | 1721 |
| 1762 SkBitmapDevice device(on_demand_tile_raster_bitmap_); | 1722 SkBitmapDevice device(on_demand_tile_raster_bitmap_); |
| 1763 SkCanvas canvas(&device); | 1723 SkCanvas canvas(&device); |
| 1764 | 1724 |
| 1765 quad->picture_pile->RasterToBitmap(&canvas, quad->content_rect, | 1725 quad->picture_pile->RasterToBitmap( |
| 1766 quad->contents_scale, NULL); | 1726 &canvas, quad->content_rect, quad->contents_scale, NULL); |
| 1767 | 1727 |
| 1768 uint8_t* bitmap_pixels = NULL; | 1728 uint8_t* bitmap_pixels = NULL; |
| 1769 SkBitmap on_demand_tile_raster_bitmap_dest; | 1729 SkBitmap on_demand_tile_raster_bitmap_dest; |
| 1770 SkBitmap::Config config = SkBitmapConfig(quad->texture_format); | 1730 SkBitmap::Config config = SkBitmapConfig(quad->texture_format); |
| 1771 if (on_demand_tile_raster_bitmap_.getConfig() != config) { | 1731 if (on_demand_tile_raster_bitmap_.getConfig() != config) { |
| 1772 on_demand_tile_raster_bitmap_.copyTo(&on_demand_tile_raster_bitmap_dest, | 1732 on_demand_tile_raster_bitmap_.copyTo(&on_demand_tile_raster_bitmap_dest, |
| 1773 config); | 1733 config); |
| 1774 // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the | 1734 // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the |
| 1775 // bitmap data. This check will be removed once crbug.com/293728 is fixed. | 1735 // bitmap data. This check will be removed once crbug.com/293728 is fixed. |
| 1776 CHECK_EQ(0u, on_demand_tile_raster_bitmap_dest.rowBytes() % 4); | 1736 CHECK_EQ(0u, on_demand_tile_raster_bitmap_dest.rowBytes() % 4); |
| 1777 bitmap_pixels = reinterpret_cast<uint8_t*>( | 1737 bitmap_pixels = reinterpret_cast<uint8_t*>( |
| 1778 on_demand_tile_raster_bitmap_dest.getPixels()); | 1738 on_demand_tile_raster_bitmap_dest.getPixels()); |
| 1779 } else { | 1739 } else { |
| 1780 bitmap_pixels = reinterpret_cast<uint8_t*>( | 1740 bitmap_pixels = |
| 1781 on_demand_tile_raster_bitmap_.getPixels()); | 1741 reinterpret_cast<uint8_t*>(on_demand_tile_raster_bitmap_.getPixels()); |
| 1782 } | 1742 } |
| 1783 | 1743 |
| 1784 resource_provider_->SetPixels( | 1744 resource_provider_->SetPixels(on_demand_tile_raster_resource_id_, |
| 1785 on_demand_tile_raster_resource_id_, | 1745 bitmap_pixels, |
| 1786 bitmap_pixels, | 1746 gfx::Rect(quad->texture_size), |
| 1787 gfx::Rect(quad->texture_size), | 1747 gfx::Rect(quad->texture_size), |
| 1788 gfx::Rect(quad->texture_size), | 1748 gfx::Vector2d()); |
| 1789 gfx::Vector2d()); | |
| 1790 | 1749 |
| 1791 DrawContentQuad(frame, quad, on_demand_tile_raster_resource_id_); | 1750 DrawContentQuad(frame, quad, on_demand_tile_raster_resource_id_); |
| 1792 } | 1751 } |
| 1793 | 1752 |
| 1794 struct TextureProgramBinding { | 1753 struct TextureProgramBinding { |
| 1795 template <class Program> | 1754 template <class Program> |
| 1796 void Set(Program* program) { | 1755 void Set(Program* program) { |
| 1797 DCHECK(program); | 1756 DCHECK(program); |
| 1798 program_id = program->program(); | 1757 program_id = program->program(); |
| 1799 sampler_location = program->fragment_shader().sampler_location(); | 1758 sampler_location = program->fragment_shader().sampler_location(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1824 if (draw_cache_.program_id == 0) | 1783 if (draw_cache_.program_id == 0) |
| 1825 return; | 1784 return; |
| 1826 | 1785 |
| 1827 // Set the correct blending mode. | 1786 // Set the correct blending mode. |
| 1828 SetBlendEnabled(draw_cache_.needs_blending); | 1787 SetBlendEnabled(draw_cache_.needs_blending); |
| 1829 | 1788 |
| 1830 // Bind the program to the GL state. | 1789 // Bind the program to the GL state. |
| 1831 SetUseProgram(draw_cache_.program_id); | 1790 SetUseProgram(draw_cache_.program_id); |
| 1832 | 1791 |
| 1833 // Bind the correct texture sampler location. | 1792 // Bind the correct texture sampler location. |
| 1834 GLC(Context(), Context()->uniform1i(draw_cache_.sampler_location, 0)); | 1793 GLC(gl_, gl_->Uniform1i(draw_cache_.sampler_location, 0)); |
| 1835 | 1794 |
| 1836 // Assume the current active textures is 0. | 1795 // Assume the current active textures is 0. |
| 1837 ResourceProvider::ScopedReadLockGL locked_quad(resource_provider_, | 1796 ResourceProvider::ScopedReadLockGL locked_quad(resource_provider_, |
| 1838 draw_cache_.resource_id); | 1797 draw_cache_.resource_id); |
| 1839 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(Context())); | 1798 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(Context())); |
| 1840 GLC(Context(), | 1799 GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, locked_quad.texture_id())); |
| 1841 Context()->bindTexture(GL_TEXTURE_2D, locked_quad.texture_id())); | |
| 1842 | 1800 |
| 1843 COMPILE_ASSERT( | 1801 COMPILE_ASSERT(sizeof(Float4) == 4 * sizeof(float), // NOLINT(runtime/sizeof) |
| 1844 sizeof(Float4) == 4 * sizeof(float), // NOLINT(runtime/sizeof) | 1802 struct_is_densely_packed); |
| 1845 struct_is_densely_packed); | |
| 1846 COMPILE_ASSERT( | 1803 COMPILE_ASSERT( |
| 1847 sizeof(Float16) == 16 * sizeof(float), // NOLINT(runtime/sizeof) | 1804 sizeof(Float16) == 16 * sizeof(float), // NOLINT(runtime/sizeof) |
| 1848 struct_is_densely_packed); | 1805 struct_is_densely_packed); |
| 1849 | 1806 |
| 1850 // Upload the tranforms for both points and uvs. | 1807 // Upload the tranforms for both points and uvs. |
| 1851 GLC(context_, | 1808 GLC(gl_, |
| 1852 context_->uniformMatrix4fv( | 1809 gl_->UniformMatrix4fv( |
| 1853 static_cast<int>(draw_cache_.matrix_location), | 1810 static_cast<int>(draw_cache_.matrix_location), |
| 1854 static_cast<int>(draw_cache_.matrix_data.size()), | 1811 static_cast<int>(draw_cache_.matrix_data.size()), |
| 1855 false, | 1812 false, |
| 1856 reinterpret_cast<float*>(&draw_cache_.matrix_data.front()))); | 1813 reinterpret_cast<float*>(&draw_cache_.matrix_data.front()))); |
| 1857 GLC(context_, | 1814 GLC(gl_, |
| 1858 context_->uniform4fv( | 1815 gl_->Uniform4fv( |
| 1859 static_cast<int>(draw_cache_.uv_xform_location), | 1816 static_cast<int>(draw_cache_.uv_xform_location), |
| 1860 static_cast<int>(draw_cache_.uv_xform_data.size()), | 1817 static_cast<int>(draw_cache_.uv_xform_data.size()), |
| 1861 reinterpret_cast<float*>(&draw_cache_.uv_xform_data.front()))); | 1818 reinterpret_cast<float*>(&draw_cache_.uv_xform_data.front()))); |
| 1862 | 1819 |
| 1863 if (draw_cache_.background_color != SK_ColorTRANSPARENT) { | 1820 if (draw_cache_.background_color != SK_ColorTRANSPARENT) { |
| 1864 Float4 background_color = PremultipliedColor(draw_cache_.background_color); | 1821 Float4 background_color = PremultipliedColor(draw_cache_.background_color); |
| 1865 GLC(context_, | 1822 GLC(gl_, |
| 1866 context_->uniform4fv( | 1823 gl_->Uniform4fv( |
| 1867 draw_cache_.background_color_location, 1, background_color.data)); | 1824 draw_cache_.background_color_location, 1, background_color.data)); |
| 1868 } | 1825 } |
| 1869 | 1826 |
| 1870 GLC(context_, | 1827 GLC(gl_, |
| 1871 context_->uniform1fv( | 1828 gl_->Uniform1fv( |
| 1872 static_cast<int>(draw_cache_.vertex_opacity_location), | 1829 static_cast<int>(draw_cache_.vertex_opacity_location), |
| 1873 static_cast<int>(draw_cache_.vertex_opacity_data.size()), | 1830 static_cast<int>(draw_cache_.vertex_opacity_data.size()), |
| 1874 static_cast<float*>(&draw_cache_.vertex_opacity_data.front()))); | 1831 static_cast<float*>(&draw_cache_.vertex_opacity_data.front()))); |
| 1875 | 1832 |
| 1876 // Draw the quads! | 1833 // Draw the quads! |
| 1877 GLC(context_, | 1834 GLC(gl_, |
| 1878 context_->drawElements(GL_TRIANGLES, | 1835 gl_->DrawElements(GL_TRIANGLES, |
| 1879 6 * draw_cache_.matrix_data.size(), | 1836 6 * draw_cache_.matrix_data.size(), |
| 1880 GL_UNSIGNED_SHORT, | 1837 GL_UNSIGNED_SHORT, |
| 1881 0)); | 1838 0)); |
| 1882 | 1839 |
| 1883 // Clear the cache. | 1840 // Clear the cache. |
| 1884 draw_cache_.program_id = 0; | 1841 draw_cache_.program_id = 0; |
| 1885 draw_cache_.uv_xform_data.resize(0); | 1842 draw_cache_.uv_xform_data.resize(0); |
| 1886 draw_cache_.vertex_opacity_data.resize(0); | 1843 draw_cache_.vertex_opacity_data.resize(0); |
| 1887 draw_cache_.matrix_data.resize(0); | 1844 draw_cache_.matrix_data.resize(0); |
| 1888 } | 1845 } |
| 1889 | 1846 |
| 1890 void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame, | 1847 void GLRenderer::EnqueueTextureQuad(const DrawingFrame* frame, |
| 1891 const TextureDrawQuad* quad) { | 1848 const TextureDrawQuad* quad) { |
| 1892 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 1849 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 1893 gl_, &highp_threshold_cache_, highp_threshold_min_, | 1850 gl_, |
| 1851 &highp_threshold_cache_, |
| 1852 highp_threshold_min_, |
| 1894 quad->shared_quad_state->visible_content_rect.bottom_right()); | 1853 quad->shared_quad_state->visible_content_rect.bottom_right()); |
| 1895 | 1854 |
| 1896 // Choose the correct texture program binding | 1855 // Choose the correct texture program binding |
| 1897 TexTransformTextureProgramBinding binding; | 1856 TexTransformTextureProgramBinding binding; |
| 1898 if (quad->premultiplied_alpha) { | 1857 if (quad->premultiplied_alpha) { |
| 1899 if (quad->background_color == SK_ColorTRANSPARENT) { | 1858 if (quad->background_color == SK_ColorTRANSPARENT) { |
| 1900 binding.Set(GetTextureProgram(tex_coord_precision)); | 1859 binding.Set(GetTextureProgram(tex_coord_precision)); |
| 1901 } else { | 1860 } else { |
| 1902 binding.Set(GetTextureBackgroundProgram(tex_coord_precision)); | 1861 binding.Set(GetTextureBackgroundProgram(tex_coord_precision)); |
| 1903 } | 1862 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1948 Float16 m; | 1907 Float16 m; |
| 1949 quad_rect_matrix.matrix().asColMajorf(m.data); | 1908 quad_rect_matrix.matrix().asColMajorf(m.data); |
| 1950 draw_cache_.matrix_data.push_back(m); | 1909 draw_cache_.matrix_data.push_back(m); |
| 1951 } | 1910 } |
| 1952 | 1911 |
| 1953 void GLRenderer::DrawIOSurfaceQuad(const DrawingFrame* frame, | 1912 void GLRenderer::DrawIOSurfaceQuad(const DrawingFrame* frame, |
| 1954 const IOSurfaceDrawQuad* quad) { | 1913 const IOSurfaceDrawQuad* quad) { |
| 1955 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 1914 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 1956 | 1915 |
| 1957 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 1916 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 1958 gl_, &highp_threshold_cache_, highp_threshold_min_, | 1917 gl_, |
| 1918 &highp_threshold_cache_, |
| 1919 highp_threshold_min_, |
| 1959 quad->shared_quad_state->visible_content_rect.bottom_right()); | 1920 quad->shared_quad_state->visible_content_rect.bottom_right()); |
| 1960 | 1921 |
| 1961 TexTransformTextureProgramBinding binding; | 1922 TexTransformTextureProgramBinding binding; |
| 1962 binding.Set(GetTextureIOSurfaceProgram(tex_coord_precision)); | 1923 binding.Set(GetTextureIOSurfaceProgram(tex_coord_precision)); |
| 1963 | 1924 |
| 1964 SetUseProgram(binding.program_id); | 1925 SetUseProgram(binding.program_id); |
| 1965 GLC(Context(), Context()->uniform1i(binding.sampler_location, 0)); | 1926 GLC(gl_, gl_->Uniform1i(binding.sampler_location, 0)); |
| 1966 if (quad->orientation == IOSurfaceDrawQuad::FLIPPED) { | 1927 if (quad->orientation == IOSurfaceDrawQuad::FLIPPED) { |
| 1967 GLC(Context(), | 1928 GLC(gl_, |
| 1968 Context()->uniform4f(binding.tex_transform_location, | 1929 gl_->Uniform4f(binding.tex_transform_location, |
| 1969 0, | 1930 0, |
| 1970 quad->io_surface_size.height(), | 1931 quad->io_surface_size.height(), |
| 1971 quad->io_surface_size.width(), | 1932 quad->io_surface_size.width(), |
| 1972 quad->io_surface_size.height() * -1.0f)); | 1933 quad->io_surface_size.height() * -1.0f)); |
| 1973 } else { | 1934 } else { |
| 1974 GLC(Context(), | 1935 GLC(gl_, |
| 1975 Context()->uniform4f(binding.tex_transform_location, | 1936 gl_->Uniform4f(binding.tex_transform_location, |
| 1976 0, | 1937 0, |
| 1977 0, | 1938 0, |
| 1978 quad->io_surface_size.width(), | 1939 quad->io_surface_size.width(), |
| 1979 quad->io_surface_size.height())); | 1940 quad->io_surface_size.height())); |
| 1980 } | 1941 } |
| 1981 | 1942 |
| 1982 const float vertex_opacity[] = { quad->opacity(), quad->opacity(), | 1943 const float vertex_opacity[] = {quad->opacity(), quad->opacity(), |
| 1983 quad->opacity(), quad->opacity() }; | 1944 quad->opacity(), quad->opacity()}; |
| 1984 GLC(Context(), | 1945 GLC(gl_, gl_->Uniform1fv(binding.vertex_opacity_location, 4, vertex_opacity)); |
| 1985 Context()->uniform1fv( | |
| 1986 binding.vertex_opacity_location, 4, vertex_opacity)); | |
| 1987 | 1946 |
| 1988 ResourceProvider::ScopedReadLockGL lock(resource_provider_, | 1947 ResourceProvider::ScopedReadLockGL lock(resource_provider_, |
| 1989 quad->io_surface_resource_id); | 1948 quad->io_surface_resource_id); |
| 1990 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(Context())); | 1949 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(Context())); |
| 1991 GLC(Context(), | 1950 GLC(gl_, gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, lock.texture_id())); |
| 1992 Context()->bindTexture(GL_TEXTURE_RECTANGLE_ARB, | |
| 1993 lock.texture_id())); | |
| 1994 | 1951 |
| 1995 DrawQuadGeometry( | 1952 DrawQuadGeometry( |
| 1996 frame, quad->quadTransform(), quad->rect, binding.matrix_location); | 1953 frame, quad->quadTransform(), quad->rect, binding.matrix_location); |
| 1997 | 1954 |
| 1998 GLC(Context(), Context()->bindTexture(GL_TEXTURE_RECTANGLE_ARB, 0)); | 1955 GLC(gl_, gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, 0)); |
| 1999 } | 1956 } |
| 2000 | 1957 |
| 2001 void GLRenderer::FinishDrawingFrame(DrawingFrame* frame) { | 1958 void GLRenderer::FinishDrawingFrame(DrawingFrame* frame) { |
| 2002 current_framebuffer_lock_.reset(); | 1959 current_framebuffer_lock_.reset(); |
| 2003 swap_buffer_rect_.Union(gfx::ToEnclosingRect(frame->root_damage_rect)); | 1960 swap_buffer_rect_.Union(gfx::ToEnclosingRect(frame->root_damage_rect)); |
| 2004 | 1961 |
| 2005 GLC(context_, context_->disable(GL_BLEND)); | 1962 GLC(gl_, gl_->Disable(GL_BLEND)); |
| 2006 blend_shadow_ = false; | 1963 blend_shadow_ = false; |
| 2007 } | 1964 } |
| 2008 | 1965 |
| 2009 void GLRenderer::FinishDrawingQuadList() { FlushTextureQuadCache(); } | 1966 void GLRenderer::FinishDrawingQuadList() { FlushTextureQuadCache(); } |
| 2010 | 1967 |
| 2011 bool GLRenderer::FlippedFramebuffer() const { return true; } | 1968 bool GLRenderer::FlippedFramebuffer() const { return true; } |
| 2012 | 1969 |
| 2013 void GLRenderer::EnsureScissorTestEnabled() { | 1970 void GLRenderer::EnsureScissorTestEnabled() { |
| 2014 if (is_scissor_enabled_) | 1971 if (is_scissor_enabled_) |
| 2015 return; | 1972 return; |
| 2016 | 1973 |
| 2017 FlushTextureQuadCache(); | 1974 FlushTextureQuadCache(); |
| 2018 GLC(context_, context_->enable(GL_SCISSOR_TEST)); | 1975 GLC(gl_, gl_->Enable(GL_SCISSOR_TEST)); |
| 2019 is_scissor_enabled_ = true; | 1976 is_scissor_enabled_ = true; |
| 2020 } | 1977 } |
| 2021 | 1978 |
| 2022 void GLRenderer::EnsureScissorTestDisabled() { | 1979 void GLRenderer::EnsureScissorTestDisabled() { |
| 2023 if (!is_scissor_enabled_) | 1980 if (!is_scissor_enabled_) |
| 2024 return; | 1981 return; |
| 2025 | 1982 |
| 2026 FlushTextureQuadCache(); | 1983 FlushTextureQuadCache(); |
| 2027 GLC(context_, context_->disable(GL_SCISSOR_TEST)); | 1984 GLC(gl_, gl_->Disable(GL_SCISSOR_TEST)); |
| 2028 is_scissor_enabled_ = false; | 1985 is_scissor_enabled_ = false; |
| 2029 } | 1986 } |
| 2030 | 1987 |
| 2031 void GLRenderer::CopyCurrentRenderPassToBitmap( | 1988 void GLRenderer::CopyCurrentRenderPassToBitmap( |
| 2032 DrawingFrame* frame, | 1989 DrawingFrame* frame, |
| 2033 scoped_ptr<CopyOutputRequest> request) { | 1990 scoped_ptr<CopyOutputRequest> request) { |
| 2034 gfx::Rect copy_rect = frame->current_render_pass->output_rect; | 1991 gfx::Rect copy_rect = frame->current_render_pass->output_rect; |
| 2035 if (request->has_area()) | 1992 if (request->has_area()) |
| 2036 copy_rect.Intersect(request->area()); | 1993 copy_rect.Intersect(request->area()); |
| 2037 GetFramebufferPixelsAsync(copy_rect, request.Pass()); | 1994 GetFramebufferPixelsAsync(copy_rect, request.Pass()); |
| 2038 } | 1995 } |
| 2039 | 1996 |
| 2040 void GLRenderer::ToGLMatrix(float* gl_matrix, const gfx::Transform& transform) { | 1997 void GLRenderer::ToGLMatrix(float* gl_matrix, const gfx::Transform& transform) { |
| 2041 transform.matrix().asColMajorf(gl_matrix); | 1998 transform.matrix().asColMajorf(gl_matrix); |
| 2042 } | 1999 } |
| 2043 | 2000 |
| 2044 void GLRenderer::SetShaderQuadF(const gfx::QuadF& quad, int quad_location) { | 2001 void GLRenderer::SetShaderQuadF(const gfx::QuadF& quad, int quad_location) { |
| 2045 if (quad_location == -1) | 2002 if (quad_location == -1) |
| 2046 return; | 2003 return; |
| 2047 | 2004 |
| 2048 float gl_quad[8]; | 2005 float gl_quad[8]; |
| 2049 gl_quad[0] = quad.p1().x(); | 2006 gl_quad[0] = quad.p1().x(); |
| 2050 gl_quad[1] = quad.p1().y(); | 2007 gl_quad[1] = quad.p1().y(); |
| 2051 gl_quad[2] = quad.p2().x(); | 2008 gl_quad[2] = quad.p2().x(); |
| 2052 gl_quad[3] = quad.p2().y(); | 2009 gl_quad[3] = quad.p2().y(); |
| 2053 gl_quad[4] = quad.p3().x(); | 2010 gl_quad[4] = quad.p3().x(); |
| 2054 gl_quad[5] = quad.p3().y(); | 2011 gl_quad[5] = quad.p3().y(); |
| 2055 gl_quad[6] = quad.p4().x(); | 2012 gl_quad[6] = quad.p4().x(); |
| 2056 gl_quad[7] = quad.p4().y(); | 2013 gl_quad[7] = quad.p4().y(); |
| 2057 GLC(context_, context_->uniform2fv(quad_location, 4, gl_quad)); | 2014 GLC(gl_, gl_->Uniform2fv(quad_location, 4, gl_quad)); |
| 2058 } | 2015 } |
| 2059 | 2016 |
| 2060 void GLRenderer::SetShaderOpacity(float opacity, int alpha_location) { | 2017 void GLRenderer::SetShaderOpacity(float opacity, int alpha_location) { |
| 2061 if (alpha_location != -1) | 2018 if (alpha_location != -1) |
| 2062 GLC(context_, context_->uniform1f(alpha_location, opacity)); | 2019 GLC(gl_, gl_->Uniform1f(alpha_location, opacity)); |
| 2063 } | 2020 } |
| 2064 | 2021 |
| 2065 void GLRenderer::SetStencilEnabled(bool enabled) { | 2022 void GLRenderer::SetStencilEnabled(bool enabled) { |
| 2066 if (enabled == stencil_shadow_) | 2023 if (enabled == stencil_shadow_) |
| 2067 return; | 2024 return; |
| 2068 | 2025 |
| 2069 if (enabled) | 2026 if (enabled) |
| 2070 GLC(context_, context_->enable(GL_STENCIL_TEST)); | 2027 GLC(gl_, gl_->Enable(GL_STENCIL_TEST)); |
| 2071 else | 2028 else |
| 2072 GLC(context_, context_->disable(GL_STENCIL_TEST)); | 2029 GLC(gl_, gl_->Disable(GL_STENCIL_TEST)); |
| 2073 stencil_shadow_ = enabled; | 2030 stencil_shadow_ = enabled; |
| 2074 } | 2031 } |
| 2075 | 2032 |
| 2076 void GLRenderer::SetBlendEnabled(bool enabled) { | 2033 void GLRenderer::SetBlendEnabled(bool enabled) { |
| 2077 if (enabled == blend_shadow_) | 2034 if (enabled == blend_shadow_) |
| 2078 return; | 2035 return; |
| 2079 | 2036 |
| 2080 if (enabled) | 2037 if (enabled) |
| 2081 GLC(context_, context_->enable(GL_BLEND)); | 2038 GLC(gl_, gl_->Enable(GL_BLEND)); |
| 2082 else | 2039 else |
| 2083 GLC(context_, context_->disable(GL_BLEND)); | 2040 GLC(gl_, gl_->Disable(GL_BLEND)); |
| 2084 blend_shadow_ = enabled; | 2041 blend_shadow_ = enabled; |
| 2085 } | 2042 } |
| 2086 | 2043 |
| 2087 void GLRenderer::SetUseProgram(unsigned program) { | 2044 void GLRenderer::SetUseProgram(unsigned program) { |
| 2088 if (program == program_shadow_) | 2045 if (program == program_shadow_) |
| 2089 return; | 2046 return; |
| 2090 gl_->UseProgram(program); | 2047 gl_->UseProgram(program); |
| 2091 program_shadow_ = program; | 2048 program_shadow_ = program; |
| 2092 } | 2049 } |
| 2093 | 2050 |
| 2094 void GLRenderer::DrawQuadGeometry(const DrawingFrame* frame, | 2051 void GLRenderer::DrawQuadGeometry(const DrawingFrame* frame, |
| 2095 const gfx::Transform& draw_transform, | 2052 const gfx::Transform& draw_transform, |
| 2096 const gfx::RectF& quad_rect, | 2053 const gfx::RectF& quad_rect, |
| 2097 int matrix_location) { | 2054 int matrix_location) { |
| 2098 gfx::Transform quad_rect_matrix; | 2055 gfx::Transform quad_rect_matrix; |
| 2099 QuadRectTransform(&quad_rect_matrix, draw_transform, quad_rect); | 2056 QuadRectTransform(&quad_rect_matrix, draw_transform, quad_rect); |
| 2100 static float gl_matrix[16]; | 2057 static float gl_matrix[16]; |
| 2101 ToGLMatrix(&gl_matrix[0], frame->projection_matrix * quad_rect_matrix); | 2058 ToGLMatrix(&gl_matrix[0], frame->projection_matrix * quad_rect_matrix); |
| 2102 GLC(context_, | 2059 GLC(gl_, gl_->UniformMatrix4fv(matrix_location, 1, false, &gl_matrix[0])); |
| 2103 context_->uniformMatrix4fv(matrix_location, 1, false, &gl_matrix[0])); | |
| 2104 | 2060 |
| 2105 GLC(context_, context_->drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0)); | 2061 GLC(gl_, gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0)); |
| 2106 } | 2062 } |
| 2107 | 2063 |
| 2108 void GLRenderer::CopyTextureToFramebuffer(const DrawingFrame* frame, | 2064 void GLRenderer::CopyTextureToFramebuffer(const DrawingFrame* frame, |
| 2109 int texture_id, | 2065 int texture_id, |
| 2110 gfx::Rect rect, | 2066 gfx::Rect rect, |
| 2111 const gfx::Transform& draw_matrix, | 2067 const gfx::Transform& draw_matrix, |
| 2112 bool flip_vertically) { | 2068 bool flip_vertically) { |
| 2113 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 2069 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 2114 gl_, &highp_threshold_cache_, highp_threshold_min_, | 2070 gl_, &highp_threshold_cache_, highp_threshold_min_, rect.bottom_right()); |
| 2115 rect.bottom_right()); | |
| 2116 | 2071 |
| 2117 const RenderPassProgram* program = GetRenderPassProgram(tex_coord_precision); | 2072 const RenderPassProgram* program = GetRenderPassProgram(tex_coord_precision); |
| 2118 SetUseProgram(program->program()); | 2073 SetUseProgram(program->program()); |
| 2119 | 2074 |
| 2120 GLC(Context(), Context()->uniform1i( | 2075 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); |
| 2121 program->fragment_shader().sampler_location(), 0)); | |
| 2122 | 2076 |
| 2123 if (flip_vertically) { | 2077 if (flip_vertically) { |
| 2124 GLC(Context(), Context()->uniform4f( | 2078 GLC(gl_, |
| 2125 program->vertex_shader().tex_transform_location(), | 2079 gl_->Uniform4f(program->vertex_shader().tex_transform_location(), |
| 2126 0.f, | 2080 0.f, |
| 2127 1.f, | 2081 1.f, |
| 2128 1.f, | 2082 1.f, |
| 2129 -1.f)); | 2083 -1.f)); |
| 2130 } else { | 2084 } else { |
| 2131 GLC(Context(), Context()->uniform4f( | 2085 GLC(gl_, |
| 2132 program->vertex_shader().tex_transform_location(), | 2086 gl_->Uniform4f(program->vertex_shader().tex_transform_location(), |
| 2133 0.f, | 2087 0.f, |
| 2134 0.f, | 2088 0.f, |
| 2135 1.f, | 2089 1.f, |
| 2136 1.f)); | 2090 1.f)); |
| 2137 } | 2091 } |
| 2138 | 2092 |
| 2139 SetShaderOpacity(1.f, program->fragment_shader().alpha_location()); | 2093 SetShaderOpacity(1.f, program->fragment_shader().alpha_location()); |
| 2140 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(Context())); | 2094 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(Context())); |
| 2141 GLC(Context(), Context()->bindTexture(GL_TEXTURE_2D, texture_id)); | 2095 GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, texture_id)); |
| 2142 DrawQuadGeometry( | 2096 DrawQuadGeometry( |
| 2143 frame, draw_matrix, rect, program->vertex_shader().matrix_location()); | 2097 frame, draw_matrix, rect, program->vertex_shader().matrix_location()); |
| 2144 } | 2098 } |
| 2145 | 2099 |
| 2146 void GLRenderer::Finish() { | 2100 void GLRenderer::Finish() { |
| 2147 TRACE_EVENT0("cc", "GLRenderer::Finish"); | 2101 TRACE_EVENT0("cc", "GLRenderer::Finish"); |
| 2148 GLC(context_, context_->finish()); | 2102 GLC(gl_, gl_->Finish()); |
| 2149 } | 2103 } |
| 2150 | 2104 |
| 2151 void GLRenderer::SwapBuffers(const CompositorFrameMetadata& metadata) { | 2105 void GLRenderer::SwapBuffers(const CompositorFrameMetadata& metadata) { |
| 2152 DCHECK(!is_backbuffer_discarded_); | 2106 DCHECK(!is_backbuffer_discarded_); |
| 2153 | 2107 |
| 2154 TRACE_EVENT0("cc", "GLRenderer::SwapBuffers"); | 2108 TRACE_EVENT0("cc", "GLRenderer::SwapBuffers"); |
| 2155 // We're done! Time to swapbuffers! | 2109 // We're done! Time to swapbuffers! |
| 2156 | 2110 |
| 2157 gfx::Size surface_size = output_surface_->SurfaceSize(); | 2111 gfx::Size surface_size = output_surface_->SurfaceSize(); |
| 2158 | 2112 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2188 last_swap_fence_ = resource_provider_->GetReadLockFence(); | 2142 last_swap_fence_ = resource_provider_->GetReadLockFence(); |
| 2189 resource_provider_->SetReadLockFence(new SimpleSwapFence()); | 2143 resource_provider_->SetReadLockFence(new SimpleSwapFence()); |
| 2190 } | 2144 } |
| 2191 | 2145 |
| 2192 void GLRenderer::EnforceMemoryPolicy() { | 2146 void GLRenderer::EnforceMemoryPolicy() { |
| 2193 if (!visible_) { | 2147 if (!visible_) { |
| 2194 TRACE_EVENT0("cc", "GLRenderer::EnforceMemoryPolicy dropping resources"); | 2148 TRACE_EVENT0("cc", "GLRenderer::EnforceMemoryPolicy dropping resources"); |
| 2195 ReleaseRenderPassTextures(); | 2149 ReleaseRenderPassTextures(); |
| 2196 DiscardBackbuffer(); | 2150 DiscardBackbuffer(); |
| 2197 resource_provider_->ReleaseCachedData(); | 2151 resource_provider_->ReleaseCachedData(); |
| 2198 GLC(context_, context_->flush()); | 2152 GLC(gl_, gl_->Flush()); |
| 2199 } | 2153 } |
| 2200 } | 2154 } |
| 2201 | 2155 |
| 2202 void GLRenderer::DiscardBackbuffer() { | 2156 void GLRenderer::DiscardBackbuffer() { |
| 2203 if (is_backbuffer_discarded_) | 2157 if (is_backbuffer_discarded_) |
| 2204 return; | 2158 return; |
| 2205 | 2159 |
| 2206 output_surface_->DiscardBackbuffer(); | 2160 output_surface_->DiscardBackbuffer(); |
| 2207 | 2161 |
| 2208 is_backbuffer_discarded_ = true; | 2162 is_backbuffer_discarded_ = true; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2231 pending_read.Pass()); | 2185 pending_read.Pass()); |
| 2232 | 2186 |
| 2233 // This is a syncronous call since the callback is null. | 2187 // This is a syncronous call since the callback is null. |
| 2234 gfx::Rect window_rect = MoveFromDrawToWindowSpace(rect); | 2188 gfx::Rect window_rect = MoveFromDrawToWindowSpace(rect); |
| 2235 DoGetFramebufferPixels(static_cast<uint8*>(pixels), | 2189 DoGetFramebufferPixels(static_cast<uint8*>(pixels), |
| 2236 window_rect, | 2190 window_rect, |
| 2237 AsyncGetFramebufferPixelsCleanupCallback()); | 2191 AsyncGetFramebufferPixelsCleanupCallback()); |
| 2238 } | 2192 } |
| 2239 | 2193 |
| 2240 void GLRenderer::GetFramebufferPixelsAsync( | 2194 void GLRenderer::GetFramebufferPixelsAsync( |
| 2241 gfx::Rect rect, scoped_ptr<CopyOutputRequest> request) { | 2195 gfx::Rect rect, |
| 2196 scoped_ptr<CopyOutputRequest> request) { |
| 2242 DCHECK(!request->IsEmpty()); | 2197 DCHECK(!request->IsEmpty()); |
| 2243 if (request->IsEmpty()) | 2198 if (request->IsEmpty()) |
| 2244 return; | 2199 return; |
| 2245 if (rect.IsEmpty()) | 2200 if (rect.IsEmpty()) |
| 2246 return; | 2201 return; |
| 2247 | 2202 |
| 2248 gfx::Rect window_rect = MoveFromDrawToWindowSpace(rect); | 2203 gfx::Rect window_rect = MoveFromDrawToWindowSpace(rect); |
| 2249 | 2204 |
| 2250 if (!request->force_bitmap_result()) { | 2205 if (!request->force_bitmap_result()) { |
| 2251 bool own_mailbox = !request->has_texture_mailbox(); | 2206 bool own_mailbox = !request->has_texture_mailbox(); |
| 2252 | 2207 |
| 2253 unsigned int texture_id = context_->createTexture(); | 2208 GLuint texture_id = 0; |
| 2209 gl_->GenTextures(1, &texture_id); |
| 2254 | 2210 |
| 2255 gpu::Mailbox mailbox; | 2211 gpu::Mailbox mailbox; |
| 2256 if (own_mailbox) { | 2212 if (own_mailbox) { |
| 2257 GLC(context_, context_->genMailboxCHROMIUM(mailbox.name)); | 2213 GLC(gl_, gl_->GenMailboxCHROMIUM(mailbox.name)); |
| 2258 if (mailbox.IsZero()) { | 2214 if (mailbox.IsZero()) { |
| 2259 context_->deleteTexture(texture_id); | 2215 gl_->DeleteTextures(1, &texture_id); |
| 2260 request->SendEmptyResult(); | 2216 request->SendEmptyResult(); |
| 2261 return; | 2217 return; |
| 2262 } | 2218 } |
| 2263 } else { | 2219 } else { |
| 2264 mailbox = request->texture_mailbox().name(); | 2220 mailbox = request->texture_mailbox().name(); |
| 2265 DCHECK_EQ(static_cast<unsigned>(GL_TEXTURE_2D), | 2221 DCHECK_EQ(static_cast<unsigned>(GL_TEXTURE_2D), |
| 2266 request->texture_mailbox().target()); | 2222 request->texture_mailbox().target()); |
| 2267 DCHECK(!mailbox.IsZero()); | 2223 DCHECK(!mailbox.IsZero()); |
| 2268 unsigned incoming_sync_point = request->texture_mailbox().sync_point(); | 2224 unsigned incoming_sync_point = request->texture_mailbox().sync_point(); |
| 2269 if (incoming_sync_point) | 2225 if (incoming_sync_point) |
| 2270 GLC(context_, context_->waitSyncPoint(incoming_sync_point)); | 2226 GLC(gl_, gl_->WaitSyncPointCHROMIUM(incoming_sync_point)); |
| 2271 } | 2227 } |
| 2272 | 2228 |
| 2273 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, texture_id)); | 2229 GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, texture_id)); |
| 2274 if (own_mailbox) { | 2230 if (own_mailbox) { |
| 2275 GLC(context_, | 2231 GLC(gl_, |
| 2276 context_->texParameteri( | 2232 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); |
| 2277 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); | 2233 GLC(gl_, |
| 2278 GLC(context_, | 2234 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); |
| 2279 context_->texParameteri( | 2235 GLC(gl_, |
| 2280 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); | 2236 gl_->TexParameteri( |
| 2281 GLC(context_, | |
| 2282 context_->texParameteri( | |
| 2283 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); | 2237 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); |
| 2284 GLC(context_, | 2238 GLC(gl_, |
| 2285 context_->texParameteri( | 2239 gl_->TexParameteri( |
| 2286 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); | 2240 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); |
| 2287 GLC(context_, | 2241 GLC(gl_, gl_->ProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name)); |
| 2288 context_->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name)); | |
| 2289 } else { | 2242 } else { |
| 2290 GLC(context_, | 2243 GLC(gl_, gl_->ConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name)); |
| 2291 context_->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name)); | |
| 2292 } | 2244 } |
| 2293 GetFramebufferTexture(texture_id, RGBA_8888, window_rect); | 2245 GetFramebufferTexture(texture_id, RGBA_8888, window_rect); |
| 2294 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, 0)); | 2246 GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, 0)); |
| 2295 | 2247 |
| 2296 unsigned sync_point = context_->insertSyncPoint(); | 2248 unsigned sync_point = gl_->InsertSyncPointCHROMIUM(); |
| 2297 TextureMailbox texture_mailbox(mailbox, GL_TEXTURE_2D, sync_point); | 2249 TextureMailbox texture_mailbox(mailbox, GL_TEXTURE_2D, sync_point); |
| 2298 | 2250 |
| 2299 scoped_ptr<SingleReleaseCallback> release_callback; | 2251 scoped_ptr<SingleReleaseCallback> release_callback; |
| 2300 if (own_mailbox) { | 2252 if (own_mailbox) { |
| 2301 release_callback = texture_mailbox_deleter_->GetReleaseCallback( | 2253 release_callback = texture_mailbox_deleter_->GetReleaseCallback( |
| 2302 output_surface_->context_provider(), texture_id); | 2254 output_surface_->context_provider(), texture_id); |
| 2303 } else { | 2255 } else { |
| 2304 context_->deleteTexture(texture_id); | 2256 gl_->DeleteTextures(1, &texture_id); |
| 2305 } | 2257 } |
| 2306 | 2258 |
| 2307 request->SendTextureResult(window_rect.size(), | 2259 request->SendTextureResult( |
| 2308 texture_mailbox, | 2260 window_rect.size(), texture_mailbox, release_callback.Pass()); |
| 2309 release_callback.Pass()); | |
| 2310 return; | 2261 return; |
| 2311 } | 2262 } |
| 2312 | 2263 |
| 2313 DCHECK(request->force_bitmap_result()); | 2264 DCHECK(request->force_bitmap_result()); |
| 2314 | 2265 |
| 2315 scoped_ptr<SkBitmap> bitmap(new SkBitmap); | 2266 scoped_ptr<SkBitmap> bitmap(new SkBitmap); |
| 2316 bitmap->setConfig(SkBitmap::kARGB_8888_Config, | 2267 bitmap->setConfig( |
| 2317 window_rect.width(), | 2268 SkBitmap::kARGB_8888_Config, window_rect.width(), window_rect.height()); |
| 2318 window_rect.height()); | |
| 2319 bitmap->allocPixels(); | 2269 bitmap->allocPixels(); |
| 2320 | 2270 |
| 2321 scoped_ptr<SkAutoLockPixels> lock(new SkAutoLockPixels(*bitmap)); | 2271 scoped_ptr<SkAutoLockPixels> lock(new SkAutoLockPixels(*bitmap)); |
| 2322 | 2272 |
| 2323 // Save a pointer to the pixels, the bitmap is owned by the cleanup_callback. | 2273 // Save a pointer to the pixels, the bitmap is owned by the cleanup_callback. |
| 2324 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); | 2274 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); |
| 2325 | 2275 |
| 2326 AsyncGetFramebufferPixelsCleanupCallback cleanup_callback = base::Bind( | 2276 AsyncGetFramebufferPixelsCleanupCallback cleanup_callback = |
| 2327 &GLRenderer::PassOnSkBitmap, | 2277 base::Bind(&GLRenderer::PassOnSkBitmap, |
| 2328 base::Unretained(this), | 2278 base::Unretained(this), |
| 2329 base::Passed(&bitmap), | 2279 base::Passed(&bitmap), |
| 2330 base::Passed(&lock)); | 2280 base::Passed(&lock)); |
| 2331 | 2281 |
| 2332 scoped_ptr<PendingAsyncReadPixels> pending_read(new PendingAsyncReadPixels); | 2282 scoped_ptr<PendingAsyncReadPixels> pending_read(new PendingAsyncReadPixels); |
| 2333 pending_read->copy_request = request.Pass(); | 2283 pending_read->copy_request = request.Pass(); |
| 2334 pending_async_read_pixels_.insert(pending_async_read_pixels_.begin(), | 2284 pending_async_read_pixels_.insert(pending_async_read_pixels_.begin(), |
| 2335 pending_read.Pass()); | 2285 pending_read.Pass()); |
| 2336 | 2286 |
| 2337 // This is an asyncronous call since the callback is not null. | 2287 // This is an asyncronous call since the callback is not null. |
| 2338 DoGetFramebufferPixels(pixels, window_rect, cleanup_callback); | 2288 DoGetFramebufferPixels(pixels, window_rect, cleanup_callback); |
| 2339 } | 2289 } |
| 2340 | 2290 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2354 unsigned temporary_texture = 0; | 2304 unsigned temporary_texture = 0; |
| 2355 unsigned temporary_fbo = 0; | 2305 unsigned temporary_fbo = 0; |
| 2356 | 2306 |
| 2357 if (do_workaround) { | 2307 if (do_workaround) { |
| 2358 // On Mac OS X, calling glReadPixels() against an FBO whose color attachment | 2308 // On Mac OS X, calling glReadPixels() against an FBO whose color attachment |
| 2359 // is an IOSurface-backed texture causes corruption of future glReadPixels() | 2309 // is an IOSurface-backed texture causes corruption of future glReadPixels() |
| 2360 // calls, even those on different OpenGL contexts. It is believed that this | 2310 // calls, even those on different OpenGL contexts. It is believed that this |
| 2361 // is the root cause of top crasher | 2311 // is the root cause of top crasher |
| 2362 // http://crbug.com/99393. <rdar://problem/10949687> | 2312 // http://crbug.com/99393. <rdar://problem/10949687> |
| 2363 | 2313 |
| 2364 temporary_texture = context_->createTexture(); | 2314 gl_->GenTextures(1, &temporary_texture); |
| 2365 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, temporary_texture)); | 2315 GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, temporary_texture)); |
| 2366 GLC(context_, context_->texParameteri( | 2316 GLC(gl_, |
| 2367 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); | 2317 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); |
| 2368 GLC(context_, context_->texParameteri( | 2318 GLC(gl_, |
| 2369 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); | 2319 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); |
| 2370 GLC(context_, context_->texParameteri( | 2320 GLC(gl_, |
| 2371 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); | 2321 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); |
| 2372 GLC(context_, context_->texParameteri( | 2322 GLC(gl_, |
| 2373 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); | 2323 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); |
| 2374 // Copy the contents of the current (IOSurface-backed) framebuffer into a | 2324 // Copy the contents of the current (IOSurface-backed) framebuffer into a |
| 2375 // temporary texture. | 2325 // temporary texture. |
| 2376 GetFramebufferTexture(temporary_texture, | 2326 GetFramebufferTexture( |
| 2377 RGBA_8888, | 2327 temporary_texture, RGBA_8888, gfx::Rect(current_surface_size_)); |
| 2378 gfx::Rect(current_surface_size_)); | 2328 gl_->GenFramebuffers(1, &temporary_fbo); |
| 2379 temporary_fbo = context_->createFramebuffer(); | |
| 2380 // Attach this texture to an FBO, and perform the readback from that FBO. | 2329 // Attach this texture to an FBO, and perform the readback from that FBO. |
| 2381 GLC(context_, context_->bindFramebuffer(GL_FRAMEBUFFER, temporary_fbo)); | 2330 GLC(gl_, gl_->BindFramebuffer(GL_FRAMEBUFFER, temporary_fbo)); |
| 2382 GLC(context_, context_->framebufferTexture2D(GL_FRAMEBUFFER, | 2331 GLC(gl_, |
| 2383 GL_COLOR_ATTACHMENT0, | 2332 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, |
| 2384 GL_TEXTURE_2D, | 2333 GL_COLOR_ATTACHMENT0, |
| 2385 temporary_texture, | 2334 GL_TEXTURE_2D, |
| 2386 0)); | 2335 temporary_texture, |
| 2336 0)); |
| 2387 | 2337 |
| 2388 DCHECK_EQ(static_cast<unsigned>(GL_FRAMEBUFFER_COMPLETE), | 2338 DCHECK_EQ(static_cast<unsigned>(GL_FRAMEBUFFER_COMPLETE), |
| 2389 context_->checkFramebufferStatus(GL_FRAMEBUFFER)); | 2339 gl_->CheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 2390 } | 2340 } |
| 2391 | 2341 |
| 2392 unsigned buffer = context_->createBuffer(); | 2342 GLuint buffer = 0; |
| 2393 GLC(context_, context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | 2343 gl_->GenBuffers(1, &buffer); |
| 2394 buffer)); | 2344 GLC(gl_, gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, buffer)); |
| 2395 GLC(context_, context_->bufferData(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | 2345 GLC(gl_, |
| 2396 4 * window_rect.size().GetArea(), | 2346 gl_->BufferData(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, |
| 2397 NULL, | 2347 4 * window_rect.size().GetArea(), |
| 2398 GL_STREAM_READ)); | 2348 NULL, |
| 2349 GL_STREAM_READ)); |
| 2399 | 2350 |
| 2400 blink::WebGLId query = 0; | 2351 GLuint query = 0; |
| 2401 if (is_async) { | 2352 if (is_async) { |
| 2402 query = context_->createQueryEXT(); | 2353 gl_->GenQueriesEXT(1, &query); |
| 2403 GLC(context_, context_->beginQueryEXT( | 2354 GLC(gl_, gl_->BeginQueryEXT(GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM, query)); |
| 2404 GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM, | |
| 2405 query)); | |
| 2406 } | 2355 } |
| 2407 | 2356 |
| 2408 GLC(context_, | 2357 GLC(gl_, |
| 2409 context_->readPixels(window_rect.x(), | 2358 gl_->ReadPixels(window_rect.x(), |
| 2410 window_rect.y(), | 2359 window_rect.y(), |
| 2411 window_rect.width(), | 2360 window_rect.width(), |
| 2412 window_rect.height(), | 2361 window_rect.height(), |
| 2413 GL_RGBA, | 2362 GL_RGBA, |
| 2414 GL_UNSIGNED_BYTE, | 2363 GL_UNSIGNED_BYTE, |
| 2415 NULL)); | 2364 NULL)); |
| 2416 | 2365 |
| 2417 GLC(context_, context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | 2366 GLC(gl_, gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, 0)); |
| 2418 0)); | |
| 2419 | 2367 |
| 2420 if (do_workaround) { | 2368 if (do_workaround) { |
| 2421 // Clean up. | 2369 // Clean up. |
| 2422 GLC(context_, context_->bindFramebuffer(GL_FRAMEBUFFER, 0)); | 2370 GLC(gl_, gl_->BindFramebuffer(GL_FRAMEBUFFER, 0)); |
| 2423 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, 0)); | 2371 GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, 0)); |
| 2424 GLC(context_, context_->deleteFramebuffer(temporary_fbo)); | 2372 GLC(gl_, gl_->DeleteFramebuffers(1, &temporary_fbo)); |
| 2425 GLC(context_, context_->deleteTexture(temporary_texture)); | 2373 GLC(gl_, gl_->DeleteTextures(1, &temporary_texture)); |
| 2426 } | 2374 } |
| 2427 | 2375 |
| 2428 base::Closure finished_callback = | 2376 base::Closure finished_callback = base::Bind(&GLRenderer::FinishedReadback, |
| 2429 base::Bind(&GLRenderer::FinishedReadback, | 2377 base::Unretained(this), |
| 2430 base::Unretained(this), | 2378 cleanup_callback, |
| 2431 cleanup_callback, | 2379 buffer, |
| 2432 buffer, | 2380 query, |
| 2433 query, | 2381 dest_pixels, |
| 2434 dest_pixels, | 2382 window_rect.size()); |
| 2435 window_rect.size()); | |
| 2436 // Save the finished_callback so it can be cancelled. | 2383 // Save the finished_callback so it can be cancelled. |
| 2437 pending_async_read_pixels_.front()->finished_read_pixels_callback.Reset( | 2384 pending_async_read_pixels_.front()->finished_read_pixels_callback.Reset( |
| 2438 finished_callback); | 2385 finished_callback); |
| 2439 | 2386 |
| 2440 // Save the buffer to verify the callbacks happen in the expected order. | 2387 // Save the buffer to verify the callbacks happen in the expected order. |
| 2441 pending_async_read_pixels_.front()->buffer = buffer; | 2388 pending_async_read_pixels_.front()->buffer = buffer; |
| 2442 | 2389 |
| 2443 if (is_async) { | 2390 if (is_async) { |
| 2444 GLC(context_, context_->endQueryEXT( | 2391 GLC(gl_, gl_->EndQueryEXT(GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM)); |
| 2445 GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM)); | |
| 2446 context_support_->SignalQuery(query, finished_callback); | 2392 context_support_->SignalQuery(query, finished_callback); |
| 2447 } else { | 2393 } else { |
| 2448 resource_provider_->Finish(); | 2394 resource_provider_->Finish(); |
| 2449 finished_callback.Run(); | 2395 finished_callback.Run(); |
| 2450 } | 2396 } |
| 2451 | 2397 |
| 2452 EnforceMemoryPolicy(); | 2398 EnforceMemoryPolicy(); |
| 2453 } | 2399 } |
| 2454 | 2400 |
| 2455 void GLRenderer::FinishedReadback( | 2401 void GLRenderer::FinishedReadback( |
| 2456 const AsyncGetFramebufferPixelsCleanupCallback& cleanup_callback, | 2402 const AsyncGetFramebufferPixelsCleanupCallback& cleanup_callback, |
| 2457 unsigned source_buffer, | 2403 unsigned source_buffer, |
| 2458 unsigned query, | 2404 unsigned query, |
| 2459 uint8* dest_pixels, | 2405 uint8* dest_pixels, |
| 2460 gfx::Size size) { | 2406 gfx::Size size) { |
| 2461 DCHECK(!pending_async_read_pixels_.empty()); | 2407 DCHECK(!pending_async_read_pixels_.empty()); |
| 2462 | 2408 |
| 2463 if (query != 0) { | 2409 if (query != 0) { |
| 2464 GLC(context_, context_->deleteQueryEXT(query)); | 2410 GLC(gl_, gl_->DeleteQueriesEXT(1, &query)); |
| 2465 } | 2411 } |
| 2466 | 2412 |
| 2467 PendingAsyncReadPixels* current_read = pending_async_read_pixels_.back(); | 2413 PendingAsyncReadPixels* current_read = pending_async_read_pixels_.back(); |
| 2468 // Make sure we service the readbacks in order. | 2414 // Make sure we service the readbacks in order. |
| 2469 DCHECK_EQ(source_buffer, current_read->buffer); | 2415 DCHECK_EQ(source_buffer, current_read->buffer); |
| 2470 | 2416 |
| 2471 uint8* src_pixels = NULL; | 2417 uint8* src_pixels = NULL; |
| 2472 | 2418 |
| 2473 if (source_buffer != 0) { | 2419 if (source_buffer != 0) { |
| 2474 GLC(context_, context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | 2420 GLC(gl_, |
| 2475 source_buffer)); | 2421 gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, source_buffer)); |
| 2476 src_pixels = static_cast<uint8*>( | 2422 src_pixels = static_cast<uint8*>(gl_->MapBufferCHROMIUM( |
| 2477 context_->mapBufferCHROMIUM(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | 2423 GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, GL_READ_ONLY)); |
| 2478 GL_READ_ONLY)); | |
| 2479 | 2424 |
| 2480 if (src_pixels) { | 2425 if (src_pixels) { |
| 2481 size_t row_bytes = size.width() * 4; | 2426 size_t row_bytes = size.width() * 4; |
| 2482 int num_rows = size.height(); | 2427 int num_rows = size.height(); |
| 2483 size_t total_bytes = num_rows * row_bytes; | 2428 size_t total_bytes = num_rows * row_bytes; |
| 2484 for (size_t dest_y = 0; dest_y < total_bytes; dest_y += row_bytes) { | 2429 for (size_t dest_y = 0; dest_y < total_bytes; dest_y += row_bytes) { |
| 2485 // Flip Y axis. | 2430 // Flip Y axis. |
| 2486 size_t src_y = total_bytes - dest_y - row_bytes; | 2431 size_t src_y = total_bytes - dest_y - row_bytes; |
| 2487 // Swizzle OpenGL -> Skia byte order. | 2432 // Swizzle OpenGL -> Skia byte order. |
| 2488 for (size_t x = 0; x < row_bytes; x += 4) { | 2433 for (size_t x = 0; x < row_bytes; x += 4) { |
| 2489 dest_pixels[dest_y + x + SK_R32_SHIFT/8] = src_pixels[src_y + x + 0]; | 2434 dest_pixels[dest_y + x + SK_R32_SHIFT / 8] = |
| 2490 dest_pixels[dest_y + x + SK_G32_SHIFT/8] = src_pixels[src_y + x + 1]; | 2435 src_pixels[src_y + x + 0]; |
| 2491 dest_pixels[dest_y + x + SK_B32_SHIFT/8] = src_pixels[src_y + x + 2]; | 2436 dest_pixels[dest_y + x + SK_G32_SHIFT / 8] = |
| 2492 dest_pixels[dest_y + x + SK_A32_SHIFT/8] = src_pixels[src_y + x + 3]; | 2437 src_pixels[src_y + x + 1]; |
| 2438 dest_pixels[dest_y + x + SK_B32_SHIFT / 8] = |
| 2439 src_pixels[src_y + x + 2]; |
| 2440 dest_pixels[dest_y + x + SK_A32_SHIFT / 8] = |
| 2441 src_pixels[src_y + x + 3]; |
| 2493 } | 2442 } |
| 2494 } | 2443 } |
| 2495 | 2444 |
| 2496 GLC(context_, context_->unmapBufferCHROMIUM( | 2445 GLC(gl_, |
| 2497 GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM)); | 2446 gl_->UnmapBufferCHROMIUM(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM)); |
| 2498 } | 2447 } |
| 2499 GLC(context_, context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | 2448 GLC(gl_, gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, 0)); |
| 2500 0)); | 2449 GLC(gl_, gl_->DeleteBuffers(1, &source_buffer)); |
| 2501 GLC(context_, context_->deleteBuffer(source_buffer)); | |
| 2502 } | 2450 } |
| 2503 | 2451 |
| 2504 // TODO(danakj): This can go away when synchronous readback is no more and its | 2452 // TODO(danakj): This can go away when synchronous readback is no more and its |
| 2505 // contents can just move here. | 2453 // contents can just move here. |
| 2506 if (!cleanup_callback.is_null()) | 2454 if (!cleanup_callback.is_null()) |
| 2507 cleanup_callback.Run(current_read->copy_request.Pass(), src_pixels != NULL); | 2455 cleanup_callback.Run(current_read->copy_request.Pass(), src_pixels != NULL); |
| 2508 | 2456 |
| 2509 pending_async_read_pixels_.pop_back(); | 2457 pending_async_read_pixels_.pop_back(); |
| 2510 } | 2458 } |
| 2511 | 2459 |
| 2512 void GLRenderer::PassOnSkBitmap( | 2460 void GLRenderer::PassOnSkBitmap(scoped_ptr<SkBitmap> bitmap, |
| 2513 scoped_ptr<SkBitmap> bitmap, | 2461 scoped_ptr<SkAutoLockPixels> lock, |
| 2514 scoped_ptr<SkAutoLockPixels> lock, | 2462 scoped_ptr<CopyOutputRequest> request, |
| 2515 scoped_ptr<CopyOutputRequest> request, | 2463 bool success) { |
| 2516 bool success) { | |
| 2517 DCHECK(request->force_bitmap_result()); | 2464 DCHECK(request->force_bitmap_result()); |
| 2518 | 2465 |
| 2519 lock.reset(); | 2466 lock.reset(); |
| 2520 if (success) | 2467 if (success) |
| 2521 request->SendBitmapResult(bitmap.Pass()); | 2468 request->SendBitmapResult(bitmap.Pass()); |
| 2522 } | 2469 } |
| 2523 | 2470 |
| 2524 void GLRenderer::GetFramebufferTexture( | 2471 void GLRenderer::GetFramebufferTexture(unsigned texture_id, |
| 2525 unsigned texture_id, ResourceFormat texture_format, gfx::Rect window_rect) { | 2472 ResourceFormat texture_format, |
| 2473 gfx::Rect window_rect) { |
| 2526 DCHECK(texture_id); | 2474 DCHECK(texture_id); |
| 2527 DCHECK_GE(window_rect.x(), 0); | 2475 DCHECK_GE(window_rect.x(), 0); |
| 2528 DCHECK_GE(window_rect.y(), 0); | 2476 DCHECK_GE(window_rect.y(), 0); |
| 2529 DCHECK_LE(window_rect.right(), current_surface_size_.width()); | 2477 DCHECK_LE(window_rect.right(), current_surface_size_.width()); |
| 2530 DCHECK_LE(window_rect.bottom(), current_surface_size_.height()); | 2478 DCHECK_LE(window_rect.bottom(), current_surface_size_.height()); |
| 2531 | 2479 |
| 2532 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, texture_id)); | 2480 GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, texture_id)); |
| 2533 GLC(context_, | 2481 GLC(gl_, |
| 2534 context_->copyTexImage2D( | 2482 gl_->CopyTexImage2D(GL_TEXTURE_2D, |
| 2535 GL_TEXTURE_2D, | 2483 0, |
| 2536 0, | 2484 GLDataFormat(texture_format), |
| 2537 GLDataFormat(texture_format), | 2485 window_rect.x(), |
| 2538 window_rect.x(), | 2486 window_rect.y(), |
| 2539 window_rect.y(), | 2487 window_rect.width(), |
| 2540 window_rect.width(), | 2488 window_rect.height(), |
| 2541 window_rect.height(), | 2489 0)); |
| 2542 0)); | 2490 GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, 0)); |
| 2543 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, 0)); | |
| 2544 } | 2491 } |
| 2545 | 2492 |
| 2546 bool GLRenderer::UseScopedTexture(DrawingFrame* frame, | 2493 bool GLRenderer::UseScopedTexture(DrawingFrame* frame, |
| 2547 const ScopedResource* texture, | 2494 const ScopedResource* texture, |
| 2548 gfx::Rect viewport_rect) { | 2495 gfx::Rect viewport_rect) { |
| 2549 DCHECK(texture->id()); | 2496 DCHECK(texture->id()); |
| 2550 frame->current_render_pass = NULL; | 2497 frame->current_render_pass = NULL; |
| 2551 frame->current_texture = texture; | 2498 frame->current_texture = texture; |
| 2552 | 2499 |
| 2553 return BindFramebufferToTexture(frame, texture, viewport_rect); | 2500 return BindFramebufferToTexture(frame, texture, viewport_rect); |
| 2554 } | 2501 } |
| 2555 | 2502 |
| 2556 void GLRenderer::BindFramebufferToOutputSurface(DrawingFrame* frame) { | 2503 void GLRenderer::BindFramebufferToOutputSurface(DrawingFrame* frame) { |
| 2557 current_framebuffer_lock_.reset(); | 2504 current_framebuffer_lock_.reset(); |
| 2558 output_surface_->BindFramebuffer(); | 2505 output_surface_->BindFramebuffer(); |
| 2559 | 2506 |
| 2560 if (output_surface_->HasExternalStencilTest()) { | 2507 if (output_surface_->HasExternalStencilTest()) { |
| 2561 SetStencilEnabled(true); | 2508 SetStencilEnabled(true); |
| 2562 GLC(context_, context_->stencilFunc(GL_EQUAL, 1, 1)); | 2509 GLC(gl_, gl_->StencilFunc(GL_EQUAL, 1, 1)); |
| 2563 } else { | 2510 } else { |
| 2564 SetStencilEnabled(false); | 2511 SetStencilEnabled(false); |
| 2565 } | 2512 } |
| 2566 } | 2513 } |
| 2567 | 2514 |
| 2568 bool GLRenderer::BindFramebufferToTexture(DrawingFrame* frame, | 2515 bool GLRenderer::BindFramebufferToTexture(DrawingFrame* frame, |
| 2569 const ScopedResource* texture, | 2516 const ScopedResource* texture, |
| 2570 gfx::Rect target_rect) { | 2517 gfx::Rect target_rect) { |
| 2571 DCHECK(texture->id()); | 2518 DCHECK(texture->id()); |
| 2572 | 2519 |
| 2573 current_framebuffer_lock_.reset(); | 2520 current_framebuffer_lock_.reset(); |
| 2574 | 2521 |
| 2575 SetStencilEnabled(false); | 2522 SetStencilEnabled(false); |
| 2576 GLC(context_, | 2523 GLC(gl_, gl_->BindFramebuffer(GL_FRAMEBUFFER, offscreen_framebuffer_id_)); |
| 2577 context_->bindFramebuffer(GL_FRAMEBUFFER, offscreen_framebuffer_id_)); | |
| 2578 current_framebuffer_lock_ = | 2524 current_framebuffer_lock_ = |
| 2579 make_scoped_ptr(new ResourceProvider::ScopedWriteLockGL( | 2525 make_scoped_ptr(new ResourceProvider::ScopedWriteLockGL( |
| 2580 resource_provider_, texture->id())); | 2526 resource_provider_, texture->id())); |
| 2581 unsigned texture_id = current_framebuffer_lock_->texture_id(); | 2527 unsigned texture_id = current_framebuffer_lock_->texture_id(); |
| 2582 GLC(context_, | 2528 GLC(gl_, |
| 2583 context_->framebufferTexture2D( | 2529 gl_->FramebufferTexture2D( |
| 2584 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture_id, 0)); | 2530 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture_id, 0)); |
| 2585 | 2531 |
| 2586 DCHECK(context_->checkFramebufferStatus(GL_FRAMEBUFFER) == | 2532 DCHECK(gl_->CheckFramebufferStatus(GL_FRAMEBUFFER) == |
| 2587 GL_FRAMEBUFFER_COMPLETE || IsContextLost()); | 2533 GL_FRAMEBUFFER_COMPLETE || |
| 2534 IsContextLost()); |
| 2588 | 2535 |
| 2589 InitializeViewport(frame, | 2536 InitializeViewport( |
| 2590 target_rect, | 2537 frame, target_rect, gfx::Rect(target_rect.size()), target_rect.size()); |
| 2591 gfx::Rect(target_rect.size()), | |
| 2592 target_rect.size()); | |
| 2593 return true; | 2538 return true; |
| 2594 } | 2539 } |
| 2595 | 2540 |
| 2596 void GLRenderer::SetScissorTestRect(gfx::Rect scissor_rect) { | 2541 void GLRenderer::SetScissorTestRect(gfx::Rect scissor_rect) { |
| 2597 EnsureScissorTestEnabled(); | 2542 EnsureScissorTestEnabled(); |
| 2598 | 2543 |
| 2599 // Don't unnecessarily ask the context to change the scissor, because it | 2544 // Don't unnecessarily ask the context to change the scissor, because it |
| 2600 // may cause undesired GPU pipeline flushes. | 2545 // may cause undesired GPU pipeline flushes. |
| 2601 if (scissor_rect == scissor_rect_ && !scissor_rect_needs_reset_) | 2546 if (scissor_rect == scissor_rect_ && !scissor_rect_needs_reset_) |
| 2602 return; | 2547 return; |
| 2603 | 2548 |
| 2604 scissor_rect_ = scissor_rect; | 2549 scissor_rect_ = scissor_rect; |
| 2605 FlushTextureQuadCache(); | 2550 FlushTextureQuadCache(); |
| 2606 GLC(context_, | 2551 GLC(gl_, |
| 2607 context_->scissor(scissor_rect.x(), | 2552 gl_->Scissor(scissor_rect.x(), |
| 2608 scissor_rect.y(), | 2553 scissor_rect.y(), |
| 2609 scissor_rect.width(), | 2554 scissor_rect.width(), |
| 2610 scissor_rect.height())); | 2555 scissor_rect.height())); |
| 2611 | 2556 |
| 2612 scissor_rect_needs_reset_ = false; | 2557 scissor_rect_needs_reset_ = false; |
| 2613 } | 2558 } |
| 2614 | 2559 |
| 2615 void GLRenderer::SetDrawViewport(gfx::Rect window_space_viewport) { | 2560 void GLRenderer::SetDrawViewport(gfx::Rect window_space_viewport) { |
| 2616 viewport_ = window_space_viewport; | 2561 viewport_ = window_space_viewport; |
| 2617 GLC(context_, context_->viewport(window_space_viewport.x(), | 2562 GLC(gl_, |
| 2618 window_space_viewport.y(), | 2563 gl_->Viewport(window_space_viewport.x(), |
| 2619 window_space_viewport.width(), | 2564 window_space_viewport.y(), |
| 2620 window_space_viewport.height())); | 2565 window_space_viewport.width(), |
| 2566 window_space_viewport.height())); |
| 2621 } | 2567 } |
| 2622 | 2568 |
| 2623 void GLRenderer::InitializeSharedObjects() { | 2569 void GLRenderer::InitializeSharedObjects() { |
| 2624 TRACE_EVENT0("cc", "GLRenderer::InitializeSharedObjects"); | 2570 TRACE_EVENT0("cc", "GLRenderer::InitializeSharedObjects"); |
| 2625 | 2571 |
| 2626 // Create an FBO for doing offscreen rendering. | 2572 // Create an FBO for doing offscreen rendering. |
| 2627 GLC(context_, offscreen_framebuffer_id_ = context_->createFramebuffer()); | 2573 GLC(gl_, gl_->GenFramebuffers(1, &offscreen_framebuffer_id_)); |
| 2628 | 2574 |
| 2629 shared_geometry_ = make_scoped_ptr( | 2575 shared_geometry_ = make_scoped_ptr( |
| 2630 new GeometryBinding(context_, QuadVertexRect())); | 2576 new GeometryBinding(context_, QuadVertexRect())); |
| 2631 } | 2577 } |
| 2632 | 2578 |
| 2633 const GLRenderer::TileCheckerboardProgram* | 2579 const GLRenderer::TileCheckerboardProgram* |
| 2634 GLRenderer::GetTileCheckerboardProgram() { | 2580 GLRenderer::GetTileCheckerboardProgram() { |
| 2635 if (!tile_checkerboard_program_.initialized()) { | 2581 if (!tile_checkerboard_program_.initialized()) { |
| 2636 TRACE_EVENT0("cc", "GLRenderer::checkerboardProgram::initalize"); | 2582 TRACE_EVENT0("cc", "GLRenderer::checkerboardProgram::initalize"); |
| 2637 tile_checkerboard_program_.Initialize( | 2583 tile_checkerboard_program_.Initialize(output_surface_->context_provider(), |
| 2638 output_surface_->context_provider(), | 2584 TexCoordPrecisionNA, |
| 2639 TexCoordPrecisionNA, | 2585 SamplerTypeNA); |
| 2640 SamplerTypeNA); | |
| 2641 } | 2586 } |
| 2642 return &tile_checkerboard_program_; | 2587 return &tile_checkerboard_program_; |
| 2643 } | 2588 } |
| 2644 | 2589 |
| 2645 const GLRenderer::DebugBorderProgram* GLRenderer::GetDebugBorderProgram() { | 2590 const GLRenderer::DebugBorderProgram* GLRenderer::GetDebugBorderProgram() { |
| 2646 if (!debug_border_program_.initialized()) { | 2591 if (!debug_border_program_.initialized()) { |
| 2647 TRACE_EVENT0("cc", "GLRenderer::debugBorderProgram::initialize"); | 2592 TRACE_EVENT0("cc", "GLRenderer::debugBorderProgram::initialize"); |
| 2648 debug_border_program_.Initialize( | 2593 debug_border_program_.Initialize(output_surface_->context_provider(), |
| 2649 output_surface_->context_provider(), | 2594 TexCoordPrecisionNA, |
| 2650 TexCoordPrecisionNA, | 2595 SamplerTypeNA); |
| 2651 SamplerTypeNA); | |
| 2652 } | 2596 } |
| 2653 return &debug_border_program_; | 2597 return &debug_border_program_; |
| 2654 } | 2598 } |
| 2655 | 2599 |
| 2656 const GLRenderer::SolidColorProgram* GLRenderer::GetSolidColorProgram() { | 2600 const GLRenderer::SolidColorProgram* GLRenderer::GetSolidColorProgram() { |
| 2657 if (!solid_color_program_.initialized()) { | 2601 if (!solid_color_program_.initialized()) { |
| 2658 TRACE_EVENT0("cc", "GLRenderer::solidColorProgram::initialize"); | 2602 TRACE_EVENT0("cc", "GLRenderer::solidColorProgram::initialize"); |
| 2659 solid_color_program_.Initialize( | 2603 solid_color_program_.Initialize(output_surface_->context_provider(), |
| 2660 output_surface_->context_provider(), | 2604 TexCoordPrecisionNA, |
| 2661 TexCoordPrecisionNA, | 2605 SamplerTypeNA); |
| 2662 SamplerTypeNA); | |
| 2663 } | 2606 } |
| 2664 return &solid_color_program_; | 2607 return &solid_color_program_; |
| 2665 } | 2608 } |
| 2666 | 2609 |
| 2667 const GLRenderer::SolidColorProgramAA* GLRenderer::GetSolidColorProgramAA() { | 2610 const GLRenderer::SolidColorProgramAA* GLRenderer::GetSolidColorProgramAA() { |
| 2668 if (!solid_color_program_aa_.initialized()) { | 2611 if (!solid_color_program_aa_.initialized()) { |
| 2669 TRACE_EVENT0("cc", "GLRenderer::solidColorProgramAA::initialize"); | 2612 TRACE_EVENT0("cc", "GLRenderer::solidColorProgramAA::initialize"); |
| 2670 solid_color_program_aa_.Initialize( | 2613 solid_color_program_aa_.Initialize(output_surface_->context_provider(), |
| 2671 output_surface_->context_provider(), | 2614 TexCoordPrecisionNA, |
| 2672 TexCoordPrecisionNA, | 2615 SamplerTypeNA); |
| 2673 SamplerTypeNA); | |
| 2674 } | 2616 } |
| 2675 return &solid_color_program_aa_; | 2617 return &solid_color_program_aa_; |
| 2676 } | 2618 } |
| 2677 | 2619 |
| 2678 const GLRenderer::RenderPassProgram* GLRenderer::GetRenderPassProgram( | 2620 const GLRenderer::RenderPassProgram* GLRenderer::GetRenderPassProgram( |
| 2679 TexCoordPrecision precision) { | 2621 TexCoordPrecision precision) { |
| 2680 DCHECK_GE(precision, 0); | 2622 DCHECK_GE(precision, 0); |
| 2681 DCHECK_LT(precision, NumTexCoordPrecisions); | 2623 DCHECK_LT(precision, NumTexCoordPrecisions); |
| 2682 RenderPassProgram* program = &render_pass_program_[precision]; | 2624 RenderPassProgram* program = &render_pass_program_[precision]; |
| 2683 if (!program->initialized()) { | 2625 if (!program->initialized()) { |
| 2684 TRACE_EVENT0("cc", "GLRenderer::renderPassProgram::initialize"); | 2626 TRACE_EVENT0("cc", "GLRenderer::renderPassProgram::initialize"); |
| 2685 program->Initialize( | 2627 program->Initialize( |
| 2686 output_surface_->context_provider(), precision, SamplerType2D); | 2628 output_surface_->context_provider(), precision, SamplerType2D); |
| 2687 } | 2629 } |
| 2688 return program; | 2630 return program; |
| 2689 } | 2631 } |
| 2690 | 2632 |
| 2691 const GLRenderer::RenderPassProgramAA* GLRenderer::GetRenderPassProgramAA( | 2633 const GLRenderer::RenderPassProgramAA* GLRenderer::GetRenderPassProgramAA( |
| 2692 TexCoordPrecision precision) { | 2634 TexCoordPrecision precision) { |
| 2693 DCHECK_GE(precision, 0); | 2635 DCHECK_GE(precision, 0); |
| 2694 DCHECK_LT(precision, NumTexCoordPrecisions); | 2636 DCHECK_LT(precision, NumTexCoordPrecisions); |
| 2695 RenderPassProgramAA* program = &render_pass_program_aa_[precision]; | 2637 RenderPassProgramAA* program = &render_pass_program_aa_[precision]; |
| 2696 if (!program->initialized()) { | 2638 if (!program->initialized()) { |
| 2697 TRACE_EVENT0("cc", "GLRenderer::renderPassProgramAA::initialize"); | 2639 TRACE_EVENT0("cc", "GLRenderer::renderPassProgramAA::initialize"); |
| 2698 program->Initialize( | 2640 program->Initialize( |
| 2699 output_surface_->context_provider(), precision, SamplerType2D); | 2641 output_surface_->context_provider(), precision, SamplerType2D); |
| 2700 } | 2642 } |
| 2701 return program; | 2643 return program; |
| 2702 } | 2644 } |
| 2703 | 2645 |
| 2704 const GLRenderer::RenderPassMaskProgram* | 2646 const GLRenderer::RenderPassMaskProgram* GLRenderer::GetRenderPassMaskProgram( |
| 2705 GLRenderer::GetRenderPassMaskProgram(TexCoordPrecision precision) { | 2647 TexCoordPrecision precision) { |
| 2706 DCHECK_GE(precision, 0); | 2648 DCHECK_GE(precision, 0); |
| 2707 DCHECK_LT(precision, NumTexCoordPrecisions); | 2649 DCHECK_LT(precision, NumTexCoordPrecisions); |
| 2708 RenderPassMaskProgram* program = &render_pass_mask_program_[precision]; | 2650 RenderPassMaskProgram* program = &render_pass_mask_program_[precision]; |
| 2709 if (!program->initialized()) { | 2651 if (!program->initialized()) { |
| 2710 TRACE_EVENT0("cc", "GLRenderer::renderPassMaskProgram::initialize"); | 2652 TRACE_EVENT0("cc", "GLRenderer::renderPassMaskProgram::initialize"); |
| 2711 program->Initialize( | 2653 program->Initialize( |
| 2712 output_surface_->context_provider(), precision, SamplerType2D); | 2654 output_surface_->context_provider(), precision, SamplerType2D); |
| 2713 } | 2655 } |
| 2714 return program; | 2656 return program; |
| 2715 } | 2657 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2780 if (!program->initialized()) { | 2722 if (!program->initialized()) { |
| 2781 TRACE_EVENT0("cc", | 2723 TRACE_EVENT0("cc", |
| 2782 "GLRenderer::renderPassMaskColorMatrixProgramAA::initialize"); | 2724 "GLRenderer::renderPassMaskColorMatrixProgramAA::initialize"); |
| 2783 program->Initialize( | 2725 program->Initialize( |
| 2784 output_surface_->context_provider(), precision, SamplerType2D); | 2726 output_surface_->context_provider(), precision, SamplerType2D); |
| 2785 } | 2727 } |
| 2786 return program; | 2728 return program; |
| 2787 } | 2729 } |
| 2788 | 2730 |
| 2789 const GLRenderer::TileProgram* GLRenderer::GetTileProgram( | 2731 const GLRenderer::TileProgram* GLRenderer::GetTileProgram( |
| 2790 TexCoordPrecision precision, SamplerType sampler) { | 2732 TexCoordPrecision precision, |
| 2733 SamplerType sampler) { |
| 2791 DCHECK_GE(precision, 0); | 2734 DCHECK_GE(precision, 0); |
| 2792 DCHECK_LT(precision, NumTexCoordPrecisions); | 2735 DCHECK_LT(precision, NumTexCoordPrecisions); |
| 2793 DCHECK_GE(sampler, 0); | 2736 DCHECK_GE(sampler, 0); |
| 2794 DCHECK_LT(sampler, NumSamplerTypes); | 2737 DCHECK_LT(sampler, NumSamplerTypes); |
| 2795 TileProgram* program = &tile_program_[precision][sampler]; | 2738 TileProgram* program = &tile_program_[precision][sampler]; |
| 2796 if (!program->initialized()) { | 2739 if (!program->initialized()) { |
| 2797 TRACE_EVENT0("cc", "GLRenderer::tileProgram::initialize"); | 2740 TRACE_EVENT0("cc", "GLRenderer::tileProgram::initialize"); |
| 2798 program->Initialize( | 2741 program->Initialize( |
| 2799 output_surface_->context_provider(), precision, sampler); | 2742 output_surface_->context_provider(), precision, sampler); |
| 2800 } | 2743 } |
| 2801 return program; | 2744 return program; |
| 2802 } | 2745 } |
| 2803 | 2746 |
| 2804 const GLRenderer::TileProgramOpaque* GLRenderer::GetTileProgramOpaque( | 2747 const GLRenderer::TileProgramOpaque* GLRenderer::GetTileProgramOpaque( |
| 2805 TexCoordPrecision precision, SamplerType sampler) { | 2748 TexCoordPrecision precision, |
| 2749 SamplerType sampler) { |
| 2806 DCHECK_GE(precision, 0); | 2750 DCHECK_GE(precision, 0); |
| 2807 DCHECK_LT(precision, NumTexCoordPrecisions); | 2751 DCHECK_LT(precision, NumTexCoordPrecisions); |
| 2808 DCHECK_GE(sampler, 0); | 2752 DCHECK_GE(sampler, 0); |
| 2809 DCHECK_LT(sampler, NumSamplerTypes); | 2753 DCHECK_LT(sampler, NumSamplerTypes); |
| 2810 TileProgramOpaque* program = &tile_program_opaque_[precision][sampler]; | 2754 TileProgramOpaque* program = &tile_program_opaque_[precision][sampler]; |
| 2811 if (!program->initialized()) { | 2755 if (!program->initialized()) { |
| 2812 TRACE_EVENT0("cc", "GLRenderer::tileProgramOpaque::initialize"); | 2756 TRACE_EVENT0("cc", "GLRenderer::tileProgramOpaque::initialize"); |
| 2813 program->Initialize( | 2757 program->Initialize( |
| 2814 output_surface_->context_provider(), precision, sampler); | 2758 output_surface_->context_provider(), precision, sampler); |
| 2815 } | 2759 } |
| 2816 return program; | 2760 return program; |
| 2817 } | 2761 } |
| 2818 | 2762 |
| 2819 const GLRenderer::TileProgramAA* GLRenderer::GetTileProgramAA( | 2763 const GLRenderer::TileProgramAA* GLRenderer::GetTileProgramAA( |
| 2820 TexCoordPrecision precision, SamplerType sampler) { | 2764 TexCoordPrecision precision, |
| 2765 SamplerType sampler) { |
| 2821 DCHECK_GE(precision, 0); | 2766 DCHECK_GE(precision, 0); |
| 2822 DCHECK_LT(precision, NumTexCoordPrecisions); | 2767 DCHECK_LT(precision, NumTexCoordPrecisions); |
| 2823 DCHECK_GE(sampler, 0); | 2768 DCHECK_GE(sampler, 0); |
| 2824 DCHECK_LT(sampler, NumSamplerTypes); | 2769 DCHECK_LT(sampler, NumSamplerTypes); |
| 2825 TileProgramAA* program = &tile_program_aa_[precision][sampler]; | 2770 TileProgramAA* program = &tile_program_aa_[precision][sampler]; |
| 2826 if (!program->initialized()) { | 2771 if (!program->initialized()) { |
| 2827 TRACE_EVENT0("cc", "GLRenderer::tileProgramAA::initialize"); | 2772 TRACE_EVENT0("cc", "GLRenderer::tileProgramAA::initialize"); |
| 2828 program->Initialize( | 2773 program->Initialize( |
| 2829 output_surface_->context_provider(), precision, sampler); | 2774 output_surface_->context_provider(), precision, sampler); |
| 2830 } | 2775 } |
| 2831 return program; | 2776 return program; |
| 2832 } | 2777 } |
| 2833 | 2778 |
| 2834 const GLRenderer::TileProgramSwizzle* GLRenderer::GetTileProgramSwizzle( | 2779 const GLRenderer::TileProgramSwizzle* GLRenderer::GetTileProgramSwizzle( |
| 2835 TexCoordPrecision precision, SamplerType sampler) { | 2780 TexCoordPrecision precision, |
| 2781 SamplerType sampler) { |
| 2836 DCHECK_GE(precision, 0); | 2782 DCHECK_GE(precision, 0); |
| 2837 DCHECK_LT(precision, NumTexCoordPrecisions); | 2783 DCHECK_LT(precision, NumTexCoordPrecisions); |
| 2838 DCHECK_GE(sampler, 0); | 2784 DCHECK_GE(sampler, 0); |
| 2839 DCHECK_LT(sampler, NumSamplerTypes); | 2785 DCHECK_LT(sampler, NumSamplerTypes); |
| 2840 TileProgramSwizzle* program = &tile_program_swizzle_[precision][sampler]; | 2786 TileProgramSwizzle* program = &tile_program_swizzle_[precision][sampler]; |
| 2841 if (!program->initialized()) { | 2787 if (!program->initialized()) { |
| 2842 TRACE_EVENT0("cc", "GLRenderer::tileProgramSwizzle::initialize"); | 2788 TRACE_EVENT0("cc", "GLRenderer::tileProgramSwizzle::initialize"); |
| 2843 program->Initialize( | 2789 program->Initialize( |
| 2844 output_surface_->context_provider(), precision, sampler); | 2790 output_surface_->context_provider(), precision, sampler); |
| 2845 } | 2791 } |
| 2846 return program; | 2792 return program; |
| 2847 } | 2793 } |
| 2848 | 2794 |
| 2849 const GLRenderer::TileProgramSwizzleOpaque* | 2795 const GLRenderer::TileProgramSwizzleOpaque* |
| 2850 GLRenderer::GetTileProgramSwizzleOpaque( | 2796 GLRenderer::GetTileProgramSwizzleOpaque(TexCoordPrecision precision, |
| 2851 TexCoordPrecision precision, SamplerType sampler) { | 2797 SamplerType sampler) { |
| 2852 DCHECK_GE(precision, 0); | 2798 DCHECK_GE(precision, 0); |
| 2853 DCHECK_LT(precision, NumTexCoordPrecisions); | 2799 DCHECK_LT(precision, NumTexCoordPrecisions); |
| 2854 DCHECK_GE(sampler, 0); | 2800 DCHECK_GE(sampler, 0); |
| 2855 DCHECK_LT(sampler, NumSamplerTypes); | 2801 DCHECK_LT(sampler, NumSamplerTypes); |
| 2856 TileProgramSwizzleOpaque* program = | 2802 TileProgramSwizzleOpaque* program = |
| 2857 &tile_program_swizzle_opaque_[precision][sampler]; | 2803 &tile_program_swizzle_opaque_[precision][sampler]; |
| 2858 if (!program->initialized()) { | 2804 if (!program->initialized()) { |
| 2859 TRACE_EVENT0("cc", "GLRenderer::tileProgramSwizzleOpaque::initialize"); | 2805 TRACE_EVENT0("cc", "GLRenderer::tileProgramSwizzleOpaque::initialize"); |
| 2860 program->Initialize( | 2806 program->Initialize( |
| 2861 output_surface_->context_provider(), precision, sampler); | 2807 output_surface_->context_provider(), precision, sampler); |
| 2862 } | 2808 } |
| 2863 return program; | 2809 return program; |
| 2864 } | 2810 } |
| 2865 | 2811 |
| 2866 const GLRenderer::TileProgramSwizzleAA* GLRenderer::GetTileProgramSwizzleAA( | 2812 const GLRenderer::TileProgramSwizzleAA* GLRenderer::GetTileProgramSwizzleAA( |
| 2867 TexCoordPrecision precision, SamplerType sampler) { | 2813 TexCoordPrecision precision, |
| 2814 SamplerType sampler) { |
| 2868 DCHECK_GE(precision, 0); | 2815 DCHECK_GE(precision, 0); |
| 2869 DCHECK_LT(precision, NumTexCoordPrecisions); | 2816 DCHECK_LT(precision, NumTexCoordPrecisions); |
| 2870 DCHECK_GE(sampler, 0); | 2817 DCHECK_GE(sampler, 0); |
| 2871 DCHECK_LT(sampler, NumSamplerTypes); | 2818 DCHECK_LT(sampler, NumSamplerTypes); |
| 2872 TileProgramSwizzleAA* program = | 2819 TileProgramSwizzleAA* program = &tile_program_swizzle_aa_[precision][sampler]; |
| 2873 &tile_program_swizzle_aa_[precision][sampler]; | |
| 2874 if (!program->initialized()) { | 2820 if (!program->initialized()) { |
| 2875 TRACE_EVENT0("cc", "GLRenderer::tileProgramSwizzleAA::initialize"); | 2821 TRACE_EVENT0("cc", "GLRenderer::tileProgramSwizzleAA::initialize"); |
| 2876 program->Initialize( | 2822 program->Initialize( |
| 2877 output_surface_->context_provider(), precision, sampler); | 2823 output_surface_->context_provider(), precision, sampler); |
| 2878 } | 2824 } |
| 2879 return program; | 2825 return program; |
| 2880 } | 2826 } |
| 2881 | 2827 |
| 2882 const GLRenderer::TextureProgram* GLRenderer::GetTextureProgram( | 2828 const GLRenderer::TextureProgram* GLRenderer::GetTextureProgram( |
| 2883 TexCoordPrecision precision) { | 2829 TexCoordPrecision precision) { |
| 2884 DCHECK_GE(precision, 0); | 2830 DCHECK_GE(precision, 0); |
| 2885 DCHECK_LT(precision, NumTexCoordPrecisions); | 2831 DCHECK_LT(precision, NumTexCoordPrecisions); |
| 2886 TextureProgram* program = &texture_program_[precision]; | 2832 TextureProgram* program = &texture_program_[precision]; |
| 2887 if (!program->initialized()) { | 2833 if (!program->initialized()) { |
| 2888 TRACE_EVENT0("cc", "GLRenderer::textureProgram::initialize"); | 2834 TRACE_EVENT0("cc", "GLRenderer::textureProgram::initialize"); |
| 2889 program->Initialize( | 2835 program->Initialize( |
| 2890 output_surface_->context_provider(), precision, SamplerType2D); | 2836 output_surface_->context_provider(), precision, SamplerType2D); |
| 2891 } | 2837 } |
| 2892 return program; | 2838 return program; |
| 2893 } | 2839 } |
| 2894 | 2840 |
| 2895 const GLRenderer::NonPremultipliedTextureProgram* | 2841 const GLRenderer::NonPremultipliedTextureProgram* |
| 2896 GLRenderer::GetNonPremultipliedTextureProgram(TexCoordPrecision precision) { | 2842 GLRenderer::GetNonPremultipliedTextureProgram(TexCoordPrecision precision) { |
| 2897 DCHECK_GE(precision, 0); | 2843 DCHECK_GE(precision, 0); |
| 2898 DCHECK_LT(precision, NumTexCoordPrecisions); | 2844 DCHECK_LT(precision, NumTexCoordPrecisions); |
| 2899 NonPremultipliedTextureProgram* program = | 2845 NonPremultipliedTextureProgram* program = |
| 2900 &nonpremultiplied_texture_program_[precision]; | 2846 &nonpremultiplied_texture_program_[precision]; |
| 2901 if (!program->initialized()) { | 2847 if (!program->initialized()) { |
| 2902 TRACE_EVENT0("cc", | 2848 TRACE_EVENT0("cc", |
| 2903 "GLRenderer::NonPremultipliedTextureProgram::Initialize"); | 2849 "GLRenderer::NonPremultipliedTextureProgram::Initialize"); |
| 2904 program->Initialize( | 2850 program->Initialize( |
| 2905 output_surface_->context_provider(), precision, SamplerType2D); | 2851 output_surface_->context_provider(), precision, SamplerType2D); |
| 2906 } | 2852 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2929 &nonpremultiplied_texture_background_program_[precision]; | 2875 &nonpremultiplied_texture_background_program_[precision]; |
| 2930 if (!program->initialized()) { | 2876 if (!program->initialized()) { |
| 2931 TRACE_EVENT0("cc", | 2877 TRACE_EVENT0("cc", |
| 2932 "GLRenderer::NonPremultipliedTextureProgram::Initialize"); | 2878 "GLRenderer::NonPremultipliedTextureProgram::Initialize"); |
| 2933 program->Initialize( | 2879 program->Initialize( |
| 2934 output_surface_->context_provider(), precision, SamplerType2D); | 2880 output_surface_->context_provider(), precision, SamplerType2D); |
| 2935 } | 2881 } |
| 2936 return program; | 2882 return program; |
| 2937 } | 2883 } |
| 2938 | 2884 |
| 2939 const GLRenderer::TextureProgram* | 2885 const GLRenderer::TextureProgram* GLRenderer::GetTextureIOSurfaceProgram( |
| 2940 GLRenderer::GetTextureIOSurfaceProgram(TexCoordPrecision precision) { | 2886 TexCoordPrecision precision) { |
| 2941 DCHECK_GE(precision, 0); | 2887 DCHECK_GE(precision, 0); |
| 2942 DCHECK_LT(precision, NumTexCoordPrecisions); | 2888 DCHECK_LT(precision, NumTexCoordPrecisions); |
| 2943 TextureProgram* program = &texture_io_surface_program_[precision]; | 2889 TextureProgram* program = &texture_io_surface_program_[precision]; |
| 2944 if (!program->initialized()) { | 2890 if (!program->initialized()) { |
| 2945 TRACE_EVENT0("cc", "GLRenderer::textureIOSurfaceProgram::initialize"); | 2891 TRACE_EVENT0("cc", "GLRenderer::textureIOSurfaceProgram::initialize"); |
| 2946 program->Initialize( | 2892 program->Initialize( |
| 2947 output_surface_->context_provider(), precision, SamplerType2DRect); | 2893 output_surface_->context_provider(), precision, SamplerType2DRect); |
| 2948 } | 2894 } |
| 2949 return program; | 2895 return program; |
| 2950 } | 2896 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2979 GLRenderer::GetVideoStreamTextureProgram(TexCoordPrecision precision) { | 2925 GLRenderer::GetVideoStreamTextureProgram(TexCoordPrecision precision) { |
| 2980 if (!Capabilities().using_egl_image) | 2926 if (!Capabilities().using_egl_image) |
| 2981 return NULL; | 2927 return NULL; |
| 2982 DCHECK_GE(precision, 0); | 2928 DCHECK_GE(precision, 0); |
| 2983 DCHECK_LT(precision, NumTexCoordPrecisions); | 2929 DCHECK_LT(precision, NumTexCoordPrecisions); |
| 2984 VideoStreamTextureProgram* program = | 2930 VideoStreamTextureProgram* program = |
| 2985 &video_stream_texture_program_[precision]; | 2931 &video_stream_texture_program_[precision]; |
| 2986 if (!program->initialized()) { | 2932 if (!program->initialized()) { |
| 2987 TRACE_EVENT0("cc", "GLRenderer::streamTextureProgram::initialize"); | 2933 TRACE_EVENT0("cc", "GLRenderer::streamTextureProgram::initialize"); |
| 2988 program->Initialize( | 2934 program->Initialize( |
| 2989 output_surface_->context_provider(), | 2935 output_surface_->context_provider(), precision, SamplerTypeExternalOES); |
| 2990 precision, | |
| 2991 SamplerTypeExternalOES); | |
| 2992 } | 2936 } |
| 2993 return program; | 2937 return program; |
| 2994 } | 2938 } |
| 2995 | 2939 |
| 2996 void GLRenderer::CleanupSharedObjects() { | 2940 void GLRenderer::CleanupSharedObjects() { |
| 2997 shared_geometry_.reset(); | 2941 shared_geometry_.reset(); |
| 2998 | 2942 |
| 2999 for (int i = 0; i < NumTexCoordPrecisions; ++i) { | 2943 for (int i = 0; i < NumTexCoordPrecisions; ++i) { |
| 3000 for (int j = 0; j < NumSamplerTypes; ++j) { | 2944 for (int j = 0; j < NumSamplerTypes; ++j) { |
| 3001 tile_program_[i][j].Cleanup(gl_); | 2945 tile_program_[i][j].Cleanup(gl_); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 3026 video_stream_texture_program_[i].Cleanup(gl_); | 2970 video_stream_texture_program_[i].Cleanup(gl_); |
| 3027 } | 2971 } |
| 3028 | 2972 |
| 3029 tile_checkerboard_program_.Cleanup(gl_); | 2973 tile_checkerboard_program_.Cleanup(gl_); |
| 3030 | 2974 |
| 3031 debug_border_program_.Cleanup(gl_); | 2975 debug_border_program_.Cleanup(gl_); |
| 3032 solid_color_program_.Cleanup(gl_); | 2976 solid_color_program_.Cleanup(gl_); |
| 3033 solid_color_program_aa_.Cleanup(gl_); | 2977 solid_color_program_aa_.Cleanup(gl_); |
| 3034 | 2978 |
| 3035 if (offscreen_framebuffer_id_) | 2979 if (offscreen_framebuffer_id_) |
| 3036 GLC(context_, context_->deleteFramebuffer(offscreen_framebuffer_id_)); | 2980 GLC(gl_, gl_->DeleteFramebuffers(1, &offscreen_framebuffer_id_)); |
| 3037 | 2981 |
| 3038 if (on_demand_tile_raster_resource_id_) | 2982 if (on_demand_tile_raster_resource_id_) |
| 3039 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_); | 2983 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_); |
| 3040 | 2984 |
| 3041 ReleaseRenderPassTextures(); | 2985 ReleaseRenderPassTextures(); |
| 3042 } | 2986 } |
| 3043 | 2987 |
| 3044 void GLRenderer::ReinitializeGLState() { | 2988 void GLRenderer::ReinitializeGLState() { |
| 3045 // Bind the common vertex attributes used for drawing all the layers. | 2989 // Bind the common vertex attributes used for drawing all the layers. |
| 3046 shared_geometry_->PrepareForDraw(); | 2990 shared_geometry_->PrepareForDraw(); |
| 3047 | 2991 |
| 3048 GLC(context_, context_->disable(GL_DEPTH_TEST)); | 2992 GLC(gl_, gl_->Disable(GL_DEPTH_TEST)); |
| 3049 GLC(context_, context_->disable(GL_CULL_FACE)); | 2993 GLC(gl_, gl_->Disable(GL_CULL_FACE)); |
| 3050 GLC(context_, context_->colorMask(true, true, true, true)); | 2994 GLC(gl_, gl_->ColorMask(true, true, true, true)); |
| 3051 GLC(context_, context_->disable(GL_STENCIL_TEST)); | 2995 GLC(gl_, gl_->Disable(GL_STENCIL_TEST)); |
| 3052 stencil_shadow_ = false; | 2996 stencil_shadow_ = false; |
| 3053 GLC(context_, context_->enable(GL_BLEND)); | 2997 GLC(gl_, gl_->Enable(GL_BLEND)); |
| 3054 blend_shadow_ = true; | 2998 blend_shadow_ = true; |
| 3055 GLC(context_, context_->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); | 2999 GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); |
| 3056 GLC(context_, context_->activeTexture(GL_TEXTURE0)); | 3000 GLC(gl_, gl_->ActiveTexture(GL_TEXTURE0)); |
| 3057 program_shadow_ = 0; | 3001 program_shadow_ = 0; |
| 3058 | 3002 |
| 3059 // Make sure scissoring starts as disabled. | 3003 // Make sure scissoring starts as disabled. |
| 3060 is_scissor_enabled_ = false; | 3004 is_scissor_enabled_ = false; |
| 3061 GLC(context_, context_->disable(GL_SCISSOR_TEST)); | 3005 GLC(gl_, gl_->Disable(GL_SCISSOR_TEST)); |
| 3062 scissor_rect_needs_reset_ = true; | 3006 scissor_rect_needs_reset_ = true; |
| 3063 } | 3007 } |
| 3064 | 3008 |
| 3065 bool GLRenderer::IsContextLost() { | 3009 bool GLRenderer::IsContextLost() { |
| 3066 return output_surface_->context_provider()->IsContextLost(); | 3010 return output_surface_->context_provider()->IsContextLost(); |
| 3067 } | 3011 } |
| 3068 | 3012 |
| 3069 } // namespace cc | 3013 } // namespace cc |
| OLD | NEW |