| OLD | NEW |
| 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 "SkGpuDevice.h" | 8 #include "SkGpuDevice.h" |
| 9 | 9 |
| 10 #include "GrContext.h" | 10 #include "GrContext.h" |
| (...skipping 1725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1736 // must be pushed upstack. | 1736 // must be pushed upstack. |
| 1737 AutoBitmapTexture abt(fContext, src, NULL, &texture); | 1737 AutoBitmapTexture abt(fContext, src, NULL, &texture); |
| 1738 if (!texture) { | 1738 if (!texture) { |
| 1739 return false; | 1739 return false; |
| 1740 } | 1740 } |
| 1741 | 1741 |
| 1742 return this->filterTexture(fContext, texture, src.width(), src.height(), | 1742 return this->filterTexture(fContext, texture, src.width(), src.height(), |
| 1743 filter, ctx, result, offset); | 1743 filter, ctx, result, offset); |
| 1744 } | 1744 } |
| 1745 | 1745 |
| 1746 #include "SkImage_Base.h" | |
| 1747 | |
| 1748 static SkImageInfo make_info(GrTexture* tex, int w, int h, bool isOpaque) { | |
| 1749 const GrPixelConfig config = tex->config(); | |
| 1750 SkColorType ct; | |
| 1751 SkAlphaType at = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; | |
| 1752 if (!GrPixelConfig2ColorAndProfileType(config, &ct, NULL)) { | |
| 1753 ct = kUnknown_SkColorType; | |
| 1754 } | |
| 1755 return SkImageInfo::Make(w, h, ct, at); | |
| 1756 } | |
| 1757 | |
| 1758 static bool wrap_as_bm(const SkImage* image, SkBitmap* bm) { | |
| 1759 GrTexture* tex = image->getTexture(); | |
| 1760 if (tex) { | |
| 1761 // TODO: handle the GrTexture directly, and skip GrPixelRef | |
| 1762 const SkImageInfo info = make_info(tex, image->width(), image->height(),
image->isOpaque()); | |
| 1763 bm->setInfo(info); | |
| 1764 bm->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, tex)))->unref(); | |
| 1765 } else { | |
| 1766 if (!as_IB(image)->getROPixels(bm)) { | |
| 1767 return false; | |
| 1768 } | |
| 1769 } | |
| 1770 return true; | |
| 1771 } | |
| 1772 | |
| 1773 void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x
, SkScalar y, | |
| 1774 const SkPaint& paint) { | |
| 1775 SkBitmap bm; | |
| 1776 if (wrap_as_bm(image, &bm)) { | |
| 1777 this->drawBitmap(draw, bm, SkMatrix::MakeTrans(x, y), paint); | |
| 1778 } | |
| 1779 } | |
| 1780 | |
| 1781 void SkGpuDevice::drawImageRect(const SkDraw& draw, const SkImage* image, const
SkRect* src, | |
| 1782 const SkRect& dst, const SkPaint& paint) { | |
| 1783 SkBitmap bm; | |
| 1784 if (wrap_as_bm(image, &bm)) { | |
| 1785 this->drawBitmapRect(draw, bm, src, dst, paint, SkCanvas::DrawBitmapRect
Flags(0)); | |
| 1786 } | |
| 1787 } | |
| 1788 | |
| 1789 /////////////////////////////////////////////////////////////////////////////// | 1746 /////////////////////////////////////////////////////////////////////////////// |
| 1790 | 1747 |
| 1791 // must be in SkCanvas::VertexMode order | 1748 // must be in SkCanvas::VertexMode order |
| 1792 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { | 1749 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { |
| 1793 kTriangles_GrPrimitiveType, | 1750 kTriangles_GrPrimitiveType, |
| 1794 kTriangleStrip_GrPrimitiveType, | 1751 kTriangleStrip_GrPrimitiveType, |
| 1795 kTriangleFan_GrPrimitiveType, | 1752 kTriangleFan_GrPrimitiveType, |
| 1796 }; | 1753 }; |
| 1797 | 1754 |
| 1798 void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, | 1755 void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2086 #endif | 2043 #endif |
| 2087 } | 2044 } |
| 2088 | 2045 |
| 2089 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 2046 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
| 2090 // We always return a transient cache, so it is freed after each | 2047 // We always return a transient cache, so it is freed after each |
| 2091 // filter traversal. | 2048 // filter traversal. |
| 2092 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 2049 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
| 2093 } | 2050 } |
| 2094 | 2051 |
| 2095 #endif | 2052 #endif |
| OLD | NEW |