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

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

Issue 92453002: [PDF] Fixes the cases where SkPDFDevice::finishContentEntry is called with empty content. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Rebase 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
« no previous file with comments | « 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 1857 matching lines...) Expand 10 before | Expand all | Expand 10 after
1868 entry->fNext.reset(contentEntries->detach()); 1868 entry->fNext.reset(contentEntries->detach());
1869 contentEntries->reset(entry); 1869 contentEntries->reset(entry);
1870 } else { 1870 } else {
1871 lastContentEntry->fNext.reset(entry); 1871 lastContentEntry->fNext.reset(entry);
1872 setLastContentEntry(entry); 1872 setLastContentEntry(entry);
1873 } 1873 }
1874 newEntry.detach(); 1874 newEntry.detach();
1875 return entry; 1875 return entry;
1876 } 1876 }
1877 1877
1878 void SkPDFDevice::finishContentEntry(const SkXfermode::Mode xfermode, 1878 void SkPDFDevice::finishContentEntry(SkXfermode::Mode xfermode,
1879 SkPDFFormXObject* dst, 1879 SkPDFFormXObject* dst,
1880 SkPath* shape) { 1880 SkPath* shape) {
1881 if (xfermode != SkXfermode::kClear_Mode && 1881 if (xfermode != SkXfermode::kClear_Mode &&
1882 xfermode != SkXfermode::kSrc_Mode && 1882 xfermode != SkXfermode::kSrc_Mode &&
1883 xfermode != SkXfermode::kDstOver_Mode &&
1883 xfermode != SkXfermode::kSrcIn_Mode && 1884 xfermode != SkXfermode::kSrcIn_Mode &&
1884 xfermode != SkXfermode::kDstIn_Mode && 1885 xfermode != SkXfermode::kDstIn_Mode &&
1885 xfermode != SkXfermode::kSrcOut_Mode && 1886 xfermode != SkXfermode::kSrcOut_Mode &&
1886 xfermode != SkXfermode::kDstOut_Mode && 1887 xfermode != SkXfermode::kDstOut_Mode &&
1887 xfermode != SkXfermode::kSrcATop_Mode && 1888 xfermode != SkXfermode::kSrcATop_Mode &&
1888 xfermode != SkXfermode::kDstATop_Mode && 1889 xfermode != SkXfermode::kDstATop_Mode &&
1889 xfermode != SkXfermode::kModulate_Mode) { 1890 xfermode != SkXfermode::kModulate_Mode) {
1890 SkASSERT(!dst); 1891 SkASSERT(!dst);
1891 return; 1892 return;
1892 } 1893 }
1894 if (xfermode == SkXfermode::kDstOver_Mode) {
1895 SkASSERT(!dst);
1896 ContentEntry* firstContentEntry = getContentEntries()->get();
1897 if (firstContentEntry->fContent.getOffset() == 0) {
1898 // For DstOver, an empty content entry was inserted before the rest
1899 // of the content entries. If nothing was drawn, it needs to be
1900 // removed.
1901 SkAutoTDelete<ContentEntry>* contentEntries = getContentEntries();
1902 contentEntries->reset(firstContentEntry->fNext.detach());
1903 }
1904 return;
1905 }
1893 if (!dst) { 1906 if (!dst) {
1894 SkASSERT(xfermode == SkXfermode::kSrc_Mode || 1907 SkASSERT(xfermode == SkXfermode::kSrc_Mode ||
1895 xfermode == SkXfermode::kSrcOut_Mode); 1908 xfermode == SkXfermode::kSrcOut_Mode);
1896 return; 1909 return;
1897 } 1910 }
1898 1911
1899 ContentEntry* contentEntries = getContentEntries()->get(); 1912 ContentEntry* contentEntries = getContentEntries()->get();
1900 SkASSERT(dst); 1913 SkASSERT(dst);
1901 SkASSERT(!contentEntries->fNext.get()); 1914 SkASSERT(!contentEntries->fNext.get());
1902 // We have to make a copy of these here because changing the current 1915 // We have to make a copy of these here because changing the current
1903 // content into a form-xobject will destroy them. 1916 // content into a form-xobject will destroy them.
1904 SkClipStack clipStack = contentEntries->fState.fClipStack; 1917 SkClipStack clipStack = contentEntries->fState.fClipStack;
1905 SkRegion clipRegion = contentEntries->fState.fClipRegion; 1918 SkRegion clipRegion = contentEntries->fState.fClipRegion;
1906 1919
1920 SkMatrix identity;
1921 identity.reset();
1922 SkPaint stockPaint;
1923
1907 SkAutoTUnref<SkPDFFormXObject> srcFormXObject; 1924 SkAutoTUnref<SkPDFFormXObject> srcFormXObject;
1908 if (isContentEmpty()) { 1925 if (isContentEmpty()) {
1909 SkASSERT(xfermode == SkXfermode::kClear_Mode); 1926 // 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.
1928 // If there is shape, then an empty source with Src, SrcIn, SrcOut,
1929 // DstIn, DstAtop or Modulate reduces to Clear and DstOut or SrcAtop
1930 // reduces to Dst.
1931 if (shape == NULL || xfermode == SkXfermode::kDstOut_Mode ||
1932 xfermode == SkXfermode::kSrcATop_Mode) {
1933 ScopedContentEntry content(this, &clipStack, clipRegion, identity,
1934 stockPaint);
1935 SkPDFUtils::DrawFormXObject(this->addXObjectResource(dst),
1936 &content.entry()->fContent);
1937 return;
1938 } else {
1939 xfermode = SkXfermode::kClear_Mode;
1940 }
1910 } else { 1941 } else {
1911 SkASSERT(!fContentEntries->fNext.get()); 1942 SkASSERT(!fContentEntries->fNext.get());
1912 srcFormXObject.reset(createFormXObjectFromDevice()); 1943 srcFormXObject.reset(createFormXObjectFromDevice());
1913 } 1944 }
1914 1945
1915 SkMatrix identity;
1916 identity.reset();
1917
1918 // TODO(vandebo) srcFormXObject may contain alpha, but here we want it 1946 // TODO(vandebo) srcFormXObject may contain alpha, but here we want it
1919 // without alpha. 1947 // without alpha.
1920 if (xfermode == SkXfermode::kSrcATop_Mode) { 1948 if (xfermode == SkXfermode::kSrcATop_Mode) {
1921 // TODO(vandebo): In order to properly support SrcATop we have to track 1949 // TODO(vandebo): In order to properly support SrcATop we have to track
1922 // the shape of what's been drawn at all times. It's the intersection of 1950 // the shape of what's been drawn at all times. It's the intersection of
1923 // the non-transparent parts of the device and the outlines (shape) of 1951 // the non-transparent parts of the device and the outlines (shape) of
1924 // all images and devices drawn. 1952 // all images and devices drawn.
1925 drawFormXObjectWithMask(addXObjectResource(srcFormXObject.get()), dst, 1953 drawFormXObjectWithMask(addXObjectResource(srcFormXObject.get()), dst,
1926 &clipStack, clipRegion, 1954 &clipStack, clipRegion,
1927 SkXfermode::kSrcOver_Mode, true); 1955 SkXfermode::kSrcOver_Mode, true);
(...skipping 11 matching lines...) Expand all
1939 filledPaint.setStyle(SkPaint::kFill_Style); 1967 filledPaint.setStyle(SkPaint::kFill_Style);
1940 this->drawPath(d, *shape, filledPaint, NULL, true); 1968 this->drawPath(d, *shape, filledPaint, NULL, true);
1941 1969
1942 dstMaskStorage.reset(createFormXObjectFromDevice()); 1970 dstMaskStorage.reset(createFormXObjectFromDevice());
1943 dstMask = dstMaskStorage.get(); 1971 dstMask = dstMaskStorage.get();
1944 } 1972 }
1945 drawFormXObjectWithMask(addXObjectResource(dst), dstMask, &clipStack, 1973 drawFormXObjectWithMask(addXObjectResource(dst), dstMask, &clipStack,
1946 clipRegion, SkXfermode::kSrcOver_Mode, true); 1974 clipRegion, SkXfermode::kSrcOver_Mode, true);
1947 } 1975 }
1948 1976
1949 SkPaint stockPaint; 1977 if (xfermode == SkXfermode::kClear_Mode) {
1950
1951 if (xfermode == SkXfermode::kSrcATop_Mode) {
1952 ScopedContentEntry content(this, &clipStack, clipRegion, identity,
1953 stockPaint);
1954 if (content.entry()) {
1955 SkPDFUtils::DrawFormXObject(this->addXObjectResource(dst),
1956 &content.entry()->fContent);
1957 }
1958 } else if (xfermode == SkXfermode::kClear_Mode || !srcFormXObject.get()) {
1959 return; 1978 return;
1960 } else if (xfermode == SkXfermode::kSrc_Mode || 1979 } else if (xfermode == SkXfermode::kSrc_Mode ||
1961 xfermode == SkXfermode::kDstATop_Mode) { 1980 xfermode == SkXfermode::kDstATop_Mode) {
1962 ScopedContentEntry content(this, &clipStack, clipRegion, identity, 1981 ScopedContentEntry content(this, &clipStack, clipRegion, identity,
1963 stockPaint); 1982 stockPaint);
1964 if (content.entry()) { 1983 if (content.entry()) {
1965 SkPDFUtils::DrawFormXObject( 1984 SkPDFUtils::DrawFormXObject(
1966 this->addXObjectResource(srcFormXObject.get()), 1985 this->addXObjectResource(srcFormXObject.get()),
1967 &content.entry()->fContent); 1986 &content.entry()->fContent);
1968 } 1987 }
1969 if (xfermode == SkXfermode::kSrc_Mode) { 1988 if (xfermode == SkXfermode::kSrc_Mode) {
1970 return; 1989 return;
1971 } 1990 }
1991 } else if (xfermode == SkXfermode::kSrcATop_Mode) {
1992 ScopedContentEntry content(this, &clipStack, clipRegion, identity,
1993 stockPaint);
1994 if (content.entry()) {
1995 SkPDFUtils::DrawFormXObject(this->addXObjectResource(dst),
1996 &content.entry()->fContent);
1997 }
1972 } 1998 }
1973 1999
1974 SkASSERT(xfermode == SkXfermode::kSrcIn_Mode || 2000 SkASSERT(xfermode == SkXfermode::kSrcIn_Mode ||
1975 xfermode == SkXfermode::kDstIn_Mode || 2001 xfermode == SkXfermode::kDstIn_Mode ||
1976 xfermode == SkXfermode::kSrcOut_Mode || 2002 xfermode == SkXfermode::kSrcOut_Mode ||
1977 xfermode == SkXfermode::kDstOut_Mode || 2003 xfermode == SkXfermode::kDstOut_Mode ||
1978 xfermode == SkXfermode::kSrcATop_Mode || 2004 xfermode == SkXfermode::kSrcATop_Mode ||
1979 xfermode == SkXfermode::kDstATop_Mode || 2005 xfermode == SkXfermode::kDstATop_Mode ||
1980 xfermode == SkXfermode::kModulate_Mode); 2006 xfermode == SkXfermode::kModulate_Mode);
1981 2007
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
2304 } 2330 }
2305 2331
2306 bool SkPDFDevice::onReadPixels(const SkBitmap& bitmap, int x, int y, 2332 bool SkPDFDevice::onReadPixels(const SkBitmap& bitmap, int x, int y,
2307 SkCanvas::Config8888) { 2333 SkCanvas::Config8888) {
2308 return false; 2334 return false;
2309 } 2335 }
2310 2336
2311 bool SkPDFDevice::allowImageFilter(SkImageFilter*) { 2337 bool SkPDFDevice::allowImageFilter(SkImageFilter*) {
2312 return false; 2338 return false;
2313 } 2339 }
OLDNEW
« no previous file with comments | « gm/xfermodes.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698