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

Side by Side Diff: src/pdf/SkPDFDevice.cpp

Issue 116423004: [PDF] Fix clipping in xfermode improvement. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years 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
« gm/xfermodes.cpp ('K') | « gm/xfermodes.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkPDFDevice.h" 8 #include "SkPDFDevice.h"
9 9
10 #include "SkAnnotation.h" 10 #include "SkAnnotation.h"
(...skipping 1894 matching lines...) Expand 10 before | Expand all | Expand 10 after
1905 } 1905 }
1906 if (!dst) { 1906 if (!dst) {
1907 SkASSERT(xfermode == SkXfermode::kSrc_Mode || 1907 SkASSERT(xfermode == SkXfermode::kSrc_Mode ||
1908 xfermode == SkXfermode::kSrcOut_Mode); 1908 xfermode == SkXfermode::kSrcOut_Mode);
1909 return; 1909 return;
1910 } 1910 }
1911 1911
1912 ContentEntry* contentEntries = getContentEntries()->get(); 1912 ContentEntry* contentEntries = getContentEntries()->get();
1913 SkASSERT(dst); 1913 SkASSERT(dst);
1914 SkASSERT(!contentEntries->fNext.get()); 1914 SkASSERT(!contentEntries->fNext.get());
1915 // We have to make a copy of these here because changing the current 1915 // Changing the current content into a form-xobject will destroy the clip
1916 // content into a form-xobject will destroy them. 1916 // objects which is fine since the xobject will already be clipped. However
1917 // if source has shape, we need to clip it too, so a copy of the clip is
1918 // saved.
1917 SkClipStack clipStack = contentEntries->fState.fClipStack; 1919 SkClipStack clipStack = contentEntries->fState.fClipStack;
1918 SkRegion clipRegion = contentEntries->fState.fClipRegion; 1920 SkRegion clipRegion = contentEntries->fState.fClipRegion;
1919 1921
1920 SkMatrix identity; 1922 SkMatrix identity;
1921 identity.reset(); 1923 identity.reset();
1922 SkPaint stockPaint; 1924 SkPaint stockPaint;
1923 1925
1924 SkAutoTUnref<SkPDFFormXObject> srcFormXObject; 1926 SkAutoTUnref<SkPDFFormXObject> srcFormXObject;
1925 if (isContentEmpty()) { 1927 if (isContentEmpty()) {
1926 // If nothing was drawn and there's no shape, then the draw was a 1928 // If nothing was drawn and there's no shape, then the draw was a
1927 // no-op, but dst needs to be restored for that to be true. 1929 // no-op, but dst needs to be restored for that to be true.
1928 // If there is shape, then an empty source with Src, SrcIn, SrcOut, 1930 // If there is shape, then an empty source with Src, SrcIn, SrcOut,
1929 // DstIn, DstAtop or Modulate reduces to Clear and DstOut or SrcAtop 1931 // DstIn, DstAtop or Modulate reduces to Clear and DstOut or SrcAtop
1930 // reduces to Dst. 1932 // reduces to Dst.
1931 if (shape == NULL || xfermode == SkXfermode::kDstOut_Mode || 1933 if (shape == NULL || xfermode == SkXfermode::kDstOut_Mode ||
1932 xfermode == SkXfermode::kSrcATop_Mode) { 1934 xfermode == SkXfermode::kSrcATop_Mode) {
1933 ScopedContentEntry content(this, &clipStack, clipRegion, identity, 1935 ScopedContentEntry content(this, &fExistingClipStack,
1936 fExistingClipRegion, identity,
1934 stockPaint); 1937 stockPaint);
1935 SkPDFUtils::DrawFormXObject(this->addXObjectResource(dst), 1938 SkPDFUtils::DrawFormXObject(this->addXObjectResource(dst),
1936 &content.entry()->fContent); 1939 &content.entry()->fContent);
1937 return; 1940 return;
1938 } else { 1941 } else {
1939 xfermode = SkXfermode::kClear_Mode; 1942 xfermode = SkXfermode::kClear_Mode;
1940 } 1943 }
1941 } else { 1944 } else {
1942 SkASSERT(!fContentEntries->fNext.get()); 1945 SkASSERT(!fContentEntries->fNext.get());
1943 srcFormXObject.reset(createFormXObjectFromDevice()); 1946 srcFormXObject.reset(createFormXObjectFromDevice());
1944 } 1947 }
1945 1948
1946 // TODO(vandebo) srcFormXObject may contain alpha, but here we want it 1949 // TODO(vandebo) srcFormXObject may contain alpha, but here we want it
1947 // without alpha. 1950 // without alpha.
1948 if (xfermode == SkXfermode::kSrcATop_Mode) { 1951 if (xfermode == SkXfermode::kSrcATop_Mode) {
1949 // TODO(vandebo): In order to properly support SrcATop we have to track 1952 // TODO(vandebo): In order to properly support SrcATop we have to track
1950 // the shape of what's been drawn at all times. It's the intersection of 1953 // the shape of what's been drawn at all times. It's the intersection of
1951 // the non-transparent parts of the device and the outlines (shape) of 1954 // the non-transparent parts of the device and the outlines (shape) of
1952 // all images and devices drawn. 1955 // all images and devices drawn.
1953 drawFormXObjectWithMask(addXObjectResource(srcFormXObject.get()), dst, 1956 drawFormXObjectWithMask(addXObjectResource(srcFormXObject.get()), dst,
1954 &clipStack, clipRegion, 1957 &fExistingClipStack, fExistingClipRegion,
1955 SkXfermode::kSrcOver_Mode, true); 1958 SkXfermode::kSrcOver_Mode, true);
1956 } else { 1959 } else {
1957 SkAutoTUnref<SkPDFFormXObject> dstMaskStorage; 1960 SkAutoTUnref<SkPDFFormXObject> dstMaskStorage;
1958 SkPDFFormXObject* dstMask = srcFormXObject.get(); 1961 SkPDFFormXObject* dstMask = srcFormXObject.get();
1959 if (shape != NULL) { 1962 if (shape != NULL) {
1960 // Draw shape into a form-xobject. 1963 // Draw shape into a form-xobject.
1961 SkDraw d; 1964 SkDraw d;
1962 d.fMatrix = &identity; 1965 d.fMatrix = &identity;
1963 d.fClip = &clipRegion; 1966 d.fClip = &clipRegion;
1964 d.fClipStack = &clipStack; 1967 d.fClipStack = &clipStack;
1965 SkPaint filledPaint; 1968 SkPaint filledPaint;
1966 filledPaint.setColor(SK_ColorBLACK); 1969 filledPaint.setColor(SK_ColorBLACK);
1967 filledPaint.setStyle(SkPaint::kFill_Style); 1970 filledPaint.setStyle(SkPaint::kFill_Style);
1968 this->drawPath(d, *shape, filledPaint, NULL, true); 1971 this->drawPath(d, *shape, filledPaint, NULL, true);
1969 1972
1970 dstMaskStorage.reset(createFormXObjectFromDevice()); 1973 dstMaskStorage.reset(createFormXObjectFromDevice());
1971 dstMask = dstMaskStorage.get(); 1974 dstMask = dstMaskStorage.get();
1972 } 1975 }
1973 drawFormXObjectWithMask(addXObjectResource(dst), dstMask, &clipStack, 1976 drawFormXObjectWithMask(addXObjectResource(dst), dstMask,
1974 clipRegion, SkXfermode::kSrcOver_Mode, true); 1977 &fExistingClipStack, fExistingClipRegion,
1978 SkXfermode::kSrcOver_Mode, true);
1975 } 1979 }
1976 1980
1977 if (xfermode == SkXfermode::kClear_Mode) { 1981 if (xfermode == SkXfermode::kClear_Mode) {
1978 return; 1982 return;
1979 } else if (xfermode == SkXfermode::kSrc_Mode || 1983 } else if (xfermode == SkXfermode::kSrc_Mode ||
1980 xfermode == SkXfermode::kDstATop_Mode) { 1984 xfermode == SkXfermode::kDstATop_Mode) {
1981 ScopedContentEntry content(this, &clipStack, clipRegion, identity, 1985 ScopedContentEntry content(this, &fExistingClipStack,
1982 stockPaint); 1986 fExistingClipRegion, identity, stockPaint);
1983 if (content.entry()) { 1987 if (content.entry()) {
1984 SkPDFUtils::DrawFormXObject( 1988 SkPDFUtils::DrawFormXObject(
1985 this->addXObjectResource(srcFormXObject.get()), 1989 this->addXObjectResource(srcFormXObject.get()),
1986 &content.entry()->fContent); 1990 &content.entry()->fContent);
1987 } 1991 }
1988 if (xfermode == SkXfermode::kSrc_Mode) { 1992 if (xfermode == SkXfermode::kSrc_Mode) {
1989 return; 1993 return;
1990 } 1994 }
1991 } else if (xfermode == SkXfermode::kSrcATop_Mode) { 1995 } else if (xfermode == SkXfermode::kSrcATop_Mode) {
1992 ScopedContentEntry content(this, &clipStack, clipRegion, identity, 1996 ScopedContentEntry content(this, &fExistingClipStack,
1993 stockPaint); 1997 fExistingClipRegion, identity, stockPaint);
1994 if (content.entry()) { 1998 if (content.entry()) {
1995 SkPDFUtils::DrawFormXObject(this->addXObjectResource(dst), 1999 SkPDFUtils::DrawFormXObject(this->addXObjectResource(dst),
1996 &content.entry()->fContent); 2000 &content.entry()->fContent);
1997 } 2001 }
1998 } 2002 }
1999 2003
2000 SkASSERT(xfermode == SkXfermode::kSrcIn_Mode || 2004 SkASSERT(xfermode == SkXfermode::kSrcIn_Mode ||
2001 xfermode == SkXfermode::kDstIn_Mode || 2005 xfermode == SkXfermode::kDstIn_Mode ||
2002 xfermode == SkXfermode::kSrcOut_Mode || 2006 xfermode == SkXfermode::kSrcOut_Mode ||
2003 xfermode == SkXfermode::kDstOut_Mode || 2007 xfermode == SkXfermode::kDstOut_Mode ||
2004 xfermode == SkXfermode::kSrcATop_Mode || 2008 xfermode == SkXfermode::kSrcATop_Mode ||
2005 xfermode == SkXfermode::kDstATop_Mode || 2009 xfermode == SkXfermode::kDstATop_Mode ||
2006 xfermode == SkXfermode::kModulate_Mode); 2010 xfermode == SkXfermode::kModulate_Mode);
2007 2011
2008 ScopedContentEntry inShapeContentEntry(this, &fExistingClipStack,
vandebo (ex-Chrome) 2013/12/17 23:11:03 This was dead code - inShapeContentEntry is not us
2009 fExistingClipRegion, identity,
2010 stockPaint);
2011 if (!inShapeContentEntry.entry()) {
vandebo (ex-Chrome) 2013/12/17 23:11:03 This can't be true because fExistingClipRegion is
2012 return;
2013 }
2014
2015 if (xfermode == SkXfermode::kSrcIn_Mode || 2012 if (xfermode == SkXfermode::kSrcIn_Mode ||
2016 xfermode == SkXfermode::kSrcOut_Mode || 2013 xfermode == SkXfermode::kSrcOut_Mode ||
2017 xfermode == SkXfermode::kSrcATop_Mode) { 2014 xfermode == SkXfermode::kSrcATop_Mode) {
2018 drawFormXObjectWithMask(addXObjectResource(srcFormXObject.get()), dst, 2015 drawFormXObjectWithMask(addXObjectResource(srcFormXObject.get()), dst,
2019 &clipStack, clipRegion, 2016 &fExistingClipStack, fExistingClipRegion,
2020 SkXfermode::kSrcOver_Mode, 2017 SkXfermode::kSrcOver_Mode,
2021 xfermode == SkXfermode::kSrcOut_Mode); 2018 xfermode == SkXfermode::kSrcOut_Mode);
2022 } else { 2019 } else {
2023 SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode; 2020 SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode;
2024 if (xfermode == SkXfermode::kModulate_Mode) { 2021 if (xfermode == SkXfermode::kModulate_Mode) {
2025 drawFormXObjectWithMask(addXObjectResource(srcFormXObject.get()), 2022 drawFormXObjectWithMask(addXObjectResource(srcFormXObject.get()),
2026 dst, &clipStack, clipRegion, 2023 dst, &fExistingClipStack,
2024 fExistingClipRegion,
2027 SkXfermode::kSrcOver_Mode, false); 2025 SkXfermode::kSrcOver_Mode, false);
2028 mode = SkXfermode::kMultiply_Mode; 2026 mode = SkXfermode::kMultiply_Mode;
2029 } 2027 }
2030 drawFormXObjectWithMask(addXObjectResource(dst), srcFormXObject.get(), 2028 drawFormXObjectWithMask(addXObjectResource(dst), srcFormXObject.get(),
2031 &clipStack, clipRegion, mode, 2029 &fExistingClipStack, fExistingClipRegion, mode,
2032 xfermode == SkXfermode::kDstOut_Mode); 2030 xfermode == SkXfermode::kDstOut_Mode);
2033 } 2031 }
2034 } 2032 }
2035 2033
2036 bool SkPDFDevice::isContentEmpty() { 2034 bool SkPDFDevice::isContentEmpty() {
2037 ContentEntry* contentEntries = getContentEntries()->get(); 2035 ContentEntry* contentEntries = getContentEntries()->get();
2038 if (!contentEntries || contentEntries->fContent.getOffset() == 0) { 2036 if (!contentEntries || contentEntries->fContent.getOffset() == 0) {
2039 SkASSERT(!contentEntries || !contentEntries->fNext.get()); 2037 SkASSERT(!contentEntries || !contentEntries->fNext.get());
2040 return true; 2038 return true;
2041 } 2039 }
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
2330 } 2328 }
2331 2329
2332 bool SkPDFDevice::onReadPixels(const SkBitmap& bitmap, int x, int y, 2330 bool SkPDFDevice::onReadPixels(const SkBitmap& bitmap, int x, int y,
2333 SkCanvas::Config8888) { 2331 SkCanvas::Config8888) {
2334 return false; 2332 return false;
2335 } 2333 }
2336 2334
2337 bool SkPDFDevice::allowImageFilter(SkImageFilter*) { 2335 bool SkPDFDevice::allowImageFilter(SkImageFilter*) {
2338 return false; 2336 return false;
2339 } 2337 }
OLDNEW
« gm/xfermodes.cpp ('K') | « gm/xfermodes.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698