1 /*
   2  * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #ifndef D3DVERTEXCACHER_H
  27 #define D3DVERTEXCACHER_H
  28 
  29 #include "jni.h"
  30 #include "D3DContext.h"
  31 
  32 #define MAX_BATCH_SIZE 1024
  33 #define APPEND_ACTION 0x0
  34 #define RESET_ACTION  0x1
  35 #define D3DFVF_J2DLVERTEX \
  36     (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX2 | \
  37     D3DFVF_TEXCOORDSIZE2(0) | D3DFVF_TEXCOORDSIZE2(1) )
  38 typedef struct _J2DLVERTEX {
  39     float x, y, z;
  40     DWORD color;
  41     float tu1, tv1;
  42     float tu2, tv2;
  43 } J2DLVERTEX;
  44 
  45 typedef struct {
  46     D3DPRIMITIVETYPE pType; // type of primitives in this batch
  47     UINT pNum; // number of primitives of pType in this batch
  48 } VertexBatch;
  49 
  50 class D3DContext;
  51 
  52 class D3DPIPELINE_API D3DVertexCacher {
  53 public:
  54     HRESULT Init(D3DContext *pCtx);
  55             ~D3DVertexCacher() { ReleaseDefPoolResources(); }
  56     void    ReleaseDefPoolResources();
  57 
  58     jint    GetColor() { return color; }
  59     void    SetColor(jint newColor) { color = newColor; }
  60     HRESULT DrawLine(int x1, int y1, int x2, int y2);
  61     HRESULT DrawPoly(jint nPoints, jboolean isClosed,
  62                      jint transX, jint transY,
  63                      jint *xPoints, jint *yPoints);
  64     HRESULT DrawScanlines(jint scanlineCount, jint *scanlines);
  65     HRESULT DrawRect(int x1, int y1, int x2, int y2);
  66     HRESULT FillRect(int x1, int y1, int x2, int y2);
  67     HRESULT FillParallelogramAA(float fx11, float fy11,
  68                                 float dx21, float dy21,
  69                                 float dx12, float dy12);
  70     HRESULT DrawParallelogramAA(float ox11, float oy11,
  71                                 float ox21, float oy21,
  72                                 float ox12, float oy12,
  73                                 float ix11, float iy11,
  74                                 float ix21, float iy21,
  75                                 float ix12, float iy12);
  76     HRESULT FillParallelogram(float fx11, float fy11,
  77                               float dx21, float dy21,
  78                               float dx12, float dy12);
  79     HRESULT FillSpans(jint spansCount, jint *spans);
  80     HRESULT DrawTexture(float dx1, float dy1, float dx2, float dy2,
  81                         float tx1, float ty1, float tx2, float ty2);
  82     HRESULT DrawTexture(float  dx1, float  dy1, float  dx2, float  dy2,
  83                         float t1x1, float t1y1, float t1x2, float t1y2,
  84                         float t2x1, float t2y1, float t2x2, float t2y2);
  85     HRESULT Render(int actionType = APPEND_ACTION);
  86     UINT    GetFreeVertices() { return (MAX_BATCH_SIZE - firstUnusedVertex); }
  87 
  88 static
  89     HRESULT CreateInstance(D3DContext *pCtx, D3DVertexCacher **ppVC);
  90 
  91 private:
  92             D3DVertexCacher();
  93     HRESULT EnsureCapacity(D3DPRIMITIVETYPE newPType, UINT vNum);
  94 
  95 private:
  96     UINT firstPendingBatch;
  97     UINT firstPendingVertex;
  98     UINT firstUnusedVertex;
  99     UINT currentBatch;
 100     J2DLVERTEX              vertices[MAX_BATCH_SIZE];
 101     VertexBatch             batches[MAX_BATCH_SIZE];
 102     IDirect3DVertexBuffer9  *lpD3DVertexBuffer;
 103     IDirect3DDevice9        *lpD3DDevice;
 104     D3DContext              *pCtx;
 105     jint                    color;
 106     float                   fudge2;
 107 };
 108 
 109 #endif // D3DVERTEXCACHER_H