1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CC_LAYERS_NINE_PATCH_GENERATOR_H_
#define CC_LAYERS_NINE_PATCH_GENERATOR_H_
#include <string>
#include <vector>
#include "base/functional/function_ref.h"
#include "cc/cc_export.h"
#include "cc/resources/ui_resource_client.h"
#include "components/viz/common/resources/resource_id.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/vector2d.h"
namespace base {
namespace trace_event {
class TracedValue;
}
}
namespace viz {
class ClientResourceProvider;
class CompositorRenderPass;
class SharedQuadState;
} // namespace viz
namespace cc {
class LayerImpl;
class CC_EXPORT NinePatchGenerator {
public:
class Patch {
public:
Patch(const gfx::Rect& image_rect,
const gfx::Size& total_image_bounds,
const gfx::Rect& output_rect);
gfx::Rect image_rect;
gfx::RectF normalized_image_rect;
gfx::Rect output_rect;
};
NinePatchGenerator();
// The bitmap stretches out the bounds of the layer. The following picture
// illustrates the parameters associated with the dimensions.
//
// Layer space layout
//
// --------------------------------
// | : : |
// | J C |
// | : : |
// | ------------------ |
// | | : | |
// |~~~I~~| ------------ | |
// | | | | | |
// | | | | | |
// |~~~A~~|~~| |~~|~B~~~~|
// | | | | | |
// | L ------------ | |
// | | : | |
// | ---K-------------- |
// | D |
// | : |
// | : |
// --------------------------------
//
// Bitmap space layout
//
// ~~~~~~~~~~ W ~~~~~~~~~~
// : : |
// : Y |
// : : |
// :~~X~~------------ |
// : | : |
// : | : |
// H | Q |
// : | : |
// : ~~~~~P~~~~~ |
// : |
// : |
// : |
// ------------------------
//
// |image_bounds| = (W, H)
// |image_aperture| = (X, Y, P, Q)
// |border| = (A, C, A + B, C + D)
// |occlusion_rectangle| = (I, J, K, L)
// |fill_center| indicates whether to draw the center quad or not.
bool SetLayout(const gfx::Size& image_bounds,
const gfx::Size& output_bounds,
const gfx::Rect& image_aperture,
const gfx::Rect& border,
const gfx::Rect& output_occlusion,
bool fill_center,
bool nearest_neighbor);
std::vector<Patch> GeneratePatches() const;
void AppendQuadsForCc(LayerImpl* layer_impl,
UIResourceId ui_resource_id,
viz::CompositorRenderPass* render_pass,
viz::SharedQuadState* shared_quad_state,
const std::vector<Patch>& patches,
const gfx::Vector2d& offset = gfx::Vector2d());
void AppendQuads(
viz::ResourceId resource,
bool opaque,
base::FunctionRef<gfx::Rect(const gfx::Rect&)> clip_visible_rect,
viz::ClientResourceProvider* client_resource_provider,
viz::CompositorRenderPass* render_pass,
viz::SharedQuadState* shared_quad_state,
const std::vector<Patch>& patches,
const gfx::Vector2d& offset = gfx::Vector2d());
void AsValueInto(base::trace_event::TracedValue* state) const;
void CheckGeometryLimitations();
const gfx::Rect& image_aperture() const { return image_aperture_; }
const gfx::Rect& border() const { return border_; }
const gfx::Rect& output_occlusion() const { return output_occlusion_; }
bool fill_center() const { return fill_center_; }
private:
std::vector<Patch> ComputeQuadsWithOcclusion() const;
std::vector<Patch> ComputeQuadsWithoutOcclusion() const;
// The center patch in image space.
gfx::Rect image_aperture_;
// An inset border that the patches will be mapped to.
gfx::Rect border_;
gfx::Size image_bounds_;
gfx::Size output_bounds_;
bool fill_center_;
bool nearest_neighbor_;
gfx::Rect output_occlusion_;
};
} // namespace cc
#endif // CC_LAYERS_NINE_PATCH_GENERATOR_H_
|