Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /**************************************************************************
  2.  *
  3.  * Copyright 2003 VMware, Inc.
  4.  * All Rights Reserved.
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a
  7.  * copy of this software and associated documentation files (the
  8.  * "Software"), to deal in the Software without restriction, including
  9.  * without limitation the rights to use, copy, modify, merge, publish,
  10.  * distribute, sub license, and/or sell copies of the Software, and to
  11.  * permit persons to whom the Software is furnished to do so, subject to
  12.  * the following conditions:
  13.  *
  14.  * The above copyright notice and this permission notice (including the
  15.  * next paragraph) shall be included in all copies or substantial portions
  16.  * of the Software.
  17.  *
  18.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  21.  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
  22.  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  23.  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  24.  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25.  *
  26.  **************************************************************************/
  27.  
  28. #include "main/glheader.h"
  29. #include "main/image.h"
  30. #include "main/state.h"
  31. #include "main/mtypes.h"
  32. #include "main/condrender.h"
  33. #include "main/fbobject.h"
  34. #include "drivers/common/meta.h"
  35.  
  36. #include "brw_context.h"
  37. #include "intel_buffers.h"
  38. #include "intel_mipmap_tree.h"
  39. #include "intel_pixel.h"
  40. #include "intel_fbo.h"
  41. #include "intel_blit.h"
  42. #include "intel_batchbuffer.h"
  43.  
  44. #define FILE_DEBUG_FLAG DEBUG_PIXEL
  45.  
  46. /**
  47.  * CopyPixels with the blitter.  Don't support zooming, pixel transfer, etc.
  48.  */
  49. static bool
  50. do_blit_copypixels(struct gl_context * ctx,
  51.                    GLint srcx, GLint srcy,
  52.                    GLsizei width, GLsizei height,
  53.                    GLint dstx, GLint dsty, GLenum type)
  54. {
  55.    struct brw_context *brw = brw_context(ctx);
  56.    struct gl_framebuffer *fb = ctx->DrawBuffer;
  57.    struct gl_framebuffer *read_fb = ctx->ReadBuffer;
  58.    GLint orig_dstx;
  59.    GLint orig_dsty;
  60.    GLint orig_srcx;
  61.    GLint orig_srcy;
  62.    struct intel_renderbuffer *draw_irb = NULL;
  63.    struct intel_renderbuffer *read_irb = NULL;
  64.  
  65.    /* Update draw buffer bounds */
  66.    _mesa_update_state(ctx);
  67.  
  68.    intel_prepare_render(brw);
  69.  
  70.    switch (type) {
  71.    case GL_COLOR:
  72.       if (fb->_NumColorDrawBuffers != 1) {
  73.          perf_debug("glCopyPixels() fallback: MRT\n");
  74.          return false;
  75.       }
  76.  
  77.       draw_irb = intel_renderbuffer(fb->_ColorDrawBuffers[0]);
  78.       read_irb = intel_renderbuffer(read_fb->_ColorReadBuffer);
  79.       break;
  80.    case GL_DEPTH_STENCIL_EXT:
  81.       draw_irb = intel_renderbuffer(fb->Attachment[BUFFER_DEPTH].Renderbuffer);
  82.       read_irb =
  83.          intel_renderbuffer(read_fb->Attachment[BUFFER_DEPTH].Renderbuffer);
  84.       break;
  85.    case GL_DEPTH:
  86.       perf_debug("glCopyPixels() fallback: GL_DEPTH\n");
  87.       return false;
  88.    case GL_STENCIL:
  89.       perf_debug("glCopyPixels() fallback: GL_STENCIL\n");
  90.       return false;
  91.    default:
  92.       perf_debug("glCopyPixels(): Unknown type\n");
  93.       return false;
  94.    }
  95.  
  96.    if (!draw_irb) {
  97.       perf_debug("glCopyPixels() fallback: missing draw buffer\n");
  98.       return false;
  99.    }
  100.  
  101.    if (!read_irb) {
  102.       perf_debug("glCopyPixels() fallback: missing read buffer\n");
  103.       return false;
  104.    }
  105.  
  106.    if (draw_irb->mt->num_samples > 1 || read_irb->mt->num_samples > 1) {
  107.       perf_debug("glCopyPixels() fallback: multisampled buffers\n");
  108.       return false;
  109.    }
  110.  
  111.    if (ctx->_ImageTransferState) {
  112.       perf_debug("glCopyPixels(): Unsupported image transfer state\n");
  113.       return false;
  114.    }
  115.  
  116.    if (ctx->Depth.Test) {
  117.       perf_debug("glCopyPixels(): Unsupported depth test state\n");
  118.       return false;
  119.    }
  120.  
  121.    if (ctx->Stencil._Enabled) {
  122.       perf_debug("glCopyPixels(): Unsupported stencil test state\n");
  123.       return false;
  124.    }
  125.  
  126.    if (ctx->Fog.Enabled ||
  127.        ctx->Texture._MaxEnabledTexImageUnit != -1 ||
  128.        ctx->FragmentProgram._Enabled) {
  129.       perf_debug("glCopyPixels(): Unsupported fragment shader state\n");
  130.       return false;
  131.    }
  132.  
  133.    if (ctx->Color.AlphaEnabled ||
  134.        ctx->Color.BlendEnabled) {
  135.       perf_debug("glCopyPixels(): Unsupported blend state\n");
  136.       return false;
  137.    }
  138.  
  139.    if (!ctx->Color.ColorMask[0][0] ||
  140.        !ctx->Color.ColorMask[0][1] ||
  141.        !ctx->Color.ColorMask[0][2] ||
  142.        !ctx->Color.ColorMask[0][3]) {
  143.       perf_debug("glCopyPixels(): Unsupported color mask state\n");
  144.       return false;
  145.    }
  146.  
  147.    if (ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F) {
  148.       perf_debug("glCopyPixles(): Unsupported pixel zoom\n");
  149.       return false;
  150.    }
  151.  
  152.    intel_batchbuffer_flush(brw);
  153.  
  154.    /* Clip to destination buffer. */
  155.    orig_dstx = dstx;
  156.    orig_dsty = dsty;
  157.    if (!_mesa_clip_to_region(fb->_Xmin, fb->_Ymin,
  158.                              fb->_Xmax, fb->_Ymax,
  159.                              &dstx, &dsty, &width, &height))
  160.       goto out;
  161.    /* Adjust src coords for our post-clipped destination origin */
  162.    srcx += dstx - orig_dstx;
  163.    srcy += dsty - orig_dsty;
  164.  
  165.    /* Clip to source buffer. */
  166.    orig_srcx = srcx;
  167.    orig_srcy = srcy;
  168.    if (!_mesa_clip_to_region(0, 0,
  169.                              read_fb->Width, read_fb->Height,
  170.                              &srcx, &srcy, &width, &height))
  171.       goto out;
  172.    /* Adjust dst coords for our post-clipped source origin */
  173.    dstx += srcx - orig_srcx;
  174.    dsty += srcy - orig_srcy;
  175.  
  176.    if (!intel_miptree_blit(brw,
  177.                            read_irb->mt, read_irb->mt_level, read_irb->mt_layer,
  178.                            srcx, srcy, _mesa_is_winsys_fbo(read_fb),
  179.                            draw_irb->mt, draw_irb->mt_level, draw_irb->mt_layer,
  180.                            dstx, dsty, _mesa_is_winsys_fbo(fb),
  181.                            width, height,
  182.                            (ctx->Color.ColorLogicOpEnabled ?
  183.                             ctx->Color.LogicOp : GL_COPY))) {
  184.       DBG("%s: blit failure\n", __func__);
  185.       return false;
  186.    }
  187.  
  188.    if (ctx->Query.CurrentOcclusionObject)
  189.       ctx->Query.CurrentOcclusionObject->Result += width * height;
  190.  
  191. out:
  192.  
  193.    DBG("%s: success\n", __func__);
  194.    return true;
  195. }
  196.  
  197.  
  198. void
  199. intelCopyPixels(struct gl_context * ctx,
  200.                 GLint srcx, GLint srcy,
  201.                 GLsizei width, GLsizei height,
  202.                 GLint destx, GLint desty, GLenum type)
  203. {
  204.    DBG("%s\n", __func__);
  205.  
  206.    if (!_mesa_check_conditional_render(ctx))
  207.       return;
  208.  
  209.    if (do_blit_copypixels(ctx, srcx, srcy, width, height, destx, desty, type))
  210.       return;
  211.  
  212.    /* this will use swrast if needed */
  213.    _mesa_meta_CopyPixels(ctx, srcx, srcy, width, height, destx, desty, type);
  214. }
  215.