Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: src/gpu/gl/GrGLGpu.cpp

Issue 1260293004: Revert of Move draw on upload decision in GrGpu (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 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
« no previous file with comments | « src/gpu/gl/GrGLGpu.h ('k') | tests/WritePixelsTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 8
9 #include "GrGLGpu.h" 9 #include "GrGLGpu.h"
10 #include "GrGLGLSL.h" 10 #include "GrGLGLSL.h"
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 fStencilClearFBOID = 0; 261 fStencilClearFBOID = 0;
262 fCopyProgram.fArrayBuffer = 0; 262 fCopyProgram.fArrayBuffer = 0;
263 fCopyProgram.fProgram = 0; 263 fCopyProgram.fProgram = 0;
264 if (this->glCaps().shaderCaps()->pathRenderingSupport()) { 264 if (this->glCaps().shaderCaps()->pathRenderingSupport()) {
265 this->glPathRendering()->abandonGpuResources(); 265 this->glPathRendering()->abandonGpuResources();
266 } 266 }
267 } 267 }
268 268
269 /////////////////////////////////////////////////////////////////////////////// 269 ///////////////////////////////////////////////////////////////////////////////
270 270
271 GrPixelConfig GrGLGpu::preferredWritePixelsConfig(GrPixelConfig writeConfig,
272 GrPixelConfig surfaceConfig) c onst {
273 if (GR_GL_RGBA_8888_PIXEL_OPS_SLOW && kRGBA_8888_GrPixelConfig == writeConfi g) {
274 return kBGRA_8888_GrPixelConfig;
275 } else {
276 return writeConfig;
277 }
278 }
279
280 bool GrGLGpu::canWriteTexturePixels(const GrTexture* texture, GrPixelConfig srcC onfig) const {
281 if (kIndex_8_GrPixelConfig == srcConfig || kIndex_8_GrPixelConfig == texture ->config()) {
282 return false;
283 }
284 if (srcConfig != texture->config() && kGLES_GrGLStandard == this->glStandard ()) {
285 // In general ES2 requires the internal format of the texture and the fo rmat of the src
286 // pixels to match. However, It may or may not be possible to upload BGR A data to a RGBA
287 // texture. It depends upon which extension added BGRA. The Apple extens ion allows it
288 // (BGRA's internal format is RGBA) while the EXT extension does not (BG RA is its own
289 // internal format).
290 if (this->glCaps().isConfigTexturable(kBGRA_8888_GrPixelConfig) &&
291 !this->glCaps().bgraIsInternalFormat() &&
292 kBGRA_8888_GrPixelConfig == srcConfig &&
293 kRGBA_8888_GrPixelConfig == texture->config()) {
294 return true;
295 } else {
296 return false;
297 }
298 } else {
299 return true;
300 }
301 }
302
271 void GrGLGpu::onResetContext(uint32_t resetBits) { 303 void GrGLGpu::onResetContext(uint32_t resetBits) {
272 // we don't use the zb at all 304 // we don't use the zb at all
273 if (resetBits & kMisc_GrGLBackendState) { 305 if (resetBits & kMisc_GrGLBackendState) {
274 GL_CALL(Disable(GR_GL_DEPTH_TEST)); 306 GL_CALL(Disable(GR_GL_DEPTH_TEST));
275 GL_CALL(DepthMask(GR_GL_FALSE)); 307 GL_CALL(DepthMask(GR_GL_FALSE));
276 308
277 fHWDrawFace = GrPipelineBuilder::kInvalid_DrawFace; 309 fHWDrawFace = GrPipelineBuilder::kInvalid_DrawFace;
278 fHWDitherEnabled = kUnknown_TriState; 310 fHWDitherEnabled = kUnknown_TriState;
279 311
280 if (kGL_GrGLStandard == this->glStandard()) { 312 if (kGL_GrGLStandard == this->glStandard()) {
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 desc.fHeight, 530 desc.fHeight,
499 desc.fSampleCnt, 531 desc.fSampleCnt,
500 format)); 532 format));
501 tgt->renderTargetPriv().didAttachStencilAttachment(sb); 533 tgt->renderTargetPriv().didAttachStencilAttachment(sb);
502 sb->unref(); 534 sb->unref();
503 } 535 }
504 return tgt; 536 return tgt;
505 } 537 }
506 538
507 //////////////////////////////////////////////////////////////////////////////// 539 ////////////////////////////////////////////////////////////////////////////////
508 bool GrGLGpu::onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height,
509 size_t rowBytes, GrPixelConfig srcConfig,
510 DrawPreference* drawPreference,
511 WritePixelTempDrawInfo* tempDrawInfo) {
512 if (kIndex_8_GrPixelConfig == srcConfig || GrPixelConfigIsCompressed(dstSurf ace->config())) {
513 return false;
514 }
515
516 tempDrawInfo->fSwapRAndB = false;
517
518 // These settings we will always want if a temp draw is performed. Initially set the config
519 // to srcConfig, though that may be modified if we decide to do a R/G swap.
520 tempDrawInfo->fTempSurfaceDesc.fFlags = kNone_GrSurfaceFlags;
521 tempDrawInfo->fTempSurfaceDesc.fConfig = srcConfig;
522 tempDrawInfo->fTempSurfaceDesc.fWidth = width;
523 tempDrawInfo->fTempSurfaceDesc.fHeight = height;
524 tempDrawInfo->fTempSurfaceDesc.fSampleCnt = 0;
525 tempDrawInfo->fTempSurfaceDesc.fOrigin = kTopLeft_GrSurfaceOrigin; // no CPU y-flip for TL.
526
527 bool configsAreRBSwaps = GrPixelConfigSwapRAndB(srcConfig) == dstSurface->co nfig();
528
529 if (configsAreRBSwaps) {
530 if (!this->caps()->isConfigTexturable(srcConfig)) {
531 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference);
532 tempDrawInfo->fTempSurfaceDesc.fConfig = dstSurface->config();
533 tempDrawInfo->fSwapRAndB = true;
534 } else if (GR_GL_RGBA_8888_PIXEL_OPS_SLOW && kRGBA_8888_GrPixelConfig == srcConfig) {
535 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference );
536 tempDrawInfo->fTempSurfaceDesc.fConfig = dstSurface->config();
537 tempDrawInfo->fSwapRAndB = true;
538 } else if (kGLES_GrGLStandard == this->glStandard() &&
539 this->glCaps().bgraIsInternalFormat()) {
540 // The internal format and external formats must match texture uploa ds so we can't
541 // swizzle while uploading when BGRA is a distinct internal format.
542 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference);
543 tempDrawInfo->fTempSurfaceDesc.fConfig = dstSurface->config();
544 tempDrawInfo->fSwapRAndB = true;
545 }
546 }
547
548 if (!this->glCaps().unpackFlipYSupport() &&
549 kBottomLeft_GrSurfaceOrigin == dstSurface->origin()) {
550 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference);
551 }
552
553 return true;
554 }
555 540
556 bool GrGLGpu::onWriteTexturePixels(GrTexture* texture, 541 bool GrGLGpu::onWriteTexturePixels(GrTexture* texture,
557 int left, int top, int width, int height, 542 int left, int top, int width, int height,
558 GrPixelConfig config, const void* buffer, 543 GrPixelConfig config, const void* buffer,
559 size_t rowBytes) { 544 size_t rowBytes) {
560 if (NULL == buffer) { 545 if (NULL == buffer) {
561 return false; 546 return false;
562 } 547 }
563 GrGLTexture* glTex = static_cast<GrGLTexture*>(texture); 548 GrGLTexture* glTex = static_cast<GrGLTexture*>(texture);
564 549
(...skipping 1147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1712 return false; 1697 return false;
1713 } 1698 }
1714 1699
1715 // If we have to do memcpy to handle non-trim rowBytes then we 1700 // If we have to do memcpy to handle non-trim rowBytes then we
1716 // get the flip for free. Otherwise it costs. 1701 // get the flip for free. Otherwise it costs.
1717 // Note that we're assuming that 0 rowBytes has already been handled and tha t the width has been 1702 // Note that we're assuming that 0 rowBytes has already been handled and tha t the width has been
1718 // clipped. 1703 // clipped.
1719 return caps.packRowLengthSupport() || GrBytesPerPixel(config) * width == row Bytes; 1704 return caps.packRowLengthSupport() || GrBytesPerPixel(config) * width == row Bytes;
1720 } 1705 }
1721 1706
1722 bool GrGLGpu::onGetReadPixelsInfo(GrSurface* srcSurface, int width, int height, size_t rowBytes, 1707 void elevate_draw_preference(GrGpu::DrawPreference* preference, GrGpu::DrawPrefe rence elevation) {
1723 GrPixelConfig readConfig, DrawPreference* draw Preference, 1708 GR_STATIC_ASSERT(GrGpu::kCallerPrefersDraw_DrawPreference > GrGpu::kNoDraw_D rawPreference);
1724 ReadPixelTempDrawInfo* tempDrawInfo) { 1709 GR_STATIC_ASSERT(GrGpu::kGpuPrefersDraw_DrawPreference >
1710 GrGpu::kCallerPrefersDraw_DrawPreference);
1711 GR_STATIC_ASSERT(GrGpu::kRequireDraw_DrawPreference > GrGpu::kGpuPrefersDraw _DrawPreference);
1712 *preference = SkTMax(*preference, elevation);
1713 }
1714
1715 bool GrGLGpu::getReadPixelsInfo(GrSurface* srcSurface, int width, int height, si ze_t rowBytes,
1716 GrPixelConfig readConfig, DrawPreference* drawPr eference,
1717 ReadPixelTempDrawInfo* tempDrawInfo) {
1718 SkASSERT(drawPreference);
1719 SkASSERT(tempDrawInfo);
1720 SkASSERT(kGpuPrefersDraw_DrawPreference != *drawPreference);
1721
1725 if (GrPixelConfigIsCompressed(readConfig)) { 1722 if (GrPixelConfigIsCompressed(readConfig)) {
1726 return false; 1723 return false;
1727 } 1724 }
1728 1725
1729 tempDrawInfo->fSwapRAndB = false; 1726 tempDrawInfo->fSwapRAndB = false;
1730 1727
1731 // These settings we will always want if a temp draw is performed. The confi g is set below 1728 // These settings we will always want if a temp draw is performed. The confi g is set below
1732 // depending on whether we want to do a R/B swap or not. 1729 // depending on whether we want to do a R/B swap or not.
1733 tempDrawInfo->fTempSurfaceDesc.fFlags = kRenderTarget_GrSurfaceFlag; 1730 tempDrawInfo->fTempSurfaceDesc.fFlags = kRenderTarget_GrSurfaceFlag;
1734 tempDrawInfo->fTempSurfaceDesc.fWidth = width; 1731 tempDrawInfo->fTempSurfaceDesc.fWidth = width;
(...skipping 11 matching lines...) Expand all
1746 1743
1747 if (GR_GL_RGBA_8888_PIXEL_OPS_SLOW && kRGBA_8888_GrPixelConfig == readConfig ) { 1744 if (GR_GL_RGBA_8888_PIXEL_OPS_SLOW && kRGBA_8888_GrPixelConfig == readConfig ) {
1748 tempDrawInfo->fTempSurfaceDesc.fConfig = kBGRA_8888_GrPixelConfig; 1745 tempDrawInfo->fTempSurfaceDesc.fConfig = kBGRA_8888_GrPixelConfig;
1749 } else if (kMesa_GrGLDriver == this->glContext().driver() && 1746 } else if (kMesa_GrGLDriver == this->glContext().driver() &&
1750 GrBytesPerPixel(readConfig) == 4 && 1747 GrBytesPerPixel(readConfig) == 4 &&
1751 GrPixelConfigSwapRAndB(readConfig) == srcConfig) { 1748 GrPixelConfigSwapRAndB(readConfig) == srcConfig) {
1752 // Mesa 3D takes a slow path on when reading back BGRA from an RGBA sur face and vice-versa. 1749 // Mesa 3D takes a slow path on when reading back BGRA from an RGBA sur face and vice-versa.
1753 // Better to do a draw with a R/B swap and then read as the original con fig. 1750 // Better to do a draw with a R/B swap and then read as the original con fig.
1754 tempDrawInfo->fTempSurfaceDesc.fConfig = srcConfig; 1751 tempDrawInfo->fTempSurfaceDesc.fConfig = srcConfig;
1755 tempDrawInfo->fSwapRAndB = true; 1752 tempDrawInfo->fSwapRAndB = true;
1756 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); 1753 elevate_draw_preference(drawPreference, kGpuPrefersDraw_DrawPreference);
1757 } else if (readConfig == kBGRA_8888_GrPixelConfig && 1754 } else if (readConfig == kBGRA_8888_GrPixelConfig &&
1758 !this->glCaps().readPixelsSupported(this->glInterface(), GR_GL_BG RA, 1755 !this->glCaps().readPixelsSupported(this->glInterface(), GR_GL_BG RA,
1759 GR_GL_UNSIGNED_BYTE, srcConfi g)) { 1756 GR_GL_UNSIGNED_BYTE, srcConfi g)) {
1760 tempDrawInfo->fTempSurfaceDesc.fConfig = kRGBA_8888_GrPixelConfig; 1757 tempDrawInfo->fTempSurfaceDesc.fConfig = kRGBA_8888_GrPixelConfig;
1761 tempDrawInfo->fSwapRAndB = true; 1758 tempDrawInfo->fSwapRAndB = true;
1762 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); 1759 elevate_draw_preference(drawPreference, kRequireDraw_DrawPreference);
1763 } 1760 }
1764 1761
1765 GrRenderTarget* srcAsRT = srcSurface->asRenderTarget(); 1762 GrRenderTarget* srcAsRT = srcSurface->asRenderTarget();
1766 if (!srcAsRT) { 1763 if (!srcAsRT) {
1767 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); 1764 elevate_draw_preference(drawPreference, kRequireDraw_DrawPreference);
1768 } else if (read_pixels_pays_for_y_flip(srcAsRT, this->glCaps(), width, heigh t, readConfig, 1765 } else if (read_pixels_pays_for_y_flip(srcAsRT, this->glCaps(), width, heigh t, readConfig,
1769 rowBytes)) { 1766 rowBytes)) {
1770 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); 1767 elevate_draw_preference(drawPreference, kGpuPrefersDraw_DrawPreference);
1771 } 1768 }
1772 1769
1770 if (kRequireDraw_DrawPreference == *drawPreference && !srcSurface->asTexture ()) {
1771 return false;
1772 }
1773 return true; 1773 return true;
1774 } 1774 }
1775 1775
1776 bool GrGLGpu::onReadPixels(GrRenderTarget* target, 1776 bool GrGLGpu::onReadPixels(GrRenderTarget* target,
1777 int left, int top, 1777 int left, int top,
1778 int width, int height, 1778 int width, int height,
1779 GrPixelConfig config, 1779 GrPixelConfig config,
1780 void* buffer, 1780 void* buffer,
1781 size_t rowBytes) { 1781 size_t rowBytes) {
1782 SkASSERT(target); 1782 SkASSERT(target);
(...skipping 1385 matching lines...) Expand 10 before | Expand all | Expand 10 after
3168 this->setVertexArrayID(gpu, 0); 3168 this->setVertexArrayID(gpu, 0);
3169 } 3169 }
3170 int attrCount = gpu->glCaps().maxVertexAttributes(); 3170 int attrCount = gpu->glCaps().maxVertexAttributes();
3171 if (fDefaultVertexArrayAttribState.count() != attrCount) { 3171 if (fDefaultVertexArrayAttribState.count() != attrCount) {
3172 fDefaultVertexArrayAttribState.resize(attrCount); 3172 fDefaultVertexArrayAttribState.resize(attrCount);
3173 } 3173 }
3174 attribState = &fDefaultVertexArrayAttribState; 3174 attribState = &fDefaultVertexArrayAttribState;
3175 } 3175 }
3176 return attribState; 3176 return attribState;
3177 } 3177 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLGpu.h ('k') | tests/WritePixelsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698