| 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 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 GLC(gl_, gl_->LineWidth(quad->width)); | 477 GLC(gl_, gl_->LineWidth(quad->width)); |
| 478 | 478 |
| 479 // The indices for the line are stored in the same array as the triangle | 479 // The indices for the line are stored in the same array as the triangle |
| 480 // indices. | 480 // indices. |
| 481 GLC(gl_, gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0)); | 481 GLC(gl_, gl_->DrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0)); |
| 482 } | 482 } |
| 483 | 483 |
| 484 static SkBitmap ApplyImageFilter(GLRenderer* renderer, | 484 static SkBitmap ApplyImageFilter(GLRenderer* renderer, |
| 485 ContextProvider* offscreen_contexts, | 485 ContextProvider* offscreen_contexts, |
| 486 const gfx::Point& origin, | 486 const gfx::Point& origin, |
| 487 const gfx::Vector2dF& scale, |
| 487 SkImageFilter* filter, | 488 SkImageFilter* filter, |
| 488 ScopedResource* source_texture_resource) { | 489 ScopedResource* source_texture_resource) { |
| 489 if (!filter) | 490 if (!filter) |
| 490 return SkBitmap(); | 491 return SkBitmap(); |
| 491 | 492 |
| 492 if (!offscreen_contexts || !offscreen_contexts->GrContext()) | 493 if (!offscreen_contexts || !offscreen_contexts->GrContext()) |
| 493 return SkBitmap(); | 494 return SkBitmap(); |
| 494 | 495 |
| 495 ResourceProvider::ScopedWriteLockGL lock(renderer->resource_provider(), | 496 ResourceProvider::ScopedWriteLockGL lock(renderer->resource_provider(), |
| 496 source_texture_resource->id()); | 497 source_texture_resource->id()); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 | 541 |
| 541 // Create a device and canvas using that backing store. | 542 // Create a device and canvas using that backing store. |
| 542 SkGpuDevice device(offscreen_contexts->GrContext(), backing_store.get()); | 543 SkGpuDevice device(offscreen_contexts->GrContext(), backing_store.get()); |
| 543 SkCanvas canvas(&device); | 544 SkCanvas canvas(&device); |
| 544 | 545 |
| 545 // Draw the source bitmap through the filter to the canvas. | 546 // Draw the source bitmap through the filter to the canvas. |
| 546 SkPaint paint; | 547 SkPaint paint; |
| 547 paint.setImageFilter(filter); | 548 paint.setImageFilter(filter); |
| 548 canvas.clear(SK_ColorTRANSPARENT); | 549 canvas.clear(SK_ColorTRANSPARENT); |
| 549 | 550 |
| 550 // TODO(senorblanco): in addition to the origin translation here, the canvas | |
| 551 // should also be scaled to accomodate device pixel ratio and pinch zoom. See | |
| 552 // crbug.com/281516 and crbug.com/281518. | |
| 553 canvas.translate(SkIntToScalar(-origin.x()), SkIntToScalar(-origin.y())); | 551 canvas.translate(SkIntToScalar(-origin.x()), SkIntToScalar(-origin.y())); |
| 552 canvas.scale(scale.x(), scale.y()); |
| 554 canvas.drawSprite(source, 0, 0, &paint); | 553 canvas.drawSprite(source, 0, 0, &paint); |
| 555 | 554 |
| 556 // Flush skia context so that all the rendered stuff appears on the | 555 // Flush skia context so that all the rendered stuff appears on the |
| 557 // texture. | 556 // texture. |
| 558 offscreen_contexts->GrContext()->flush(); | 557 offscreen_contexts->GrContext()->flush(); |
| 559 | 558 |
| 560 // Flush the GL context so rendering results from this context are | 559 // Flush the GL context so rendering results from this context are |
| 561 // visible in the compositor's context. | 560 // visible in the compositor's context. |
| 562 offscreen_contexts->ContextGL()->Flush(); | 561 offscreen_contexts->ContextGL()->Flush(); |
| 563 | 562 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 | 754 |
| 756 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( | 755 skia::RefPtr<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( |
| 757 quad->background_filters, device_background_texture->size()); | 756 quad->background_filters, device_background_texture->size()); |
| 758 | 757 |
| 759 SkBitmap filtered_device_background; | 758 SkBitmap filtered_device_background; |
| 760 if (apply_background_filters) { | 759 if (apply_background_filters) { |
| 761 filtered_device_background = | 760 filtered_device_background = |
| 762 ApplyImageFilter(this, | 761 ApplyImageFilter(this, |
| 763 frame->offscreen_context_provider, | 762 frame->offscreen_context_provider, |
| 764 quad->rect.origin(), | 763 quad->rect.origin(), |
| 764 quad->filters_scale, |
| 765 filter.get(), | 765 filter.get(), |
| 766 device_background_texture.get()); | 766 device_background_texture.get()); |
| 767 } | 767 } |
| 768 *background_changed = (filtered_device_background.getTexture() != NULL); | 768 *background_changed = (filtered_device_background.getTexture() != NULL); |
| 769 | 769 |
| 770 int filtered_device_background_texture_id = 0; | 770 int filtered_device_background_texture_id = 0; |
| 771 scoped_ptr<ResourceProvider::ScopedReadLockGL> lock; | 771 scoped_ptr<ResourceProvider::ScopedReadLockGL> lock; |
| 772 if (filtered_device_background.getTexture()) { | 772 if (filtered_device_background.getTexture()) { |
| 773 GrTexture* texture = | 773 GrTexture* texture = |
| 774 reinterpret_cast<GrTexture*>(filtered_device_background.getTexture()); | 774 reinterpret_cast<GrTexture*>(filtered_device_background.getTexture()); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 } | 889 } |
| 890 | 890 |
| 891 if (cf && cf->asColorMatrix(color_matrix) && !filter->getInput(0)) { | 891 if (cf && cf->asColorMatrix(color_matrix) && !filter->getInput(0)) { |
| 892 // We have a single color matrix as a filter; apply it locally | 892 // We have a single color matrix as a filter; apply it locally |
| 893 // in the compositor. | 893 // in the compositor. |
| 894 use_color_matrix = true; | 894 use_color_matrix = true; |
| 895 } else { | 895 } else { |
| 896 filter_bitmap = ApplyImageFilter(this, | 896 filter_bitmap = ApplyImageFilter(this, |
| 897 frame->offscreen_context_provider, | 897 frame->offscreen_context_provider, |
| 898 quad->rect.origin(), | 898 quad->rect.origin(), |
| 899 quad->filters_scale, |
| 899 filter.get(), | 900 filter.get(), |
| 900 contents_texture); | 901 contents_texture); |
| 901 } | 902 } |
| 902 } | 903 } |
| 903 } | 904 } |
| 904 | 905 |
| 905 if (quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode && | 906 if (quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode && |
| 906 background_texture) { | 907 background_texture) { |
| 907 filter_bitmap = | 908 filter_bitmap = |
| 908 ApplyBlendModeWithBackdrop(this, | 909 ApplyBlendModeWithBackdrop(this, |
| (...skipping 2127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3036 is_scissor_enabled_ = false; | 3037 is_scissor_enabled_ = false; |
| 3037 GLC(gl_, gl_->Disable(GL_SCISSOR_TEST)); | 3038 GLC(gl_, gl_->Disable(GL_SCISSOR_TEST)); |
| 3038 scissor_rect_needs_reset_ = true; | 3039 scissor_rect_needs_reset_ = true; |
| 3039 } | 3040 } |
| 3040 | 3041 |
| 3041 bool GLRenderer::IsContextLost() { | 3042 bool GLRenderer::IsContextLost() { |
| 3042 return output_surface_->context_provider()->IsContextLost(); | 3043 return output_surface_->context_provider()->IsContextLost(); |
| 3043 } | 3044 } |
| 3044 | 3045 |
| 3045 } // namespace cc | 3046 } // namespace cc |
| OLD | NEW |