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