| 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 1712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1723 // must be pushed upstack. | 1723 // must be pushed upstack. |
| 1724 AutoBitmapTexture abt(fContext, src, NULL, &texture); | 1724 AutoBitmapTexture abt(fContext, src, NULL, &texture); |
| 1725 if (!texture) { | 1725 if (!texture) { |
| 1726 return false; | 1726 return false; |
| 1727 } | 1727 } |
| 1728 | 1728 |
| 1729 return this->filterTexture(fContext, texture, src.width(), src.height(), | 1729 return this->filterTexture(fContext, texture, src.width(), src.height(), |
| 1730 filter, ctx, result, offset); | 1730 filter, ctx, result, offset); |
| 1731 } | 1731 } |
| 1732 | 1732 |
| 1733 #include "SkImage_Base.h" |
| 1734 |
| 1735 static SkImageInfo make_info(GrTexture* tex, int w, int h, bool isOpaque) { |
| 1736 const GrPixelConfig config = tex->config(); |
| 1737 SkColorType ct; |
| 1738 SkAlphaType at = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; |
| 1739 if (!GrPixelConfig2ColorAndProfileType(config, &ct, NULL)) { |
| 1740 ct = kUnknown_SkColorType; |
| 1741 } |
| 1742 return SkImageInfo::Make(w, h, ct, at); |
| 1743 } |
| 1744 |
| 1745 static bool wrap_as_bm(const SkImage* image, SkBitmap* bm) { |
| 1746 GrTexture* tex = image->getTexture(); |
| 1747 if (tex) { |
| 1748 // TODO: handle the GrTexture directly, and skip GrPixelRef |
| 1749 const SkImageInfo info = make_info(tex, image->width(), image->height(),
image->isOpaque()); |
| 1750 bm->setInfo(info); |
| 1751 bm->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, tex)))->unref(); |
| 1752 } else { |
| 1753 if (!as_IB(image)->getROPixels(bm)) { |
| 1754 return false; |
| 1755 } |
| 1756 } |
| 1757 return true; |
| 1758 } |
| 1759 |
| 1760 void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x
, SkScalar y, |
| 1761 const SkPaint& paint) { |
| 1762 SkBitmap bm; |
| 1763 if (wrap_as_bm(image, &bm)) { |
| 1764 this->drawBitmap(draw, bm, SkMatrix::MakeTrans(x, y), paint); |
| 1765 } |
| 1766 } |
| 1767 |
| 1768 void SkGpuDevice::drawImageRect(const SkDraw& draw, const SkImage* image, const
SkRect* src, |
| 1769 const SkRect& dst, const SkPaint& paint) { |
| 1770 SkBitmap bm; |
| 1771 if (wrap_as_bm(image, &bm)) { |
| 1772 this->drawBitmapRect(draw, bm, src, dst, paint, SkCanvas::DrawBitmapRect
Flags(0)); |
| 1773 } |
| 1774 } |
| 1775 |
| 1733 /////////////////////////////////////////////////////////////////////////////// | 1776 /////////////////////////////////////////////////////////////////////////////// |
| 1734 | 1777 |
| 1735 // must be in SkCanvas::VertexMode order | 1778 // must be in SkCanvas::VertexMode order |
| 1736 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { | 1779 static const GrPrimitiveType gVertexMode2PrimitiveType[] = { |
| 1737 kTriangles_GrPrimitiveType, | 1780 kTriangles_GrPrimitiveType, |
| 1738 kTriangleStrip_GrPrimitiveType, | 1781 kTriangleStrip_GrPrimitiveType, |
| 1739 kTriangleFan_GrPrimitiveType, | 1782 kTriangleFan_GrPrimitiveType, |
| 1740 }; | 1783 }; |
| 1741 | 1784 |
| 1742 void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, | 1785 void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2030 #endif | 2073 #endif |
| 2031 } | 2074 } |
| 2032 | 2075 |
| 2033 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 2076 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
| 2034 // We always return a transient cache, so it is freed after each | 2077 // We always return a transient cache, so it is freed after each |
| 2035 // filter traversal. | 2078 // filter traversal. |
| 2036 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 2079 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
| 2037 } | 2080 } |
| 2038 | 2081 |
| 2039 #endif | 2082 #endif |
| OLD | NEW |