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: src/gpu/SkGpuDevice.cpp

Issue 22978012: Split SkDevice into SkBaseDevice and SkBitmapDevice (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: update to ToT, re-add SkBaseDevice::config & default parameter Created 7 years, 4 months 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 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/GrTextureDomainEffect.h" 10 #include "effects/GrTextureDomainEffect.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 return NULL; 154 return NULL;
155 } 155 }
156 if (surface->asTexture()) { 156 if (surface->asTexture()) {
157 return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asTextur e())); 157 return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asTextur e()));
158 } else { 158 } else {
159 return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asRender Target())); 159 return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asRender Target()));
160 } 160 }
161 } 161 }
162 162
163 SkGpuDevice::SkGpuDevice(GrContext* context, GrTexture* texture) 163 SkGpuDevice::SkGpuDevice(GrContext* context, GrTexture* texture)
164 : SkDevice(make_bitmap(context, texture->asRenderTarget())) { 164 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) {
165 this->initFromRenderTarget(context, texture->asRenderTarget(), false); 165 this->initFromRenderTarget(context, texture->asRenderTarget(), false);
166 } 166 }
167 167
168 SkGpuDevice::SkGpuDevice(GrContext* context, GrRenderTarget* renderTarget) 168 SkGpuDevice::SkGpuDevice(GrContext* context, GrRenderTarget* renderTarget)
169 : SkDevice(make_bitmap(context, renderTarget)) { 169 : SkBitmapDevice(make_bitmap(context, renderTarget)) {
170 this->initFromRenderTarget(context, renderTarget, false); 170 this->initFromRenderTarget(context, renderTarget, false);
171 } 171 }
172 172
173 void SkGpuDevice::initFromRenderTarget(GrContext* context, 173 void SkGpuDevice::initFromRenderTarget(GrContext* context,
174 GrRenderTarget* renderTarget, 174 GrRenderTarget* renderTarget,
175 bool cached) { 175 bool cached) {
176 fDrawProcs = NULL; 176 fDrawProcs = NULL;
177 177
178 fContext = context; 178 fContext = context;
179 fContext->ref(); 179 fContext->ref();
(...skipping 16 matching lines...) Expand all
196 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (surface, cached)); 196 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (surface, cached));
197 197
198 this->setPixelRef(pr, 0)->unref(); 198 this->setPixelRef(pr, 0)->unref();
199 } 199 }
200 200
201 SkGpuDevice::SkGpuDevice(GrContext* context, 201 SkGpuDevice::SkGpuDevice(GrContext* context,
202 SkBitmap::Config config, 202 SkBitmap::Config config,
203 int width, 203 int width,
204 int height, 204 int height,
205 int sampleCount) 205 int sampleCount)
206 : SkDevice(config, width, height, false /*isOpaque*/) { 206 : SkBitmapDevice(config, width, height, false /*isOpaque*/) {
207 207
208 fDrawProcs = NULL; 208 fDrawProcs = NULL;
209 209
210 fContext = context; 210 fContext = context;
211 fContext->ref(); 211 fContext->ref();
212 212
213 fRenderTarget = NULL; 213 fRenderTarget = NULL;
214 fNeedClear = false; 214 fNeedClear = false;
215 215
216 if (config != SkBitmap::kRGB_565_Config) { 216 if (config != SkBitmap::kRGB_565_Config) {
(...skipping 1212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1429 GrPaint grPaint; 1429 GrPaint grPaint;
1430 grPaint.addColorEffect(effect); 1430 grPaint.addColorEffect(effect);
1431 bool alphaOnly = !(SkBitmap::kA8_Config == bitmap.config()); 1431 bool alphaOnly = !(SkBitmap::kA8_Config == bitmap.config());
1432 if (!skPaint2GrPaintNoShader(this, paint, alphaOnly, false, &grPaint)) { 1432 if (!skPaint2GrPaintNoShader(this, paint, alphaOnly, false, &grPaint)) {
1433 return; 1433 return;
1434 } 1434 }
1435 1435
1436 fContext->drawRectToRect(grPaint, dstRect, paintRect, &m); 1436 fContext->drawRectToRect(grPaint, dstRect, paintRect, &m);
1437 } 1437 }
1438 1438
1439 static bool filter_texture(SkDevice* device, GrContext* context, 1439 static bool filter_texture(SkBaseDevice* device, GrContext* context,
1440 GrTexture* texture, SkImageFilter* filter, 1440 GrTexture* texture, SkImageFilter* filter,
1441 int w, int h, const SkMatrix& ctm, SkBitmap* result, 1441 int w, int h, const SkMatrix& ctm, SkBitmap* result,
1442 SkIPoint* offset) { 1442 SkIPoint* offset) {
1443 SkASSERT(filter); 1443 SkASSERT(filter);
1444 SkDeviceImageFilterProxy proxy(device); 1444 SkDeviceImageFilterProxy proxy(device);
1445 1445
1446 if (filter->canFilterImageGPU()) { 1446 if (filter->canFilterImageGPU()) {
1447 // Save the render target and set it to NULL, so we don't accidentally d raw to it in the 1447 // Save the render target and set it to NULL, so we don't accidentally d raw to it in the
1448 // filter. Also set the clip wide open and the matrix to identity. 1448 // filter. Also set the clip wide open and the matrix to identity.
1449 GrContext::AutoWideOpenIdentityDraw awo(context, NULL); 1449 GrContext::AutoWideOpenIdentityDraw awo(context, NULL);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1528 if (!bitmapBounds.contains(tmpSrc)) { 1528 if (!bitmapBounds.contains(tmpSrc)) {
1529 if (!tmpSrc.intersect(bitmapBounds)) { 1529 if (!tmpSrc.intersect(bitmapBounds)) {
1530 return; // nothing to draw 1530 return; // nothing to draw
1531 } 1531 }
1532 } 1532 }
1533 } 1533 }
1534 1534
1535 this->drawBitmapCommon(draw, bitmap, &tmpSrc, matrix, paint, flags); 1535 this->drawBitmapCommon(draw, bitmap, &tmpSrc, matrix, paint, flags);
1536 } 1536 }
1537 1537
1538 void SkGpuDevice::drawDevice(const SkDraw& draw, SkDevice* device, 1538 void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device,
1539 int x, int y, const SkPaint& paint) { 1539 int x, int y, const SkPaint& paint) {
1540 // clear of the source device must occur before CHECK_SHOULD_DRAW 1540 // clear of the source device must occur before CHECK_SHOULD_DRAW
1541 SkGpuDevice* dev = static_cast<SkGpuDevice*>(device); 1541 SkGpuDevice* dev = static_cast<SkGpuDevice*>(device);
1542 if (dev->fNeedClear) { 1542 if (dev->fNeedClear) {
1543 // TODO: could check here whether we really need to draw at all 1543 // TODO: could check here whether we really need to draw at all
1544 dev->clear(0x0); 1544 dev->clear(0x0);
1545 } 1545 }
1546 1546
1547 // drawDevice is defined to be in device coords. 1547 // drawDevice is defined to be in device coords.
1548 CHECK_SHOULD_DRAW(draw, true); 1548 CHECK_SHOULD_DRAW(draw, true);
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1811 return false; 1811 return false;
1812 } 1812 }
1813 1813
1814 void SkGpuDevice::flush() { 1814 void SkGpuDevice::flush() {
1815 DO_DEFERRED_CLEAR(); 1815 DO_DEFERRED_CLEAR();
1816 fContext->resolveRenderTarget(fRenderTarget); 1816 fContext->resolveRenderTarget(fRenderTarget);
1817 } 1817 }
1818 1818
1819 /////////////////////////////////////////////////////////////////////////////// 1819 ///////////////////////////////////////////////////////////////////////////////
1820 1820
1821 SkDevice* SkGpuDevice::onCreateCompatibleDevice(SkBitmap::Config config, 1821 SkBaseDevice* SkGpuDevice::onCreateCompatibleDevice(SkBitmap::Config config,
1822 int width, int height, 1822 int width, int height,
1823 bool isOpaque, 1823 bool isOpaque,
1824 Usage usage) { 1824 Usage usage) {
1825 GrTextureDesc desc; 1825 GrTextureDesc desc;
1826 desc.fConfig = fRenderTarget->config(); 1826 desc.fConfig = fRenderTarget->config();
1827 desc.fFlags = kRenderTarget_GrTextureFlagBit; 1827 desc.fFlags = kRenderTarget_GrTextureFlagBit;
1828 desc.fWidth = width; 1828 desc.fWidth = width;
1829 desc.fHeight = height; 1829 desc.fHeight = height;
1830 desc.fSampleCnt = fRenderTarget->numSamples(); 1830 desc.fSampleCnt = fRenderTarget->numSamples();
1831 1831
1832 SkAutoTUnref<GrTexture> texture; 1832 SkAutoTUnref<GrTexture> texture;
1833 // Skia's convention is to only clear a device if it is non-opaque. 1833 // Skia's convention is to only clear a device if it is non-opaque.
1834 bool needClear = !isOpaque; 1834 bool needClear = !isOpaque;
(...skipping 12 matching lines...) Expand all
1847 return SkNEW_ARGS(SkGpuDevice,(fContext, texture, needClear)); 1847 return SkNEW_ARGS(SkGpuDevice,(fContext, texture, needClear));
1848 } else { 1848 } else {
1849 GrPrintf("---- failed to create compatible device texture [%d %d]\n", wi dth, height); 1849 GrPrintf("---- failed to create compatible device texture [%d %d]\n", wi dth, height);
1850 return NULL; 1850 return NULL;
1851 } 1851 }
1852 } 1852 }
1853 1853
1854 SkGpuDevice::SkGpuDevice(GrContext* context, 1854 SkGpuDevice::SkGpuDevice(GrContext* context,
1855 GrTexture* texture, 1855 GrTexture* texture,
1856 bool needClear) 1856 bool needClear)
1857 : SkDevice(make_bitmap(context, texture->asRenderTarget())) { 1857 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) {
1858 1858
1859 SkASSERT(texture && texture->asRenderTarget()); 1859 SkASSERT(texture && texture->asRenderTarget());
1860 // This constructor is called from onCreateCompatibleDevice. It has locked t he RT in the texture 1860 // This constructor is called from onCreateCompatibleDevice. It has locked t he RT in the texture
1861 // cache. We pass true for the third argument so that it will get unlocked. 1861 // cache. We pass true for the third argument so that it will get unlocked.
1862 this->initFromRenderTarget(context, texture->asRenderTarget(), true); 1862 this->initFromRenderTarget(context, texture->asRenderTarget(), true);
1863 fNeedClear = needClear; 1863 fNeedClear = needClear;
1864 } 1864 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698