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 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 508 // Flush the GL context so rendering results from this context are | 508 // Flush the GL context so rendering results from this context are |
| 509 // visible in the compositor's context. | 509 // visible in the compositor's context. |
| 510 offscreen_contexts->Context3d()->flush(); | 510 offscreen_contexts->Context3d()->flush(); |
| 511 | 511 |
| 512 // Use the compositor's GL context again. | 512 // Use the compositor's GL context again. |
| 513 renderer->Context()->makeContextCurrent(); | 513 renderer->Context()->makeContextCurrent(); |
| 514 return source; | 514 return source; |
| 515 } | 515 } |
| 516 | 516 |
| 517 static SkBitmap ApplyImageFilter(GLRenderer* renderer, | 517 static SkBitmap ApplyImageFilter(GLRenderer* renderer, |
| 518 gfx::Rect rect, | |
|
danakj
2013/08/19 21:09:08
better variable name than the type of the variable
| |
| 518 SkImageFilter* filter, | 519 SkImageFilter* filter, |
| 519 ScopedResource* source_texture_resource) { | 520 ScopedResource* source_texture_resource) { |
| 520 if (!filter) | 521 if (!filter) |
| 521 return SkBitmap(); | 522 return SkBitmap(); |
| 522 | 523 |
| 523 ContextProvider* offscreen_contexts = | 524 ContextProvider* offscreen_contexts = |
| 524 renderer->resource_provider()->offscreen_context_provider(); | 525 renderer->resource_provider()->offscreen_context_provider(); |
| 525 if (!offscreen_contexts || !offscreen_contexts->GrContext()) | 526 if (!offscreen_contexts || !offscreen_contexts->GrContext()) |
| 526 return SkBitmap(); | 527 return SkBitmap(); |
| 527 | 528 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 574 skia::AdoptRef(scratch_texture.detach()); | 575 skia::AdoptRef(scratch_texture.detach()); |
| 575 | 576 |
| 576 // Create a device and canvas using that backing store. | 577 // Create a device and canvas using that backing store. |
| 577 SkGpuDevice device(offscreen_contexts->GrContext(), backing_store.get()); | 578 SkGpuDevice device(offscreen_contexts->GrContext(), backing_store.get()); |
| 578 SkCanvas canvas(&device); | 579 SkCanvas canvas(&device); |
| 579 | 580 |
| 580 // Draw the source bitmap through the filter to the canvas. | 581 // Draw the source bitmap through the filter to the canvas. |
| 581 SkPaint paint; | 582 SkPaint paint; |
| 582 paint.setImageFilter(filter); | 583 paint.setImageFilter(filter); |
| 583 canvas.clear(SK_ColorTRANSPARENT); | 584 canvas.clear(SK_ColorTRANSPARENT); |
| 585 canvas.translate(SkFloatToScalar(rect.x()), SkFloatToScalar(rect.y())); | |
| 584 canvas.drawSprite(source, 0, 0, &paint); | 586 canvas.drawSprite(source, 0, 0, &paint); |
| 585 | 587 |
| 586 // Flush skia context so that all the rendered stuff appears on the | 588 // Flush skia context so that all the rendered stuff appears on the |
| 587 // texture. | 589 // texture. |
| 588 offscreen_contexts->GrContext()->flush(); | 590 offscreen_contexts->GrContext()->flush(); |
| 589 | 591 |
| 590 // Flush the GL context so rendering results from this context are | 592 // Flush the GL context so rendering results from this context are |
| 591 // visible in the compositor's context. | 593 // visible in the compositor's context. |
| 592 offscreen_contexts->Context3d()->flush(); | 594 offscreen_contexts->Context3d()->flush(); |
| 593 | 595 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 770 SkColorFilter* colorfilter_rawptr = NULL; | 772 SkColorFilter* colorfilter_rawptr = NULL; |
| 771 quad->filter->asColorFilter(&colorfilter_rawptr); | 773 quad->filter->asColorFilter(&colorfilter_rawptr); |
| 772 cf = skia::AdoptRef(colorfilter_rawptr); | 774 cf = skia::AdoptRef(colorfilter_rawptr); |
| 773 } | 775 } |
| 774 | 776 |
| 775 if (cf && cf->asColorMatrix(color_matrix) && !quad->filter->getInput(0)) { | 777 if (cf && cf->asColorMatrix(color_matrix) && !quad->filter->getInput(0)) { |
| 776 // We have a single color matrix as a filter; apply it locally | 778 // We have a single color matrix as a filter; apply it locally |
| 777 // in the compositor. | 779 // in the compositor. |
| 778 use_color_matrix = true; | 780 use_color_matrix = true; |
| 779 } else { | 781 } else { |
| 780 filter_bitmap = | 782 filter_bitmap = ApplyImageFilter( |
| 781 ApplyImageFilter(this, quad->filter.get(), contents_texture); | 783 this, quad->rect, quad->filter.get(), contents_texture); |
| 782 } | 784 } |
| 783 } else if (!quad->filters.IsEmpty()) { | 785 } else if (!quad->filters.IsEmpty()) { |
| 784 FilterOperations optimized_filters = | 786 FilterOperations optimized_filters = |
| 785 RenderSurfaceFilters::Optimize(quad->filters); | 787 RenderSurfaceFilters::Optimize(quad->filters); |
| 786 | 788 |
| 787 if ((optimized_filters.size() == 1) && | 789 if ((optimized_filters.size() == 1) && |
| 788 (optimized_filters.at(0).type() == FilterOperation::COLOR_MATRIX)) { | 790 (optimized_filters.at(0).type() == FilterOperation::COLOR_MATRIX)) { |
| 789 memcpy( | 791 memcpy( |
| 790 color_matrix, optimized_filters.at(0).matrix(), sizeof(color_matrix)); | 792 color_matrix, optimized_filters.at(0).matrix(), sizeof(color_matrix)); |
| 791 use_color_matrix = true; | 793 use_color_matrix = true; |
| (...skipping 2364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3156 std::string unique_context_name = base::StringPrintf( | 3158 std::string unique_context_name = base::StringPrintf( |
| 3157 "%s-Offscreen-%p", | 3159 "%s-Offscreen-%p", |
| 3158 Settings().compositor_name.c_str(), | 3160 Settings().compositor_name.c_str(), |
| 3159 context_); | 3161 context_); |
| 3160 resource_provider()->offscreen_context_provider()->Context3d()-> | 3162 resource_provider()->offscreen_context_provider()->Context3d()-> |
| 3161 pushGroupMarkerEXT(unique_context_name.c_str()); | 3163 pushGroupMarkerEXT(unique_context_name.c_str()); |
| 3162 } | 3164 } |
| 3163 | 3165 |
| 3164 | 3166 |
| 3165 } // namespace cc | 3167 } // namespace cc |
| OLD | NEW |