1//
2// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// Image11.h: Defines the rx::Image11 class, which acts as the interface to
8// the actual underlying resources of a Texture
9
10#ifndef LIBGLESV2_RENDERER_IMAGE11_H_
11#define LIBGLESV2_RENDERER_IMAGE11_H_
12
13#include "libGLESv2/renderer/d3d/ImageD3D.h"
14
15#include "common/debug.h"
16
17namespace gl
18{
19class Framebuffer;
20}
21
22namespace rx
23{
24class Renderer;
25class Renderer11;
26class TextureStorage11;
27
28class Image11 : public ImageD3D
29{
30  public:
31    Image11();
32    virtual ~Image11();
33
34    static Image11 *makeImage11(Image *img);
35
36    static void generateMipmap(Image11 *dest, Image11 *src);
37
38    virtual bool isDirty() const;
39
40    virtual bool copyToStorage2D(TextureStorage *storage, int level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
41    virtual bool copyToStorageCube(TextureStorage *storage, int face, int level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
42    virtual bool copyToStorage3D(TextureStorage *storage, int level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth);
43    virtual bool copyToStorage2DArray(TextureStorage *storage, int level, GLint xoffset, GLint yoffset, GLint arrayLayer, GLsizei width, GLsizei height);
44
45    virtual bool redefine(Renderer *renderer, GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, bool forceRelease);
46
47    DXGI_FORMAT getDXGIFormat() const;
48
49    virtual void loadData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
50                          GLint unpackAlignment, GLenum type, const void *input);
51    virtual void loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
52                                    const void *input);
53
54    virtual void copy(GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source);
55
56    bool recoverFromAssociatedStorage();
57    bool isAssociatedStorageValid(TextureStorage11* textureStorage) const;
58    void disassociateStorage();
59
60  protected:
61    HRESULT map(D3D11_MAP mapType, D3D11_MAPPED_SUBRESOURCE *map);
62    void unmap();
63
64  private:
65    DISALLOW_COPY_AND_ASSIGN(Image11);
66
67    bool copyToStorageImpl(TextureStorage11 *storage11, int level, int layerTarget, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
68
69    ID3D11Resource *getStagingTexture();
70    unsigned int getStagingSubresource();
71    void createStagingTexture();
72    void releaseStagingTexture();
73
74    Renderer11 *mRenderer;
75
76    DXGI_FORMAT mDXGIFormat;
77    ID3D11Resource *mStagingTexture;
78    unsigned int mStagingSubresource;
79
80    bool mRecoverFromStorage;
81    TextureStorage11 *mAssociatedStorage;
82    int mAssociatedStorageLevel;
83    int mAssociatedStorageLayerTarget;
84    unsigned int mRecoveredFromStorageCount;
85};
86
87}
88
89#endif // LIBGLESV2_RENDERER_IMAGE11_H_
90