Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(612)

Side by Side Diff: Source/core/platform/graphics/GraphicsContext.cpp

Issue 23643003: ImageBuffer-less SVG masking and clipping. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Removed Linux rebaselines. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 void GraphicsContext::restore() 123 void GraphicsContext::restore()
124 { 124 {
125 if (paintingDisabled()) 125 if (paintingDisabled())
126 return; 126 return;
127 127
128 if (m_stateStack.size() == 1) { 128 if (m_stateStack.size() == 1) {
129 LOG_ERROR("ERROR void GraphicsContext::restore() stack is empty"); 129 LOG_ERROR("ERROR void GraphicsContext::restore() stack is empty");
130 return; 130 return;
131 } 131 }
132 132
133 if (!m_state->m_imageBufferClip.empty()) {
134 applyClipFromImage(m_state->m_clip, m_state->m_imageBufferClip);
135 m_canvas->restore();
136 }
137
138 m_stateStack.removeLast(); 133 m_stateStack.removeLast();
139 m_state = m_stateStack.last().get(); 134 m_state = m_stateStack.last().get();
140 135
141 DeferredSaveState savedState = m_saveStateStack.last(); 136 DeferredSaveState savedState = m_saveStateStack.last();
142 m_saveStateStack.removeLast(); 137 m_saveStateStack.removeLast();
143 m_deferredSaveFlags = savedState.m_flags; 138 m_deferredSaveFlags = savedState.m_flags;
144 m_canvas->restoreToCount(savedState.m_restoreCount); 139 m_canvas->restoreToCount(savedState.m_restoreCount);
145 } 140 }
146 141
147 void GraphicsContext::saveLayer(const SkRect* bounds, const SkPaint* paint, SkCa nvas::SaveFlags saveFlags) 142 void GraphicsContext::saveLayer(const SkRect* bounds, const SkPaint* paint, SkCa nvas::SaveFlags saveFlags)
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 return; 421 return;
427 422
428 restoreLayer(); 423 restoreLayer();
429 424
430 ASSERT(m_transparencyCount > 0); 425 ASSERT(m_transparencyCount > 0);
431 #if !ASSERT_DISABLED 426 #if !ASSERT_DISABLED
432 --m_transparencyCount; 427 --m_transparencyCount;
433 #endif 428 #endif
434 } 429 }
435 430
436 void GraphicsContext::clipToImageBuffer(const ImageBuffer* imageBuffer, const Fl oatRect& rect)
437 {
438 if (paintingDisabled())
439 return;
440
441 SkRect bounds = WebCoreFloatRectToSKRect(rect);
442
443 if (imageBuffer->internalSize().isEmpty()) {
444 clipRect(bounds);
445 return;
446 }
447
448 // Skia doesn't support clipping to an image, so we create a layer. The next
449 // time restore is invoked the layer and |imageBuffer| are combined to
450 // create the resulting image.
451 m_state->m_clip = bounds;
452
453 // Get the absolute coordinates of the stored clipping rectangle to make it
454 // independent of any transform changes.
455 getTotalMatrix().mapRect(&m_state->m_clip);
456
457 SkCanvas::SaveFlags saveFlags = static_cast<SkCanvas::SaveFlags>(SkCanvas::k HasAlphaLayer_SaveFlag | SkCanvas::kFullColorLayer_SaveFlag);
458 saveLayer(&bounds, 0, saveFlags);
459
460 const SkBitmap* bitmap = imageBuffer->context()->bitmap();
461
462 if (m_trackOpaqueRegion) {
463 SkRect opaqueRect = bitmap->isOpaque() ? m_state->m_clip : SkRect::MakeE mpty();
464 m_opaqueRegion.setImageMask(opaqueRect);
465 }
466
467 // Copy off the image as |imageBuffer| may be deleted before restore is invo ked.
468 if (bitmap->isImmutable())
469 m_state->m_imageBufferClip = *bitmap;
470 else {
471 // We need to make a deep-copy of the pixels themselves, so they don't
472 // change on us between now and when we want to apply them in restore()
473 bitmap->copyTo(&m_state->m_imageBufferClip, SkBitmap::kARGB_8888_Config) ;
474 }
475 }
476
477 void GraphicsContext::setupPaintForFilling(SkPaint* paint) const 431 void GraphicsContext::setupPaintForFilling(SkPaint* paint) const
478 { 432 {
479 if (paintingDisabled()) 433 if (paintingDisabled())
480 return; 434 return;
481 435
482 setupPaintCommon(paint); 436 setupPaintCommon(paint);
483 437
484 setupShader(paint, m_state->m_fillGradient.get(), m_state->m_fillPattern.get (), m_state->m_fillColor.rgb()); 438 setupShader(paint, m_state->m_fillGradient.get(), m_state->m_fillPattern.get (), m_state->m_fillColor.rgb());
485 } 439 }
486 440
(...skipping 1376 matching lines...) Expand 10 before | Expand all | Expand 10 after
1863 } else if (pat) { 1817 } else if (pat) {
1864 shader = pat->shader(); 1818 shader = pat->shader();
1865 color = SK_ColorBLACK; 1819 color = SK_ColorBLACK;
1866 paint->setFilterBitmap(imageInterpolationQuality() != InterpolationNone) ; 1820 paint->setFilterBitmap(imageInterpolationQuality() != InterpolationNone) ;
1867 } 1821 }
1868 1822
1869 paint->setColor(m_state->applyAlpha(color)); 1823 paint->setColor(m_state->applyAlpha(color));
1870 paint->setShader(shader.get()); 1824 paint->setShader(shader.get());
1871 } 1825 }
1872 1826
1873
1874 void GraphicsContext::applyClipFromImage(const SkRect& rect, const SkBitmap& ima geBuffer)
1875 {
1876 if (paintingDisabled())
1877 return;
1878
1879 // NOTE: this assumes the image mask contains opaque black for the portions that are to be shown, as such we
1880 // only look at the alpha when compositing. I'm not 100% sure this is what W ebKit expects for image clipping.
1881 SkPaint paint;
1882 paint.setXfermodeMode(SkXfermode::kDstIn_Mode);
1883 realizeSave(SkCanvas::kMatrixClip_SaveFlag);
1884 m_canvas->save(SkCanvas::kMatrix_SaveFlag);
1885 m_canvas->resetMatrix();
1886 m_canvas->drawBitmapRect(imageBuffer, 0, rect, &paint);
1887 m_canvas->restore();
1888 }
1889
1890 void GraphicsContext::didDrawTextInRect(const SkRect& textRect) 1827 void GraphicsContext::didDrawTextInRect(const SkRect& textRect)
1891 { 1828 {
1892 if (m_trackTextRegion) { 1829 if (m_trackTextRegion) {
1893 TRACE_EVENT0("skia", "PlatformContextSkia::trackTextRegion"); 1830 TRACE_EVENT0("skia", "PlatformContextSkia::trackTextRegion");
1894 m_textRegion.join(textRect); 1831 m_textRegion.join(textRect);
1895 } 1832 }
1896 } 1833 }
1897 1834
1898 } 1835 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698