| 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 "GrBlurUtils.h" | 10 #include "GrBlurUtils.h" |
| 11 #include "GrContext.h" | 11 #include "GrContext.h" |
| 12 #include "GrContextPriv.h" | |
| 13 #include "GrDrawContextPriv.h" | 12 #include "GrDrawContextPriv.h" |
| 14 #include "GrGpu.h" | 13 #include "GrGpu.h" |
| 15 #include "GrGpuResourcePriv.h" | |
| 16 #include "GrImageIDTextureAdjuster.h" | 14 #include "GrImageIDTextureAdjuster.h" |
| 17 #include "GrStyle.h" | 15 #include "GrStyle.h" |
| 18 #include "GrTracing.h" | 16 #include "GrTracing.h" |
| 19 | 17 |
| 20 #include "SkCanvasPriv.h" | 18 #include "SkCanvasPriv.h" |
| 21 #include "SkDraw.h" | 19 #include "SkDraw.h" |
| 22 #include "SkErrorInternals.h" | 20 #include "SkErrorInternals.h" |
| 23 #include "SkGlyphCache.h" | 21 #include "SkGlyphCache.h" |
| 24 #include "SkGr.h" | 22 #include "SkGr.h" |
| 25 #include "SkGrPriv.h" | 23 #include "SkGrPriv.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 default: // If it is unpremul or unknown don't try to render | 83 default: // If it is unpremul or unknown don't try to render |
| 86 return false; | 84 return false; |
| 87 } | 85 } |
| 88 } | 86 } |
| 89 if (kClear_InitContents == init) { | 87 if (kClear_InitContents == init) { |
| 90 *flags |= kNeedClear_Flag; | 88 *flags |= kNeedClear_Flag; |
| 91 } | 89 } |
| 92 return true; | 90 return true; |
| 93 } | 91 } |
| 94 | 92 |
| 95 sk_sp<SkGpuDevice> SkGpuDevice::Make(sk_sp<GrRenderTarget> rt, sk_sp<SkColorSpac
e> colorSpace, | 93 sk_sp<SkGpuDevice> SkGpuDevice::Make(sk_sp<GrDrawContext> drawContext, |
| 96 const SkSurfaceProps* props, InitContents i
nit) { | 94 int width, int height, |
| 97 if (!rt || rt->wasDestroyed() || !rt->getContext()) { | 95 InitContents init) { |
| 98 return nullptr; | |
| 99 } | |
| 100 unsigned flags; | |
| 101 if (!CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) { | |
| 102 return nullptr; | |
| 103 } | |
| 104 | |
| 105 const int width = rt->width(); | |
| 106 const int height = rt->height(); | |
| 107 | |
| 108 GrContext* context = rt->getContext(); | |
| 109 | |
| 110 sk_sp<GrDrawContext> drawContext(context->contextPriv().makeWrappedDrawConte
xt( | |
| 111 std:
:move(rt), | |
| 112 std:
:move(colorSpace), | |
| 113 prop
s)); | |
| 114 return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(drawContext), width, hei
ght, flags)); | |
| 115 } | |
| 116 | |
| 117 sk_sp<SkBaseDevice> SkGpuDevice::Make(sk_sp<GrDrawContext> drawContext, | |
| 118 int width, int height, | |
| 119 InitContents init) { | |
| 120 if (!drawContext || drawContext->wasAbandoned()) { | 96 if (!drawContext || drawContext->wasAbandoned()) { |
| 121 return nullptr; | 97 return nullptr; |
| 122 } | 98 } |
| 123 unsigned flags; | 99 unsigned flags; |
| 124 if (!CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) { | 100 if (!CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) { |
| 125 return nullptr; | 101 return nullptr; |
| 126 } | 102 } |
| 127 return sk_sp<SkBaseDevice>(new SkGpuDevice(std::move(drawContext), width, he
ight, flags)); | 103 return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(drawContext), width, hei
ght, flags)); |
| 128 } | 104 } |
| 129 | 105 |
| 130 sk_sp<SkGpuDevice> SkGpuDevice::Make(GrContext* context, SkBudgeted budgeted, | 106 sk_sp<SkGpuDevice> SkGpuDevice::Make(GrContext* context, SkBudgeted budgeted, |
| 131 const SkImageInfo& info, int sampleCount, | 107 const SkImageInfo& info, int sampleCount, |
| 132 GrSurfaceOrigin origin, | 108 GrSurfaceOrigin origin, |
| 133 const SkSurfaceProps* props, InitContents i
nit) { | 109 const SkSurfaceProps* props, InitContents i
nit) { |
| 134 unsigned flags; | 110 unsigned flags; |
| 135 if (!CheckAlphaTypeAndGetFlags(&info, init, &flags)) { | 111 if (!CheckAlphaTypeAndGetFlags(&info, init, &flags)) { |
| 136 return nullptr; | 112 return nullptr; |
| 137 } | 113 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 ASSERT_SINGLE_OWNER | 217 ASSERT_SINGLE_OWNER |
| 242 // TODO: teach fRenderTarget to take ImageInfo directly to specify the src p
ixels | 218 // TODO: teach fRenderTarget to take ImageInfo directly to specify the src p
ixels |
| 243 GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *fContext->caps()); | 219 GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *fContext->caps()); |
| 244 if (kUnknown_GrPixelConfig == config) { | 220 if (kUnknown_GrPixelConfig == config) { |
| 245 return false; | 221 return false; |
| 246 } | 222 } |
| 247 uint32_t flags = 0; | 223 uint32_t flags = 0; |
| 248 if (kUnpremul_SkAlphaType == info.alphaType()) { | 224 if (kUnpremul_SkAlphaType == info.alphaType()) { |
| 249 flags = GrContext::kUnpremul_PixelOpsFlag; | 225 flags = GrContext::kUnpremul_PixelOpsFlag; |
| 250 } | 226 } |
| 251 fDrawContext->accessRenderTarget()->writePixels(x, y, info.width(), info.hei
ght(), | 227 return fDrawContext->accessRenderTarget()->writePixels(x, y, info.width(), i
nfo.height(), |
| 252 config, pixels, rowBytes, fl
ags); | 228 config, pixels, rowBy
tes, flags); |
| 253 return true; | |
| 254 } | 229 } |
| 255 | 230 |
| 256 bool SkGpuDevice::onAccessPixels(SkPixmap* pmap) { | 231 bool SkGpuDevice::onAccessPixels(SkPixmap* pmap) { |
| 257 ASSERT_SINGLE_OWNER | 232 ASSERT_SINGLE_OWNER |
| 258 return false; | 233 return false; |
| 259 } | 234 } |
| 260 | 235 |
| 261 // call this every draw call, to ensure that the context reflects our state, | 236 // call this every draw call, to ensure that the context reflects our state, |
| 262 // and not the state from some other canvas/device | 237 // and not the state from some other canvas/device |
| 263 void SkGpuDevice::prepareDraw(const SkDraw& draw) { | 238 void SkGpuDevice::prepareDraw(const SkDraw& draw) { |
| (...skipping 1514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1778 } | 1753 } |
| 1779 | 1754 |
| 1780 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { | 1755 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { |
| 1781 ASSERT_SINGLE_OWNER | 1756 ASSERT_SINGLE_OWNER |
| 1782 // We always return a transient cache, so it is freed after each | 1757 // We always return a transient cache, so it is freed after each |
| 1783 // filter traversal. | 1758 // filter traversal. |
| 1784 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); | 1759 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); |
| 1785 } | 1760 } |
| 1786 | 1761 |
| 1787 #endif | 1762 #endif |
| OLD | NEW |