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 "effects/GrBicubicEffect.h" | 10 #include "effects/GrBicubicEffect.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 | 120 |
121 struct GrSkDrawProcs : public SkDrawProcs { | 121 struct GrSkDrawProcs : public SkDrawProcs { |
122 public: | 122 public: |
123 GrContext* fContext; | 123 GrContext* fContext; |
124 GrTextContext* fTextContext; | 124 GrTextContext* fTextContext; |
125 GrFontScaler* fFontScaler; // cached in the skia glyphcache | 125 GrFontScaler* fFontScaler; // cached in the skia glyphcache |
126 }; | 126 }; |
127 | 127 |
128 /////////////////////////////////////////////////////////////////////////////// | 128 /////////////////////////////////////////////////////////////////////////////// |
129 | 129 |
130 /* | |
131 * GrRenderTarget does not know its opaqueness, only its config, so we have | |
132 * to make conservative guesses when we return an "equivalent" bitmap. | |
133 */ | |
134 static SkBitmap make_bitmap(GrContext* context, GrRenderTarget* renderTarget) { | |
135 SkBitmap bitmap; | |
136 bitmap.setInfo(renderTarget->info()); | |
137 return bitmap; | |
138 } | |
139 | |
140 SkGpuDevice* SkGpuDevice::Create(GrSurface* surface, unsigned flags) { | 130 SkGpuDevice* SkGpuDevice::Create(GrSurface* surface, unsigned flags) { |
141 SkASSERT(NULL != surface); | 131 SkASSERT(NULL != surface); |
142 if (NULL == surface->asRenderTarget() || NULL == surface->getContext()) { | 132 if (NULL == surface->asRenderTarget() || NULL == surface->getContext()) { |
143 return NULL; | 133 return NULL; |
144 } | 134 } |
145 if (surface->asTexture()) { | 135 if (surface->asTexture()) { |
146 return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asTextur
e(), flags)); | 136 return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asTextur
e(), flags)); |
147 } else { | 137 } else { |
148 return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asRender
Target(), flags)); | 138 return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asRender
Target(), flags)); |
149 } | 139 } |
150 } | 140 } |
151 | 141 |
152 SkGpuDevice::SkGpuDevice(GrContext* context, GrTexture* texture, unsigned flags) | 142 SkGpuDevice::SkGpuDevice(GrContext* context, GrTexture* texture, unsigned flags)
{ |
153 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { | |
154 this->initFromRenderTarget(context, texture->asRenderTarget(), flags); | 143 this->initFromRenderTarget(context, texture->asRenderTarget(), flags); |
155 } | 144 } |
156 | 145 |
157 SkGpuDevice::SkGpuDevice(GrContext* context, GrRenderTarget* renderTarget, unsig
ned flags) | 146 SkGpuDevice::SkGpuDevice(GrContext* context, GrRenderTarget* renderTarget, unsig
ned flags) { |
158 : SkBitmapDevice(make_bitmap(context, renderTarget)) { | |
159 this->initFromRenderTarget(context, renderTarget, flags); | 147 this->initFromRenderTarget(context, renderTarget, flags); |
160 } | 148 } |
161 | 149 |
162 void SkGpuDevice::initFromRenderTarget(GrContext* context, | 150 void SkGpuDevice::initFromRenderTarget(GrContext* context, |
163 GrRenderTarget* renderTarget, | 151 GrRenderTarget* renderTarget, |
164 unsigned flags) { | 152 unsigned flags) { |
165 fDrawProcs = NULL; | 153 fDrawProcs = NULL; |
166 | 154 |
167 fContext = context; | 155 fContext = context; |
168 fContext->ref(); | 156 fContext->ref(); |
169 | 157 |
170 fRenderTarget = NULL; | 158 fRenderTarget = NULL; |
171 fNeedClear = flags & kNeedClear_Flag; | 159 fNeedClear = flags & kNeedClear_Flag; |
172 | 160 |
173 SkASSERT(NULL != renderTarget); | 161 SkASSERT(NULL != renderTarget); |
174 fRenderTarget = renderTarget; | 162 fRenderTarget = renderTarget; |
175 fRenderTarget->ref(); | 163 fRenderTarget->ref(); |
176 | 164 |
177 // Hold onto to the texture in the pixel ref (if there is one) because the t
exture holds a ref | 165 // Hold onto to the texture in the pixel ref (if there is one) because the t
exture holds a ref |
178 // on the RT but not vice-versa. | 166 // on the RT but not vice-versa. |
179 // TODO: Remove this trickery once we figure out how to make SkGrPixelRef do
this without | 167 // TODO: Remove this trickery once we figure out how to make SkGrPixelRef do
this without |
180 // busting chrome (for a currently unknown reason). | 168 // busting chrome (for a currently unknown reason). |
181 GrSurface* surface = fRenderTarget->asTexture(); | 169 GrSurface* surface = fRenderTarget->asTexture(); |
182 if (NULL == surface) { | 170 if (NULL == surface) { |
183 surface = fRenderTarget; | 171 surface = fRenderTarget; |
184 } | 172 } |
185 | 173 |
186 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, | 174 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, |
187 (surface->info(), surface, SkToBool(flags & kCac
hed_Flag))); | 175 (surface->info(), surface, SkToBool(flags & kCac
hed_Flag))); |
188 | 176 fLegacyBitmap.setInfo(surface->info()); |
189 this->setPixelRef(pr)->unref(); | 177 fLegacyBitmap.setPixelRef(pr)->unref(); |
190 | 178 |
191 bool useDFFonts = !!(flags & kDFFonts_Flag); | 179 bool useDFFonts = !!(flags & kDFFonts_Flag); |
192 fMainTextContext = fContext->createTextContext(fRenderTarget, fLeakyProperti
es, useDFFonts); | 180 fMainTextContext = fContext->createTextContext(fRenderTarget, fLeakyProperti
es, useDFFonts); |
193 fFallbackTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, fLeakyProp
erties)); | 181 fFallbackTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, fLeakyProp
erties)); |
194 } | 182 } |
195 | 183 |
196 SkGpuDevice* SkGpuDevice::Create(GrContext* context, const SkImageInfo& origInfo
, | 184 SkGpuDevice* SkGpuDevice::Create(GrContext* context, const SkImageInfo& origInfo
, |
197 int sampleCount) { | 185 int sampleCount) { |
198 if (kUnknown_SkColorType == origInfo.colorType() || | 186 if (kUnknown_SkColorType == origInfo.colorType() || |
199 origInfo.width() < 0 || origInfo.height() < 0) { | 187 origInfo.width() < 0 || origInfo.height() < 0) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 if (kUnknown_GrPixelConfig == config) { | 271 if (kUnknown_GrPixelConfig == config) { |
284 return false; | 272 return false; |
285 } | 273 } |
286 uint32_t flags = 0; | 274 uint32_t flags = 0; |
287 if (kUnpremul_SkAlphaType == info.alphaType()) { | 275 if (kUnpremul_SkAlphaType == info.alphaType()) { |
288 flags = GrContext::kUnpremul_PixelOpsFlag; | 276 flags = GrContext::kUnpremul_PixelOpsFlag; |
289 } | 277 } |
290 fRenderTarget->writePixels(x, y, info.width(), info.height(), config, pixels
, rowBytes, flags); | 278 fRenderTarget->writePixels(x, y, info.width(), info.height(), config, pixels
, rowBytes, flags); |
291 | 279 |
292 // need to bump our genID for compatibility with clients that "know" we have
a bitmap | 280 // need to bump our genID for compatibility with clients that "know" we have
a bitmap |
293 this->onAccessBitmap().notifyPixelsChanged(); | 281 fLegacyBitmap.notifyPixelsChanged(); |
294 | 282 |
295 return true; | 283 return true; |
296 } | 284 } |
297 | 285 |
298 const SkBitmap& SkGpuDevice::onAccessBitmap() { | 286 const SkBitmap& SkGpuDevice::onAccessBitmap() { |
299 DO_DEFERRED_CLEAR(); | 287 DO_DEFERRED_CLEAR(); |
300 return INHERITED::onAccessBitmap(); | 288 return fLegacyBitmap; |
301 } | 289 } |
302 | 290 |
303 void SkGpuDevice::onAttachToCanvas(SkCanvas* canvas) { | 291 void SkGpuDevice::onAttachToCanvas(SkCanvas* canvas) { |
304 INHERITED::onAttachToCanvas(canvas); | 292 INHERITED::onAttachToCanvas(canvas); |
305 | 293 |
306 // Canvas promises that this ptr is valid until onDetachFromCanvas is called | 294 // Canvas promises that this ptr is valid until onDetachFromCanvas is called |
307 fClipData.fClipStack = canvas->getClipStack(); | 295 fClipData.fClipStack = canvas->getClipStack(); |
308 } | 296 } |
309 | 297 |
310 void SkGpuDevice::onDetachFromCanvas() { | 298 void SkGpuDevice::onDetachFromCanvas() { |
(...skipping 1685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1996 picture->fPlayback->setReplacements(NULL); | 1984 picture->fPlayback->setReplacements(NULL); |
1997 | 1985 |
1998 // unlock the layers | 1986 // unlock the layers |
1999 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { | 1987 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { |
2000 GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture, i); | 1988 GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture, i); |
2001 fContext->getLayerCache()->unlock(layer); | 1989 fContext->getLayerCache()->unlock(layer); |
2002 } | 1990 } |
2003 | 1991 |
2004 return true; | 1992 return true; |
2005 } | 1993 } |
OLD | NEW |