Chromium Code Reviews

Side by Side Diff: cc/output/gl_renderer.cc

Issue 23060011: Pass the quad's rect (contents_rect) origin to skia image filters as an offset in the CTM. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add pixel test. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
OLDNEW
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 475 matching lines...)
486 // texture. 486 // texture.
487 renderer->resource_provider()->Flush(); 487 renderer->resource_provider()->Flush();
488 488
489 // Make sure skia uses the correct GL context. 489 // Make sure skia uses the correct GL context.
490 offscreen_contexts->Context3d()->makeContextCurrent(); 490 offscreen_contexts->Context3d()->makeContextCurrent();
491 491
492 // Lazily label this context. 492 // Lazily label this context.
493 renderer->LazyLabelOffscreenContext(offscreen_contexts); 493 renderer->LazyLabelOffscreenContext(offscreen_contexts);
494 494
495 SkBitmap source = 495 SkBitmap source =
496 RenderSurfaceFilters::Apply(filters, 496 RenderSurfaceFilters::Apply(filters,
danakj 2013/08/28 22:26:58 Will this path do the right thing already? Are the
Stephen White 2013/08/29 00:36:34 No, there are none. There are no crop rects in fil
497 lock.texture_id(), 497 lock.texture_id(),
498 source_texture_resource->size(), 498 source_texture_resource->size(),
499 offscreen_contexts->GrContext()); 499 offscreen_contexts->GrContext());
500 500
501 // Flush skia context so that all the rendered stuff appears on the 501 // Flush skia context so that all the rendered stuff appears on the
502 // texture. 502 // texture.
503 offscreen_contexts->GrContext()->flush(); 503 offscreen_contexts->GrContext()->flush();
504 504
505 // Flush the GL context so rendering results from this context are 505 // Flush the GL context so rendering results from this context are
506 // visible in the compositor's context. 506 // visible in the compositor's context.
507 offscreen_contexts->Context3d()->flush(); 507 offscreen_contexts->Context3d()->flush();
508 508
509 // Use the compositor's GL context again. 509 // Use the compositor's GL context again.
510 renderer->Context()->makeContextCurrent(); 510 renderer->Context()->makeContextCurrent();
511 return source; 511 return source;
512 } 512 }
513 513
514 static SkBitmap ApplyImageFilter(GLRenderer* renderer, 514 static SkBitmap ApplyImageFilter(GLRenderer* renderer,
515 ContextProvider* offscreen_contexts, 515 ContextProvider* offscreen_contexts,
516 gfx::Point origin,
516 SkImageFilter* filter, 517 SkImageFilter* filter,
517 ScopedResource* source_texture_resource) { 518 ScopedResource* source_texture_resource) {
518 if (!filter) 519 if (!filter)
519 return SkBitmap(); 520 return SkBitmap();
520 521
521 if (!offscreen_contexts || !offscreen_contexts->GrContext()) 522 if (!offscreen_contexts || !offscreen_contexts->GrContext())
522 return SkBitmap(); 523 return SkBitmap();
523 524
524 ResourceProvider::ScopedWriteLockGL lock(renderer->resource_provider(), 525 ResourceProvider::ScopedWriteLockGL lock(renderer->resource_provider(),
525 source_texture_resource->id()); 526 source_texture_resource->id());
(...skipping 44 matching lines...)
570 skia::AdoptRef(scratch_texture.detach()); 571 skia::AdoptRef(scratch_texture.detach());
571 572
572 // Create a device and canvas using that backing store. 573 // Create a device and canvas using that backing store.
573 SkGpuDevice device(offscreen_contexts->GrContext(), backing_store.get()); 574 SkGpuDevice device(offscreen_contexts->GrContext(), backing_store.get());
574 SkCanvas canvas(&device); 575 SkCanvas canvas(&device);
575 576
576 // Draw the source bitmap through the filter to the canvas. 577 // Draw the source bitmap through the filter to the canvas.
577 SkPaint paint; 578 SkPaint paint;
578 paint.setImageFilter(filter); 579 paint.setImageFilter(filter);
579 canvas.clear(SK_ColorTRANSPARENT); 580 canvas.clear(SK_ColorTRANSPARENT);
581 canvas.translate(SkFloatToScalar(-origin.x()), SkFloatToScalar(-origin.y()));
danakj 2013/08/28 22:26:58 nit: I think you want SkIntToScalar?
Stephen White 2013/08/29 00:36:34 Done. Thanks!
580 canvas.drawSprite(source, 0, 0, &paint); 582 canvas.drawSprite(source, 0, 0, &paint);
danakj 2013/08/28 22:26:58 Could you just pass the origin here instead of 0,0
Stephen White 2013/08/29 00:36:34 Nope. We're drawing the bitmap in the correct plac
581 583
582 // Flush skia context so that all the rendered stuff appears on the 584 // Flush skia context so that all the rendered stuff appears on the
583 // texture. 585 // texture.
584 offscreen_contexts->GrContext()->flush(); 586 offscreen_contexts->GrContext()->flush();
585 587
586 // Flush the GL context so rendering results from this context are 588 // Flush the GL context so rendering results from this context are
587 // visible in the compositor's context. 589 // visible in the compositor's context.
588 offscreen_contexts->Context3d()->flush(); 590 offscreen_contexts->Context3d()->flush();
589 591
590 // Use the compositor's GL context again. 592 // Use the compositor's GL context again.
(...skipping 180 matching lines...)
771 cf = skia::AdoptRef(colorfilter_rawptr); 773 cf = skia::AdoptRef(colorfilter_rawptr);
772 } 774 }
773 775
774 if (cf && cf->asColorMatrix(color_matrix) && !quad->filter->getInput(0)) { 776 if (cf && cf->asColorMatrix(color_matrix) && !quad->filter->getInput(0)) {
775 // We have a single color matrix as a filter; apply it locally 777 // We have a single color matrix as a filter; apply it locally
776 // in the compositor. 778 // in the compositor.
777 use_color_matrix = true; 779 use_color_matrix = true;
778 } else { 780 } else {
779 filter_bitmap = ApplyImageFilter(this, 781 filter_bitmap = ApplyImageFilter(this,
780 frame->offscreen_context_provider, 782 frame->offscreen_context_provider,
783 quad->rect.origin(),
781 quad->filter.get(), 784 quad->filter.get(),
782 contents_texture); 785 contents_texture);
783 } 786 }
784 } else if (!quad->filters.IsEmpty()) { 787 } else if (!quad->filters.IsEmpty()) {
785 FilterOperations optimized_filters = 788 FilterOperations optimized_filters =
786 RenderSurfaceFilters::Optimize(quad->filters); 789 RenderSurfaceFilters::Optimize(quad->filters);
787 790
788 if ((optimized_filters.size() == 1) && 791 if ((optimized_filters.size() == 1) &&
789 (optimized_filters.at(0).type() == FilterOperation::COLOR_MATRIX)) { 792 (optimized_filters.at(0).type() == FilterOperation::COLOR_MATRIX)) {
790 memcpy( 793 memcpy(
(...skipping 2362 matching lines...)
3153 std::string unique_context_name = base::StringPrintf( 3156 std::string unique_context_name = base::StringPrintf(
3154 "%s-Offscreen-%p", 3157 "%s-Offscreen-%p",
3155 Settings().compositor_name.c_str(), 3158 Settings().compositor_name.c_str(),
3156 context_); 3159 context_);
3157 offscreen_context_provider->Context3d()->pushGroupMarkerEXT( 3160 offscreen_context_provider->Context3d()->pushGroupMarkerEXT(
3158 unique_context_name.c_str()); 3161 unique_context_name.c_str());
3159 } 3162 }
3160 3163
3161 3164
3162 } // namespace cc 3165 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/trees/layer_tree_host_pixeltest_filters.cc » ('j') | cc/trees/layer_tree_host_pixeltest_filters.cc » ('J')

Powered by Google App Engine