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

Side by Side Diff: Source/core/html/canvas/CanvasRenderingContext2D.cpp

Issue 104023007: Refactoring ImageBuffer to decouple it from Canvas2DLayerBridge (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: mac+win build fix 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies)
4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 4 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> 6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org>
7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
8 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. 8 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved.
9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
10 * 10 *
(...skipping 1850 matching lines...) Expand 10 before | Expand all | Expand 10 after
1861 1861
1862 IntSize size = expandedIntSize(logicalSize); 1862 IntSize size = expandedIntSize(logicalSize);
1863 if (size.width() < 1) 1863 if (size.width() < 1)
1864 size.setWidth(1); 1864 size.setWidth(1);
1865 if (size.height() < 1) 1865 if (size.height() < 1)
1866 size.setHeight(1); 1866 size.setHeight(1);
1867 1867
1868 return createEmptyImageData(size); 1868 return createEmptyImageData(size);
1869 } 1869 }
1870 1870
1871 PassRefPtr<ImageData> CanvasRenderingContext2D::webkitGetImageDataHD(float sx, f loat sy, float sw, float sh, ExceptionState& exceptionState) const
1872 {
1873 return getImageData(sx, sy, sw, sh, exceptionState);
1874 }
1875
1871 PassRefPtr<ImageData> CanvasRenderingContext2D::getImageData(float sx, float sy, float sw, float sh, ExceptionState& exceptionState) const 1876 PassRefPtr<ImageData> CanvasRenderingContext2D::getImageData(float sx, float sy, float sw, float sh, ExceptionState& exceptionState) const
1872 { 1877 {
1873 return getImageData(ImageBuffer::LogicalCoordinateSystem, sx, sy, sw, sh, ex ceptionState);
1874 }
1875
1876 PassRefPtr<ImageData> CanvasRenderingContext2D::webkitGetImageDataHD(float sx, f loat sy, float sw, float sh, ExceptionState& exceptionState) const
1877 {
1878 return getImageData(ImageBuffer::BackingStoreCoordinateSystem, sx, sy, sw, s h, exceptionState);
1879 }
1880
1881 PassRefPtr<ImageData> CanvasRenderingContext2D::getImageData(ImageBuffer::Coordi nateSystem coordinateSystem, float sx, float sy, float sw, float sh, ExceptionSt ate& exceptionState) const
1882 {
1883 if (!canvas()->originClean()) { 1878 if (!canvas()->originClean()) {
1884 exceptionState.throwSecurityError("The canvas has been tainted by cross- origin data."); 1879 exceptionState.throwSecurityError("The canvas has been tainted by cross- origin data.");
1885 return 0; 1880 return 0;
1886 } 1881 }
1887 1882
1888 if (!sw || !sh) { 1883 if (!sw || !sh) {
1889 exceptionState.throwUninformativeAndGenericDOMException(IndexSizeError); 1884 exceptionState.throwUninformativeAndGenericDOMException(IndexSizeError);
1890 return 0; 1885 return 0;
1891 } 1886 }
1892 if (!std::isfinite(sx) || !std::isfinite(sy) || !std::isfinite(sw) || !std:: isfinite(sh)) { 1887 if (!std::isfinite(sx) || !std::isfinite(sy) || !std::isfinite(sw) || !std:: isfinite(sh)) {
(...skipping 16 matching lines...) Expand all
1909 if (logicalRect.height() < 1) 1904 if (logicalRect.height() < 1)
1910 logicalRect.setHeight(1); 1905 logicalRect.setHeight(1);
1911 if (!logicalRect.isExpressibleAsIntRect()) 1906 if (!logicalRect.isExpressibleAsIntRect())
1912 return 0; 1907 return 0;
1913 1908
1914 IntRect imageDataRect = enclosingIntRect(logicalRect); 1909 IntRect imageDataRect = enclosingIntRect(logicalRect);
1915 ImageBuffer* buffer = canvas()->buffer(); 1910 ImageBuffer* buffer = canvas()->buffer();
1916 if (!buffer) 1911 if (!buffer)
1917 return createEmptyImageData(imageDataRect.size()); 1912 return createEmptyImageData(imageDataRect.size());
1918 1913
1919 RefPtr<Uint8ClampedArray> byteArray = buffer->getUnmultipliedImageData(image DataRect, coordinateSystem); 1914 RefPtr<Uint8ClampedArray> byteArray = buffer->getUnmultipliedImageData(image DataRect);
1920 if (!byteArray) 1915 if (!byteArray)
1921 return 0; 1916 return 0;
1922 1917
1923 return ImageData::create(imageDataRect.size(), byteArray.release()); 1918 return ImageData::create(imageDataRect.size(), byteArray.release());
1924 } 1919 }
1925 1920
1926 void CanvasRenderingContext2D::putImageData(ImageData* data, float dx, float dy, ExceptionState& exceptionState) 1921 void CanvasRenderingContext2D::putImageData(ImageData* data, float dx, float dy, ExceptionState& exceptionState)
1927 { 1922 {
1928 if (!data) { 1923 if (!data) {
1929 exceptionState.throwUninformativeAndGenericDOMException(TypeMismatchErro r); 1924 exceptionState.throwUninformativeAndGenericDOMException(TypeMismatchErro r);
1930 return; 1925 return;
1931 } 1926 }
1932 putImageData(data, dx, dy, 0, 0, data->width(), data->height(), exceptionSta te); 1927 putImageData(data, dx, dy, 0, 0, data->width(), data->height(), exceptionSta te);
1933 } 1928 }
1934 1929
1935 void CanvasRenderingContext2D::webkitPutImageDataHD(ImageData* data, float dx, f loat dy, ExceptionState& exceptionState)
1936 {
1937 if (!data) {
1938 exceptionState.throwUninformativeAndGenericDOMException(TypeMismatchErro r);
1939 return;
1940 }
1941 webkitPutImageDataHD(data, dx, dy, 0, 0, data->width(), data->height(), exce ptionState);
1942 }
1943
1944 void CanvasRenderingContext2D::putImageData(ImageData* data, float dx, float dy, float dirtyX, float dirtyY, 1930 void CanvasRenderingContext2D::putImageData(ImageData* data, float dx, float dy, float dirtyX, float dirtyY,
1945 float dirtyWidth, float dirtyHeight, ExceptionState& exceptionState) 1931 float dirtyWidth, float dirtyHeight, ExceptionState& exceptionState)
1946 { 1932 {
1947 putImageData(data, ImageBuffer::LogicalCoordinateSystem, dx, dy, dirtyX, dir tyY, dirtyWidth, dirtyHeight, exceptionState);
1948 }
1949
1950 void CanvasRenderingContext2D::webkitPutImageDataHD(ImageData* data, float dx, f loat dy, float dirtyX, float dirtyY, float dirtyWidth, float dirtyHeight, Except ionState& exceptionState)
1951 {
1952 putImageData(data, ImageBuffer::BackingStoreCoordinateSystem, dx, dy, dirtyX , dirtyY, dirtyWidth, dirtyHeight, exceptionState);
1953 }
1954
1955 void CanvasRenderingContext2D::putImageData(ImageData* data, ImageBuffer::Coordi nateSystem coordinateSystem, float dx, float dy, float dirtyX, float dirtyY,
1956 float dirtyWidth, float dirtyHeight, ExceptionState& exceptionState)
1957 {
1958 if (!data) { 1933 if (!data) {
1959 exceptionState.throwUninformativeAndGenericDOMException(TypeMismatchErro r); 1934 exceptionState.throwUninformativeAndGenericDOMException(TypeMismatchErro r);
1960 return; 1935 return;
1961 } 1936 }
1962 if (!std::isfinite(dx) || !std::isfinite(dy) || !std::isfinite(dirtyX) || !s td::isfinite(dirtyY) || !std::isfinite(dirtyWidth) || !std::isfinite(dirtyHeight )) { 1937 if (!std::isfinite(dx) || !std::isfinite(dy) || !std::isfinite(dirtyX) || !s td::isfinite(dirtyY) || !std::isfinite(dirtyWidth) || !std::isfinite(dirtyHeight )) {
1963 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro r); 1938 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro r);
1964 return; 1939 return;
1965 } 1940 }
1966 1941
1967 ImageBuffer* buffer = canvas()->buffer(); 1942 ImageBuffer* buffer = canvas()->buffer();
1968 if (!buffer) 1943 if (!buffer)
1969 return; 1944 return;
1970 1945
1971 if (dirtyWidth < 0) { 1946 if (dirtyWidth < 0) {
1972 dirtyX += dirtyWidth; 1947 dirtyX += dirtyWidth;
1973 dirtyWidth = -dirtyWidth; 1948 dirtyWidth = -dirtyWidth;
1974 } 1949 }
1975 1950
1976 if (dirtyHeight < 0) { 1951 if (dirtyHeight < 0) {
1977 dirtyY += dirtyHeight; 1952 dirtyY += dirtyHeight;
1978 dirtyHeight = -dirtyHeight; 1953 dirtyHeight = -dirtyHeight;
1979 } 1954 }
1980 1955
1981 FloatRect clipRect(dirtyX, dirtyY, dirtyWidth, dirtyHeight); 1956 FloatRect clipRect(dirtyX, dirtyY, dirtyWidth, dirtyHeight);
1982 clipRect.intersect(IntRect(0, 0, data->width(), data->height())); 1957 clipRect.intersect(IntRect(0, 0, data->width(), data->height()));
1983 IntSize destOffset(static_cast<int>(dx), static_cast<int>(dy)); 1958 IntSize destOffset(static_cast<int>(dx), static_cast<int>(dy));
1984 IntRect destRect = enclosingIntRect(clipRect); 1959 IntRect destRect = enclosingIntRect(clipRect);
1985 destRect.move(destOffset); 1960 destRect.move(destOffset);
1986 destRect.intersect(IntRect(IntPoint(), coordinateSystem == ImageBuffer::Logi calCoordinateSystem ? buffer->logicalSize() : buffer->internalSize())); 1961 destRect.intersect(IntRect(IntPoint(), buffer->size()));
1987 if (destRect.isEmpty()) 1962 if (destRect.isEmpty())
1988 return; 1963 return;
1989 IntRect sourceRect(destRect); 1964 IntRect sourceRect(destRect);
1990 sourceRect.move(-destOffset); 1965 sourceRect.move(-destOffset);
1991 1966
1992 buffer->putByteArray(Unmultiplied, data->data(), IntSize(data->width(), data ->height()), sourceRect, IntPoint(destOffset), coordinateSystem); 1967 buffer->putByteArray(Unmultiplied, data->data(), IntSize(data->width(), data ->height()), sourceRect, IntPoint(destOffset));
1993 1968
1994 if (coordinateSystem == ImageBuffer::BackingStoreCoordinateSystem) {
1995 FloatRect dirtyRect = destRect;
1996 dirtyRect.scale(1 / canvas()->deviceScaleFactor());
1997 destRect = enclosingIntRect(dirtyRect);
1998 }
1999 didDraw(destRect); 1969 didDraw(destRect);
2000 } 1970 }
2001 1971
2002 String CanvasRenderingContext2D::font() const 1972 String CanvasRenderingContext2D::font() const
2003 { 1973 {
2004 if (!state().m_realizedFont) 1974 if (!state().m_realizedFont)
2005 return defaultFont; 1975 return defaultFont;
2006 1976
2007 StringBuilder serializedFont; 1977 StringBuilder serializedFont;
2008 const FontDescription& fontDescription = state().m_font.fontDescription(); 1978 const FontDescription& fontDescription = state().m_font.fontDescription();
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
2426 const int focusRingWidth = 5; 2396 const int focusRingWidth = 5;
2427 const int focusRingOutline = 0; 2397 const int focusRingOutline = 0;
2428 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); 2398 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor);
2429 2399
2430 c->restore(); 2400 c->restore();
2431 2401
2432 didDraw(dirtyRect); 2402 didDraw(dirtyRect);
2433 } 2403 }
2434 2404
2435 } // namespace WebCore 2405 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698