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

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

Issue 944643002: PDF: Now threadsafe! (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: TODO=DONE Created 5 years, 10 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
« no previous file with comments | « src/pdf/SkPDFCanon.cpp ('k') | src/pdf/SkPDFFont.h » ('j') | 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 719 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 730
731 void SkPDFDevice::init() { 731 void SkPDFDevice::init() {
732 fAnnotations = NULL; 732 fAnnotations = NULL;
733 fResourceDict = NULL; 733 fResourceDict = NULL;
734 fContentEntries.free(); 734 fContentEntries.free();
735 fLastContentEntry = NULL; 735 fLastContentEntry = NULL;
736 fMarginContentEntries.free(); 736 fMarginContentEntries.free();
737 fLastMarginContentEntry = NULL; 737 fLastMarginContentEntry = NULL;
738 fDrawingArea = kContent_DrawingArea; 738 fDrawingArea = kContent_DrawingArea;
739 if (fFontGlyphUsage.get() == NULL) { 739 if (fFontGlyphUsage.get() == NULL) {
740 fFontGlyphUsage.reset(new SkPDFGlyphSetMap()); 740 fFontGlyphUsage.reset(SkNEW(SkPDFGlyphSetMap));
741 } 741 }
742 } 742 }
743 743
744 void SkPDFDevice::cleanUp(bool clearFontUsage) { 744 void SkPDFDevice::cleanUp(bool clearFontUsage) {
745 fGraphicStateResources.unrefAll(); 745 fGraphicStateResources.unrefAll();
746 fXObjectResources.unrefAll(); 746 fXObjectResources.unrefAll();
747 fFontResources.unrefAll(); 747 fFontResources.unrefAll();
748 fShaderResources.unrefAll(); 748 fShaderResources.unrefAll();
749 SkSafeUnref(fAnnotations); 749 SkSafeUnref(fAnnotations);
750 SkSafeUnref(fResourceDict); 750 SkSafeUnref(fResourceDict);
(...skipping 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1889 // a pattern the size of the current clip. 1889 // a pattern the size of the current clip.
1890 SkIRect bounds = clipRegion.getBounds(); 1890 SkIRect bounds = clipRegion.getBounds();
1891 1891
1892 // We need to apply the initial transform to bounds in order to get 1892 // We need to apply the initial transform to bounds in order to get
1893 // bounds in a consistent coordinate system. 1893 // bounds in a consistent coordinate system.
1894 SkRect boundsTemp; 1894 SkRect boundsTemp;
1895 boundsTemp.set(bounds); 1895 boundsTemp.set(bounds);
1896 fInitialTransform.mapRect(&boundsTemp); 1896 fInitialTransform.mapRect(&boundsTemp);
1897 boundsTemp.roundOut(&bounds); 1897 boundsTemp.roundOut(&bounds);
1898 1898
1899 pdfShader.reset(SkPDFShader::GetPDFShader(*shader, transform, bounds, 1899 SkScalar rasterScale =
1900 SkIntToScalar(fRasterDpi) / DPI_FOR_RASTER_SCALE_ONE)); 1900 SkIntToScalar(fRasterDpi) / DPI_FOR_RASTER_SCALE_ONE;
1901 pdfShader.reset(SkPDFShader::GetPDFShader(
1902 fCanon, fRasterDpi, *shader, transform, bounds, rasterScale));
1901 1903
1902 if (pdfShader.get()) { 1904 if (pdfShader.get()) {
1903 // pdfShader has been canonicalized so we can directly compare 1905 // pdfShader has been canonicalized so we can directly compare
1904 // pointers. 1906 // pointers.
1905 int resourceIndex = fShaderResources.find(pdfShader.get()); 1907 int resourceIndex = fShaderResources.find(pdfShader.get());
1906 if (resourceIndex < 0) { 1908 if (resourceIndex < 0) {
1907 resourceIndex = fShaderResources.count(); 1909 resourceIndex = fShaderResources.count();
1908 fShaderResources.push(pdfShader.get()); 1910 fShaderResources.push(pdfShader.get());
1909 pdfShader.get()->ref(); 1911 pdfShader.get()->ref();
1910 } 1912 }
(...skipping 10 matching lines...) Expand all
1921 SkShader::kColor_GradientType) { 1923 SkShader::kColor_GradientType) {
1922 entry->fColor = SkColorSetA(gradientColor, 0xFF); 1924 entry->fColor = SkColorSetA(gradientColor, 0xFF);
1923 color = gradientColor; 1925 color = gradientColor;
1924 } 1926 }
1925 } 1927 }
1926 } 1928 }
1927 1929
1928 SkAutoTUnref<SkPDFGraphicState> newGraphicState; 1930 SkAutoTUnref<SkPDFGraphicState> newGraphicState;
1929 if (color == paint.getColor()) { 1931 if (color == paint.getColor()) {
1930 newGraphicState.reset( 1932 newGraphicState.reset(
1931 SkPDFGraphicState::GetGraphicStateForPaint(paint)); 1933 SkPDFGraphicState::GetGraphicStateForPaint(fCanon, paint));
1932 } else { 1934 } else {
1933 SkPaint newPaint = paint; 1935 SkPaint newPaint = paint;
1934 newPaint.setColor(color); 1936 newPaint.setColor(color);
1935 newGraphicState.reset( 1937 newGraphicState.reset(
1936 SkPDFGraphicState::GetGraphicStateForPaint(newPaint)); 1938 SkPDFGraphicState::GetGraphicStateForPaint(fCanon, newPaint));
1937 } 1939 }
1938 int resourceIndex = addGraphicStateResource(newGraphicState.get()); 1940 int resourceIndex = addGraphicStateResource(newGraphicState.get());
1939 entry->fGraphicStateIndex = resourceIndex; 1941 entry->fGraphicStateIndex = resourceIndex;
1940 1942
1941 if (hasText) { 1943 if (hasText) {
1942 entry->fTextScaleX = paint.getTextScaleX(); 1944 entry->fTextScaleX = paint.getTextScaleX();
1943 entry->fTextFill = paint.getStyle(); 1945 entry->fTextFill = paint.getStyle();
1944 } else { 1946 } else {
1945 entry->fTextScaleX = 0; 1947 entry->fTextScaleX = 0;
1946 } 1948 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1982 SkPDFResourceDict::kFont_ResourceType, 1984 SkPDFResourceDict::kFont_ResourceType,
1983 fontIndex).c_str()); 1985 fontIndex).c_str());
1984 contentEntry->fContent.writeText(" "); 1986 contentEntry->fContent.writeText(" ");
1985 SkPDFScalar::Append(paint.getTextSize(), &contentEntry->fContent); 1987 SkPDFScalar::Append(paint.getTextSize(), &contentEntry->fContent);
1986 contentEntry->fContent.writeText(" Tf\n"); 1988 contentEntry->fContent.writeText(" Tf\n");
1987 contentEntry->fState.fFont = fFontResources[fontIndex]; 1989 contentEntry->fState.fFont = fFontResources[fontIndex];
1988 } 1990 }
1989 } 1991 }
1990 1992
1991 int SkPDFDevice::getFontResourceIndex(SkTypeface* typeface, uint16_t glyphID) { 1993 int SkPDFDevice::getFontResourceIndex(SkTypeface* typeface, uint16_t glyphID) {
1992 SkAutoTUnref<SkPDFFont> newFont(SkPDFFont::GetFontResource(typeface, 1994 SkAutoTUnref<SkPDFFont> newFont(
1993 glyphID)); 1995 SkPDFFont::GetFontResource(fCanon, typeface, glyphID));
1994 int resourceIndex = fFontResources.find(newFont.get()); 1996 int resourceIndex = fFontResources.find(newFont.get());
1995 if (resourceIndex < 0) { 1997 if (resourceIndex < 0) {
1996 resourceIndex = fFontResources.count(); 1998 resourceIndex = fFontResources.count();
1997 fFontResources.push(newFont.get()); 1999 fFontResources.push(newFont.get());
1998 newFont.get()->ref(); 2000 newFont.get()->ref();
1999 } 2001 }
2000 return resourceIndex; 2002 return resourceIndex;
2001 } 2003 }
2002 2004
2003 void SkPDFDevice::internalDrawBitmap(const SkMatrix& origMatrix, 2005 void SkPDFDevice::internalDrawBitmap(const SkMatrix& origMatrix,
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
2126 shape.addRect(SkRect::MakeWH(SkIntToScalar(subset.width()), 2128 shape.addRect(SkRect::MakeWH(SkIntToScalar(subset.width()),
2127 SkIntToScalar( subset.height()))); 2129 SkIntToScalar( subset.height())));
2128 shape.transform(matrix); 2130 shape.transform(matrix);
2129 content.setShape(shape); 2131 content.setShape(shape);
2130 } 2132 }
2131 if (!content.needSource()) { 2133 if (!content.needSource()) {
2132 return; 2134 return;
2133 } 2135 }
2134 2136
2135 SkAutoTUnref<SkPDFObject> image( 2137 SkAutoTUnref<SkPDFObject> image(
2136 SkPDFCreateImageObject(*bitmap, subset)); 2138 SkPDFCreateImageObject(fCanon, *bitmap, subset));
2137 if (!image) { 2139 if (!image) {
2138 return; 2140 return;
2139 } 2141 }
2140 2142
2141 SkPDFUtils::DrawFormXObject(this->addXObjectResource(image.get()), 2143 SkPDFUtils::DrawFormXObject(this->addXObjectResource(image.get()),
2142 &content.entry()->fContent); 2144 &content.entry()->fContent);
2143 } 2145 }
2144
OLDNEW
« no previous file with comments | « src/pdf/SkPDFCanon.cpp ('k') | src/pdf/SkPDFFont.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698